ByChance.Levels2D.Chunk2D.SetPosition C# (CSharp) Method

SetPosition() private method

Sets the position of this chunk within the level and changes the relative positions of all anchors of this chunk to match its rotation.
private SetPosition ( Vector2F position ) : void
position Vector2F New position of this chunk within the level.
return void
        internal void SetPosition(Vector2F position)
        {
            // Set new position.
            this.Position = position;

            // Rotate anchors if necessary.
            if (this.Rotation <= 0)
            {
                return;
            }

            var center = this.Extents / 2;

            foreach (Anchor2D anchor in this.ChunkAnchors)
            {
                var origin = anchor.RelativePosition - center;

                var anchorRelativePositionX = (origin.X * (float)Math.Cos(this.Rotation))
                                              - (origin.Y * (float)Math.Sin(this.Rotation)) + center.Y;
                var anchorRelativePositionY = (origin.Y * (float)Math.Cos(this.Rotation))
                                              + (origin.X * (float)Math.Sin(this.Rotation)) + center.X;

                anchor.RelativePosition = new Vector2F(anchorRelativePositionX, anchorRelativePositionY);
            }
        }