using System.Collections.Generic; using Syntriax.Engine.Core; namespace Syntriax.Engine.Systems.Tween; public static class TweenShape2DExtensions { public static ITween TweenShape2D(this Shape2D shape, ITweenManager tweenManager, float duration, Shape2D targetShape2D) { List initialVertices = new(shape.Vertices); List shapeVertices = new(shape.Vertices); return tweenManager.StartTween(duration, t => { shapeVertices.Clear(); int count = Math.Lerp(initialVertices.Count, targetShape2D.Vertices.Count, t).RoundToInt(); for (int i = 0; i < count; i++) { int initialIndex = i.Min(initialVertices.Count); int targetIndex = i.Min(targetShape2D.Vertices.Count); shapeVertices.Add(targetShape2D.Vertices[targetIndex].Lerp(initialVertices[initialIndex], 1f - t)); } shape.Vertices = shapeVertices; } ); } }