public void CanConvertToPolygon() { var rect = new Rect2d(100, 200, 300, 400, Anchor2d.BottomCenter); var poly = rect.ToPolygon(); // Extra point from where corner 4 closes back to corner 1 Assert.Equal(5, poly.Points.Count); }
public override void Draw(Entity entity) { var sprite = entity.GetComponent <SpriteComponent>(); if (!TryGetAnimatedSprite(sprite, out Rect2d src) && !TryGetStaticSprite(sprite, out src)) { // Can't determine a valid sprite to draw return; } Rect2d dest = entity.Space; // Get the origin before any transformations are applied Vector2d origin = (dest.GetOriginPosition() - dest.TopLeft).ToVector(); Rotation2d rotation = sprite.Rotation; if (sprite.RotationAnimation != null) { rotation.Turn(sprite.RotationAnimation.GetFrame(this.Timer.Total)); } dest.Shift(sprite.Offset); if (sprite.OffsetAnimation != null) { dest.Shift(sprite.OffsetAnimation.GetFrame(this.Timer.Total)); } dest.Scale(sprite.Scale); if (sprite.ScaleAnimation != null) { var animScale = sprite.ScaleAnimation.GetFrame(this.Timer.Total); dest.Scale(animScale); } entity.SetDirective <SpriteDirective>("simple-sprite", sd => { sd.Asset = sprite.SpriteSheet.Name; sd.Source = src; sd.Destination = dest.GetOriginPosition(); sd.Size = dest.GetSize(); sd.Rotation = rotation.Radians; sd.Origin = origin; }); if (sprite.EnableBoxOutline) { entity.SetDirective <PolygonDirective>("simple-sprite-box-outline", pd => { pd.Color = new ColorRGBA(255, 255, 0); pd.Points = dest.ToPolygon().Points; }); } }