Skip to content

Commit

Permalink
Fixed all tests and converted bespoke 3D tests to the functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
crener committed Oct 4, 2020
1 parent d1be7ba commit 7e76d34
Show file tree
Hide file tree
Showing 16 changed files with 234 additions and 240 deletions.
10 changes: 5 additions & 5 deletions Assets/Crener.Spline/BaseSpline/BaseSpline3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public virtual void AddControlPoint(float3 point)
/// <param name="index">segment index</param>
/// <param name="point">location to insert</param>
public virtual void InsertControlPointWorldSpace(int index, float3 point)
{
InsertControlPointLocalSpace(index, ConvertToLocalSpace(point));
}

public virtual void InsertControlPointLocalSpace(int index, float3 point)
{
if(Points.Count < 1 || index >= ControlPointCount)
{
Expand All @@ -86,11 +91,6 @@ public virtual void InsertControlPointWorldSpace(int index, float3 point)
RecalculateLengthBias();
}

public virtual void InsertControlPointLocalSpace(int index, float3 point)
{
InsertControlPointWorldSpace(index, point);
}

/// <summary>
/// Remove existing control points data
/// </summary>
Expand Down
18 changes: 9 additions & 9 deletions Assets/Crener.Spline/BezierSpline/BezierSpline3DSimple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,23 @@ public override void AddControlPoint(float3 point)
/// <param name="mode">type of point to update</param>
public override void UpdateControlPointWorld(int index, float3 point, SplinePoint mode)
{
Assert.IsTrue(index <= ControlPointCount);

int i = IndexMode(index, mode);
Points[i] = point;

RecalculateLengthBias();
UpdateControlPointLocal(index, ConvertToLocalSpace(point), mode);
}

/// <summary>
/// Update an existing control points data
/// </summary>
/// <param name="index">control point index</param>
/// <param name="point">location of the point in world space</param>
/// <param name="point">location of the point</param>
/// <param name="mode">type of point to update</param>
public void UpdateControlPointFromWorld(int index, float3 point, SplinePoint mode)
public override void UpdateControlPointLocal(int index, float3 point, SplinePoint mode)
{
UpdateControlPointWorld(index, ConvertToLocalSpace(point), mode);
Assert.IsTrue(index <= ControlPointCount);

int i = IndexMode(index, mode);
Points[i] = point;

RecalculateLengthBias();
}

/// <summary>
Expand Down
18 changes: 9 additions & 9 deletions Assets/Crener.Spline/Editor/3D/BezierSpline3DSimpleEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected void RenderControlPoints()
UpdateOppositePoint(postMagnitude, point, newPos, i, SplinePoint.Post);
}

bezierSpline.UpdateControlPointFromWorld(i, newPos, SplinePoint.Pre);
bezierSpline.UpdateControlPointWorld(i, newPos, SplinePoint.Pre);
break;
}
case SplineEditMode.Mirror:
Expand All @@ -119,11 +119,11 @@ protected void RenderControlPoints()
UpdateOppositePoint(preMagnitude, point, newPos, i, SplinePoint.Post);
}

bezierSpline.UpdateControlPointFromWorld(i, newPos, SplinePoint.Pre);
bezierSpline.UpdateControlPointWorld(i, newPos, SplinePoint.Pre);
break;
}
case SplineEditMode.Free:
bezierSpline.UpdateControlPointFromWorld(i, newPos, SplinePoint.Pre);
bezierSpline.UpdateControlPointWorld(i, newPos, SplinePoint.Pre);
break;
default:
throw new ArgumentOutOfRangeException();
Expand All @@ -147,7 +147,7 @@ protected void RenderControlPoints()
EditorUtility.SetDirty(bezierSpline);

float3 newPoint = new float3(pos.x, pos.y, pos.z);
bezierSpline.UpdateControlPointFromWorld(i, newPoint, SplinePoint.Point);
bezierSpline.UpdateControlPointWorld(i, newPoint, SplinePoint.Point);

if(m_editMoveWithTrans)
{
Expand All @@ -157,7 +157,7 @@ protected void RenderControlPoints()
void UpdatePoint(SplinePoint type)
{
float3 cp = bezierSpline.GetControlPoint3DWorld(i, type);
bezierSpline.UpdateControlPointFromWorld(i, cp + delta, type);
bezierSpline.UpdateControlPointWorld(i, cp + delta, type);
}

if(preExists) UpdatePoint(SplinePoint.Pre);
Expand Down Expand Up @@ -195,7 +195,7 @@ void UpdatePoint(SplinePoint type)
UpdateOppositePoint(preMagnitude, point, newPos, i, SplinePoint.Pre);
}

