public void Point3() { ITestSpline testSpline = PrepareSpline(); float3 a = float3.zero; AddControlPointLocalSpace(testSpline, a); float3 b = new float3(2.5f, 0f, 0f); AddControlPointLocalSpace(testSpline, b); float3 c = new float3(7.5f, 0f, 0f); AddControlPointLocalSpace(testSpline, c); float3 d = new float3(10f, 0f, 0f); AddControlPointLocalSpace(testSpline, d); Assert.AreEqual(4, testSpline.ControlPointCount); Assert.AreEqual(4, testSpline.Modes.Count); Assert.AreEqual(10f, testSpline.Length()); Assert.AreEqual(2, testSpline.Times.Count); // a-b-c 1st spline segment Assert.AreEqual(0.5f, testSpline.Times[0]); // b-c-d 2nd spline segment Assert.AreEqual(1f, testSpline.Times[1]); ComparePoint(a, GetProgressWorld(testSpline, -1f)); ComparePoint(a, GetProgressWorld(testSpline, 0f)); ComparePoint(new float3(5f, 0f, 0f), GetProgressWorld(testSpline, 0.5f)); ComparePoint(d, GetProgressWorld(testSpline, 1f)); ComparePoint(d, GetProgressWorld(testSpline, 1.5f)); ComparePoint(d, GetProgressWorld(testSpline, 5f)); }
public override ITestSpline CreateNewSpline() { GameObject game = new GameObject(); ITestSpline spline = game.AddComponent <MeaninglessTestWrapper2.TestLinearCubicSpline3DPlaneSimpleJob>(); return(spline); }
public void PointCreation() { ITestSpline testSpline = PrepareSpline(); float3 a = float3.zero; AddControlPointLocalSpace(testSpline, a); Assert.AreEqual(1, testSpline.ControlPointCount); Assert.AreEqual(1, testSpline.Modes.Count); Assert.AreEqual(1, testSpline.Times.Count); Assert.AreEqual(1, testSpline.ControlPointCount); ComparePoint(a, GetControlPoint(testSpline, 0, SplinePoint.Point)); float3 b = new float3(10f, 0f, 0f); AddControlPointLocalSpace(testSpline, b); Assert.AreEqual(2, testSpline.ControlPointCount); Assert.AreEqual(2, testSpline.Modes.Count); Assert.AreEqual(1, testSpline.Times.Count); Assert.AreEqual(10f, testSpline.Length()); Assert.AreEqual(2, testSpline.ControlPointCount); ComparePoint(a, GetControlPoint(testSpline, 0, SplinePoint.Point)); ComparePoint(new float3(1f, 0f, 0f), GetControlPoint(testSpline, 0, SplinePoint.Post)); ComparePoint(new float3(9f, 0f, 0f), GetControlPoint(testSpline, 1, SplinePoint.Pre)); ComparePoint(b, GetControlPoint(testSpline, 1, SplinePoint.Point)); }
public void Point3() { ITestSpline testSpline = PrepareSpline(); float3 a = float3.zero; AddControlPointLocalSpace(testSpline, a); float3 b = new float3(2.5f, 0f, 0f); AddControlPointLocalSpace(testSpline, b); float3 c = new float3(7.5f, 0f, 0f); AddControlPointLocalSpace(testSpline, c); float3 d = new float3(10f, 0f, 0f); AddControlPointLocalSpace(testSpline, d); Assert.AreEqual(4, testSpline.ControlPointCount); Assert.AreEqual(4, testSpline.Modes.Count); Assert.AreEqual(10f, testSpline.Length()); Assert.AreEqual(testSpline.ExpectedTimeCount(testSpline.ControlPointCount), testSpline.Times.Count); Assert.AreEqual(0.25f, testSpline.Times[0]); Assert.AreEqual(0.75f, testSpline.Times[1]); Assert.AreEqual(1f, testSpline.Times[2]); ComparePoint(a, GetProgressWorld(testSpline, 0f)); ComparePoint(b, GetProgressWorld(testSpline, 0.25f)); ComparePoint(new float3(5f, 0f, 0f), GetProgressWorld(testSpline, 0.5f)); ComparePoint(d, GetProgressWorld(testSpline, 1f)); ComparePoint(d, GetProgressWorld(testSpline, 1.5f)); ComparePoint(d, GetProgressWorld(testSpline, 5f)); }
public void NoEditModeChange([Values] SplineEditMode mode) { ITestSpline testSpline = PrepareSpline(); float3 a = float3.zero; AddControlPointLocalSpace(testSpline, a); testSpline.ChangeEditMode(0, mode); Assert.AreEqual(SplineEditMode.Standard, testSpline.GetEditMode(0)); }
public void TwoPointLoopback() { ITestSpline testSpline = PrepareSpline(); float3 a = new float3(10f, 10f, 3f); AddControlPointLocalSpace(testSpline, a); float3 b = new float3(20f, 20f, 3f); AddControlPointLocalSpace(testSpline, b); TestHelpers.CheckFloat3(a, GetProgressWorld(testSpline, 0f)); TestHelpers.CheckFloat3(math.lerp(a, b, 0.5f), GetProgressWorld(testSpline, 0.5f)); TestHelpers.CheckFloat3(math.lerp(a, b, 0.7f), GetProgressWorld(testSpline, 0.7f)); TestHelpers.CheckFloat3(b, GetProgressWorld(testSpline, 1f)); }
public void RotationPrePoint() { ITestSpline testSpline = PrepareSpline(); // rotate Quaternion targetRotation = Quaternion.Euler(0f, 90f, 0f); ((MonoBehaviour)testSpline).transform.rotation = targetRotation; // add point float3 a = new float3(10f, 10f, 0f); InsertControlPointLocalSpace(testSpline, 12, a); ComparePoint(targetRotation * a, GetProgressWorld(testSpline, 0f)); ComparePoint(a, GetControlPoint(testSpline, 0, SplinePoint.Point)); }
public void ZigZagLength() { ITestSpline testSpline = PrepareSpline(); float3 a = new float3(0f, 0f, 0f); float3 b = new float3(10f, 10f, 0f); float3 c = new float3(0f, 20f, 0f); float3 d = new float3(20f, 30f, 0f); AddControlPointLocalSpace(testSpline, a); AddControlPointLocalSpace(testSpline, d); InsertControlPointWorldSpace(testSpline, 1, b); InsertControlPointWorldSpace(testSpline, 2, c); float minLength = math.distance(a, b) + math.distance(b, c) + math.distance(c, d); Assert.Greater(testSpline.Length(), minLength); }
public void ZigZagLength2() { ITestSpline testSpline = PrepareSpline(); float3 a = new float3(0f, 0f, 0f); AddControlPointLocalSpace(testSpline, a); float3 b = new float3(1f, 3f, 0f); AddControlPointLocalSpace(testSpline, b); UpdateControlPoint(testSpline, 0, new float3(1f, 0f, 0f), SplinePoint.Post); UpdateControlPoint(testSpline, 1, new float3(0f, 3f, 0f), SplinePoint.Pre); float length = math.distance(a, b); Assert.Greater(testSpline.Length(), length); }
public void TranslationRotation() { ITestSpline testSpline = PrepareSpline(); // move spline float3 move = new float3(10f, 0f, 10f); ((MonoBehaviour)testSpline).transform.position = move; // rotate spline Quaternion targetRotation = Quaternion.Euler(0f, 90f, 0f); ((MonoBehaviour)testSpline).transform.rotation = targetRotation; // add to spline float3 a = new float3(20f, 3f, 4f); InsertControlPointLocalSpace(testSpline, 12, a); ComparePoint(a, GetControlPoint(testSpline, 0, SplinePoint.Point)); if (testSpline is ISpline3DPlane) { Debug.Log(""); float3 rotation = targetRotation * new float3(a.xy, 0); Debug.Log($"GameObject Rotation: {rotation:N5}"); Debug.Log(""); float3 world = GetProgressWorld(testSpline, 0f); Debug.Log($"WorldPos: {world:N5}"); ComparePoint(move + rotation, world); Debug.Log(""); float3 local = GetProgressLocal(testSpline, 0f); Debug.Log($"LocalPos: {local:N5}"); ComparePoint(rotation, local); Debug.Log(""); } else { ComparePoint(a, GetProgressLocal(testSpline, 0f)); ComparePoint(move + (float3)(targetRotation * a), GetProgressWorld(testSpline, 0f)); } }
public void Point5() { ITestSpline testSpline = PrepareSpline(); float3 a = new float3(1f, 10f, 0f); AddControlPointLocalSpace(testSpline, a); float3 b = new float3(2f, 10f, 0f); AddControlPointLocalSpace(testSpline, b); float3 c = new float3(3f, 10f, 0f); AddControlPointLocalSpace(testSpline, c); Assert.AreEqual(3, testSpline.ControlPointCount); Assert.AreEqual(2f, testSpline.Length()); ComparePoint(new float3(2.5f, 10f, 0f), GetProgressWorld(testSpline, 0.7f), 0.01f); }
public void ZigZagLength2() { ITestSpline testSpline = PrepareSpline(); float3 a = new float3(0f, 0f, 1f); AddControlPointLocalSpace(testSpline, a); float3 b = new float3(1f, 3f, 1f); AddControlPointLocalSpace(testSpline, b); UpdateControlPoint(testSpline, 0, new float3(1f, 0f, 1f), SplinePoint.Post); UpdateControlPoint(testSpline, 1, new float3(0f, 3f, 1f), SplinePoint.Pre); float length = math.distance(a, b); float spline = testSpline.Length(); Assert.IsTrue(math.abs(length - spline) <= 0.00005f, $"Expected: {length}, but received: {spline}"); }
public void ZigZagLength() { ITestSpline testSpline = PrepareSpline(); float3 a = new float3(0f, 0f, 1f); AddControlPointLocalSpace(testSpline, a); float3 b = new float3(10f, 10f, 1f); AddControlPointLocalSpace(testSpline, b); float3 c = new float3(0f, 20f, 1f); AddControlPointLocalSpace(testSpline, c); float3 d = new float3(20f, 30f, 1f); AddControlPointLocalSpace(testSpline, d); float length = math.distance(a, b) + math.distance(b, c) + math.distance(c, d); float spline = testSpline.Length(); Assert.Less(spline, length); }
public void ZigZagLength() { ITestSpline testSpline = PrepareSpline(); float3 a = new float3(0f, 0f, 1f); AddControlPointLocalSpace(testSpline, a); float3 b = new float3(10f, 10f, 1f); AddControlPointLocalSpace(testSpline, b); float3 c = new float3(0f, 20f, 1f); AddControlPointLocalSpace(testSpline, c); float3 d = new float3(20f, 30f, 1f); AddControlPointLocalSpace(testSpline, d); float length = math.distance(a, b) + math.distance(b, c) + math.distance(c, d); float spline = testSpline.Length(); Assert.IsTrue(math.abs(length - spline) <= 0.00005f, $"Expected: {length}, but received: {spline}"); }
public override void CompareProgressNotEquals(ITestSpline spline, float progress, float3 expectedPoint) => s_splineBase.CompareProgressNotEquals(spline as ISpline2D, progress, expectedPoint);
public override void CompareProgressEquals(ITestSpline spline, float progress, float3 expectedPoint, float tolerance = 0.00001f) => s_splineBase.CompareProgressEquals(spline as ISpline2D, progress, expectedPoint, tolerance);
public override float3 GetProgressLocal(ITestSpline spline, float progress) => s_splineBase.GetProgressLocal(spline as ISpline2D, progress);
public override void UpdateControlPoint(ITestSpline spline, int index, float3 newPoint, SplinePoint pointType) => s_splineBase.UpdateControlPoint(spline as ISpline2D, index, newPoint, pointType);
public override float3 GetControlPoint(ITestSpline spline, int index, SplinePoint pointType) => s_splineBase.GetControlPoint(spline as ISpline2D, index, pointType);
public override void InsertControlPointLocalSpace(ITestSpline spline, int index, float3 point) => s_splineBase.InsertControlPointWorldSpace(spline as ISpline2D, index, point);
public override void AddControlPointLocalSpace(ITestSpline spline, float3 point) => s_splineBase.AddControlPointLocalSpace(spline as ISpline2D, point);
public override float3 GetProgressWorld(ITestSpline spline, float progress) => s_splineBase.GetProgressWorld(spline as ISpline3DPlane, progress);