Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Intar.Tests/AnimationCurveTest.Unity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
}
27 changes: 27 additions & 0 deletions Intar.Tests/AnimationCurveTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}

}
}
1 change: 1 addition & 0 deletions Intar/AnimationCurveI17F15.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public KeyframeI17F15[] Keys {
return;
}
keys = new List<KeyframeI17F15>(value);
Utility.InsertionSort(keys, (a, b) => a.Time.CompareTo(b.Time));
}
}
public int Length {
Expand Down
22 changes: 22 additions & 0 deletions Intar/Utility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;

namespace Intar {
/// <summary>
/// 主に実装用のユーティリティクラス
/// </summary>
static class Utility {
internal static void InsertionSort<T>(IList<T> list, Comparison<T> 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;
}
}
}
}
2 changes: 2 additions & 0 deletions Intar/Utility.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.