bezierSpline.UpdateControlPointFromWorld(i, newPos, SplinePoint.Post);
bezierSpline.UpdateControlPointWorld(i, newPos, SplinePoint.Post);
break;
}
case SplineEditMode.Mirror:
Expand All @@ -206,11 +206,11 @@ void UpdatePoint(SplinePoint type)
UpdateOppositePoint(postMagnitude, point, newPos, i, SplinePoint.Pre);
}

bezierSpline.UpdateControlPointFromWorld(i, newPos, SplinePoint.Post);
bezierSpline.UpdateControlPointWorld(i, newPos, SplinePoint.Post);
break;
}
case SplineEditMode.Free:
bezierSpline.UpdateControlPointFromWorld(i, newPos, SplinePoint.Post);
bezierSpline.UpdateControlPointWorld(i, newPos, SplinePoint.Post);
break;
default:
throw new ArgumentOutOfRangeException();
Expand Down Expand Up @@ -253,7 +253,7 @@ private void UpdateOppositePoint(float magnitude, float3 center, float3 newPos,
center.x + dir.x,
center.y + dir.y,
center.z + dir.z);
bezierSpline.UpdateControlPointFromWorld(i, updatedPoint, pointType);
bezierSpline.UpdateControlPointWorld(i, updatedPoint, pointType);
}
}
}
52 changes: 30 additions & 22 deletions Assets/Crener.Spline/Example/2D sample.unity
Original file line number Diff line number Diff line change
Expand Up @@ -549,42 +549,50 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
SegmentLength:
- 0.12168938
- 0.89337325
- 0.17499016
- 0.41864437
- 0.8466602
- 1
LengthCache: 9.380623
LengthCache: 6.52297
Points:
- x: 8.472568
y: 36.00013
- x: 8.96714
y: 37.027157
- x: 10.117895
y: 38.085167
- x: 11.039634
y: 37.027966
- x: 11.138698
y: 36.03266
a:
- 36.00013
- 37.027157
- 38.085167
- 37.027966
- 36.03266
b:
- 1.7522584
- 2.7252684
- -9.526738
- 2.373041
- 1.4837039
- 1.860088
- -9.120012
- 0
c:
- 0
- 1.9673753
- -7.879098
- -1.7981933
- 2.1252692
- -14.037648
- 0
d:
- 1.3259766
- -1.5836757
- 26.511845
- -1.211951
- 1.1364895
- -5.8450837
- 47.234337
- 0
segmentDistance:
- 0.49457264
- 2.0724936
- 1.1507549
- 0.9217386
- 0.09906387
--- !u!4 &426229413
Transform:
Expand Down Expand Up @@ -1361,7 +1369,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1294645324}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -23.32, y: 21.1, z: -13.91087}
m_LocalPosition: {x: -48.36, y: 41.56, z: -13.91087}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1775453985}
Expand All @@ -1380,17 +1388,17 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
SegmentLength:
- 0.3340142
- 0.63801426
- 0.3831854
- 0.7252086
- 1
LengthCache: 30.21701
LengthCache: 39.8052
Points:
- x: -25.32
y: 21.1
- x: -18.211926
y: 28.265343
- x: -14.449539
y: 19.885216
- x: -5.950001
y: -2.2199974
- x: 3.1006317
y: 10.057343
- x: 4.9204597
y: -3.434782
looped: 1
--- !u!1 &1393734955
GameObject:
Expand Down
112 changes: 56 additions & 56 deletions Assets/Crener.Spline/Example/3D sample.unity
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 75190060}
m_LocalRotation: {x: -0, y: 0.14460483, z: -0, w: 0.98948956}
m_LocalPosition: {x: 23.6, y: -1.81, z: 33.6}
m_LocalRotation: {x: 0, y: 0.7071068, z: 0, w: 0.7071068}
m_LocalPosition: {x: 67, y: 13.73, z: 22.3}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 635739486}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 16.629, z: 0}
m_LocalEulerAnglesHint: {x: 0, y: 90, z: 0}
--- !u!114 &75190062
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -173,45 +173,45 @@ MonoBehaviour:
- 1
LengthCache: 111.704544
Points:
- x: -18.43252
y: 15.546598
z: 10.889525
- x: -15.4290905
y: 15.0004835
z: 10.193729
- x: -4.8120327
y: 13.015839
z: 7.455065
- x: -0.98386955
y: 12.376356
z: 6.5279655
- x: 6.238865
y: 11.169822
z: 4.7787724
- x: 32.554768
y: 2.530325
z: 8.083285
- x: 42.744694
y: 3.0131817
z: 7.4399967
- x: 58.997166
y: 3.7833233
z: 6.413985
- x: 68.79529
y: 12.957303
z: -4.0144205
- x: 81.77658
y: 12.855606
z: -3.947092
- x: 82.77336
y: 12.93592
z: -4.943449
- x: 85.314255
y: 13.140649
z: -7.21945
- x: 86.311035
y: 13.220963
z: -8.215807
- x: -57.97252
y: 5.6166
z: 21.039528
- x: -54.969086
y: 5.070485
z: 20.34373
- x: -44.35204
y: 3.0858402
z: 17.605068
- x: -40.52387
y: 2.4463577
z: 16.677967
- x: -33.301136
y: 1.2398233
z: 14.928776
- x: -6.9852333
y: -7.3996735
z: 18.233288
- x: 3.204689
y: -6.9168167
z: 17.59
- x: 19.45716
y: -6.146675
z: 16.563984
- x: 29.25528
y: 3.0273046
z: 6.135582
- x: 42.236576
y: 2.9256077
z: 6.2029076
- x: 43.233353
y: 3.0059214
z: 5.2065544
- x: 45.774246
y: 3.2106504
z: 2.9305534
- x: 46.771027
y: 3.2909641
z: 1.9341927
PointEdit: 0000000000000000000000000000000000000000
arkParameterization: 0
arkLength: 0.1
Expand Down Expand Up @@ -737,13 +737,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 850266195}
m_LocalRotation: {x: 0.012725968, y: 0.58007646, z: -0.033247966, w: 0.81378376}
m_LocalPosition: {x: 44.8, y: 31.6, z: 44.8}
m_LocalRotation: {x: 0.01951505, y: 0.74008507, z: -0.029774828, w: 0.6715704}
m_LocalPosition: {x: 31.08, y: 58.37, z: 42.53}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 635739486}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 3.399, y: 70.897, z: -2.259}
m_LocalEulerAnglesHint: {x: 4.03, y: 95.535, z: -0.638}
--- !u!114 &850266197
MonoBehaviour:
m_ObjectHideFlags: 0
Expand All @@ -757,20 +757,20 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
SegmentLength:
- 0.26923728
- 0.26923734
- 0.5665167
- 1
LengthCache: 39.77907
LengthCache: 39.779076
Points:
- x: 24.098848
y: 24.719696
z: 3.506734
- x: 14.825594
y: 29.966507
z: 4.5939493
- x: 7.857342
y: 23.10698
z: -2.0568206
- x: 8.178848
y: -0.12030029
z: 1.4167366
- x: -1.09441
y: 5.1265106
z: 2.503952
- x: -8.06266
y: -1.733017
z: -4.14682
looped: 1
--- !u!1 &1293263843
GameObject:
Expand Down
9 changes: 1 addition & 8 deletions Assets/Crener.Spline/Test/3D/BaseSimpleSplineTests3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,16 +544,9 @@ public void TranslationRotation()
Quaternion targetRotation = Quaternion.Euler(0f, 90f, 0f);
((MonoBehaviour) testSpline).transform.rotation = targetRotation;

Assert.AreEqual(0, testSpline.ControlPointCount);
Assert.AreEqual(0, testSpline.Modes.Count);
Assert.AreEqual(1, testSpline.Times.Count);

float3 a = new float3(20f, 3f, 4f);
testSpline.InsertControlPointWorldSpace(12, a);

Assert.AreEqual(1, testSpline.ControlPointCount);
Assert.AreEqual(1, testSpline.Modes.Count);
Assert.AreEqual(1, testSpline.Times.Count);

TestHelpers.CheckFloat3(move + (float3)(targetRotation * a), testSpline.Get3DPoint(0f));
TestHelpers.CheckFloat3(a, testSpline.GetControlPoint(0, SplinePoint.Point));
}
Expand Down
Loading

0 comments on commit 7e76d34

Please sign in to comment.