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 maxCount = initialVertices.Count.Max(targetShape2D.Vertices.Count); for (int i = 0; i < maxCount; i++) { int initialIndex = (i * (initialVertices.Count / (float)maxCount)).RoundToInt(Math.RoundMode.Floor); int targetIndex = (i * (targetShape2D.Vertices.Count / (float)maxCount)).RoundToInt(Math.RoundMode.Floor); shapeVertices.Add(targetShape2D.Vertices[targetIndex].Lerp(initialVertices[initialIndex], 1f - t)); } shape.Vertices = shapeVertices; } ).OnComplete(() => { shapeVertices.Clear(); for (int i = 0; i < targetShape2D.Vertices.Count; i++) shapeVertices.Add(targetShape2D.Vertices[i]); shape.Vertices = shapeVertices; }); } }