From 55cd7e2a3cb2f7336a50e2d7ce9a90cf11621138 Mon Sep 17 00:00:00 2001 From: agate-pris Date: Sun, 9 Nov 2025 13:44:38 +0900 Subject: [PATCH 1/2] =?UTF-8?q?AnimationCurveI17F15.Keys=20=E3=82=BB?= =?UTF-8?q?=E3=83=83=E3=83=88=E6=99=82=E3=81=AB=E3=82=BD=E3=83=BC=E3=83=88?= =?UTF-8?q?=E3=81=95=E3=82=8C=E3=81=AA=E3=81=84=E4=B8=8D=E5=85=B7=E5=90=88?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Intar.Tests/AnimationCurveTest.Unity.cs | 26 ++++++++++++++++++++++++ Intar.Tests/AnimationCurveTest.cs | 27 +++++++++++++++++++++++++ Intar/AnimationCurveI17F15.cs | 1 + Intar/Utility.cs | 22 ++++++++++++++++++++ Intar/Utility.cs.meta | 2 ++ 5 files changed, 78 insertions(+) create mode 100644 Intar/Utility.cs create mode 100644 Intar/Utility.cs.meta diff --git a/Intar.Tests/AnimationCurveTest.Unity.cs b/Intar.Tests/AnimationCurveTest.Unity.cs index 691c5341a..864424ce3 100644 --- a/Intar.Tests/AnimationCurveTest.Unity.cs +++ b/Intar.Tests/AnimationCurveTest.Unity.cs @@ -48,5 +48,31 @@ public static void TestAnimationCurveConstructor() { Assert.IsNotNull(curve.keys); Assert.AreEqual(0, curve.length); } + + [Test] + public static void TestSetKeys() { + var keys = new Keyframe[] { + new Keyframe(4, 5), + new Keyframe(4, 4), + new Keyframe(3, 4), + new Keyframe(3, 3), + new Keyframe(2, 3), + new Keyframe(2, 2), + new Keyframe(1, 2), + new Keyframe(1, 1), + }; + var curve = new AnimationCurve { keys = keys }; + + // keys 設定時, 値が安定ソートされることをテスト + Assert.AreEqual(8, curve.length); + Assert.AreEqual(keys[6], curve[0]); + Assert.AreEqual(keys[7], curve[1]); + Assert.AreEqual(keys[4], curve[2]); + Assert.AreEqual(keys[5], curve[3]); + Assert.AreEqual(keys[2], curve[4]); + Assert.AreEqual(keys[3], curve[5]); + Assert.AreEqual(keys[0], curve[6]); + Assert.AreEqual(keys[1], curve[7]); + } } } diff --git a/Intar.Tests/AnimationCurveTest.cs b/Intar.Tests/AnimationCurveTest.cs index 6cab910e8..a99516525 100644 --- a/Intar.Tests/AnimationCurveTest.cs +++ b/Intar.Tests/AnimationCurveTest.cs @@ -39,5 +39,32 @@ public static void TestAnimationCurveI17F15Constructor() { Assert.IsNotNull(curve.Keys); Assert.AreEqual(0, curve.Length); } + + [Test] + public static void TestSetKeysI17F15() { + var keys = new KeyframeI17F15[] { + new KeyframeI17F15(I17F15.FromBits(4000), I17F15.FromBits(5000)), + new KeyframeI17F15(I17F15.FromBits(4000), I17F15.FromBits(4000)), + new KeyframeI17F15(I17F15.FromBits(3000), I17F15.FromBits(4000)), + new KeyframeI17F15(I17F15.FromBits(3000), I17F15.FromBits(3000)), + new KeyframeI17F15(I17F15.FromBits(2000), I17F15.FromBits(3000)), + new KeyframeI17F15(I17F15.FromBits(2000), I17F15.FromBits(2000)), + new KeyframeI17F15(I17F15.FromBits(1000), I17F15.FromBits(2000)), + new KeyframeI17F15(I17F15.FromBits(1000), I17F15.FromBits(1000)), + }; + var curve = new AnimationCurveI17F15 { Keys = keys }; + + // Keys 設定時, 値が安定ソートされることをテスト + Assert.AreEqual(8, curve.Length); + Assert.AreEqual(keys[6], curve[0]); + Assert.AreEqual(keys[7], curve[1]); + Assert.AreEqual(keys[4], curve[2]); + Assert.AreEqual(keys[5], curve[3]); + Assert.AreEqual(keys[2], curve[4]); + Assert.AreEqual(keys[3], curve[5]); + Assert.AreEqual(keys[0], curve[6]); + Assert.AreEqual(keys[1], curve[7]); + } + } } diff --git a/Intar/AnimationCurveI17F15.cs b/Intar/AnimationCurveI17F15.cs index daf5384e8..e1a1a64a2 100644 --- a/Intar/AnimationCurveI17F15.cs +++ b/Intar/AnimationCurveI17F15.cs @@ -85,6 +85,7 @@ public KeyframeI17F15[] Keys { return; } keys = new List(value); + Utility.InsertionSort(keys, (a, b) => a.Time.CompareTo(b.Time)); } } public int Length { diff --git a/Intar/Utility.cs b/Intar/Utility.cs new file mode 100644 index 000000000..889151940 --- /dev/null +++ b/Intar/Utility.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; + +namespace Intar { + /// + /// 主に実装用のユーティリティクラス + /// + static class Utility { + internal static void InsertionSort(IList list, Comparison comparison) { + var count = list.Count; + for (var i = 1; i < count; i++) { + var key = list[i]; + var j = i - 1; + while (0 <= j && 0 < comparison(list[j], key)) { + list[j + 1] = list[j]; + j--; + } + list[j + 1] = key; + } + } + } +} diff --git a/Intar/Utility.cs.meta b/Intar/Utility.cs.meta new file mode 100644 index 000000000..bb110110c --- /dev/null +++ b/Intar/Utility.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: fe2eea8ac0eb02740bb044dcd32f2edf \ No newline at end of file From 0b9975a47f60e86b9d9207af88d0f2bfa7701b68 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 9 Nov 2025 15:27:34 +0000 Subject: [PATCH 2/2] Initial plan