Skip to content

Commit dd4d4bb

Browse files
authored
ArgumentOutOfRangeException fix (#27)
* Prevent ArgumentOutOfRangeException if normalizedT >= 2 or <= -2 Authored-by: Olaf Horbowy <olafhorbowy@pm.me>
1 parent 6e4e8ef commit dd4d4bb

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

Plugins/BezierSolution/BezierSpline.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -618,11 +618,9 @@ public Vector3 GetPoint( float normalizedT )
618618
}
619619
else
620620
{
621-
// 2nd conditions isn't 'else if' because in rare occasions, floating point precision issues may arise; e.g. for normalizedT = -0.0000000149,
622-
// incrementing the value by 1 results in perfect 1.0000000000 with no mantissa
623-
if( normalizedT < 0f )
621+
while( normalizedT < 0f )
624622
normalizedT += 1f;
625-
if( normalizedT >= 1f )
623+
while( normalizedT >= 1f )
626624
normalizedT -= 1f;
627625
}
628626

@@ -662,9 +660,9 @@ public Vector3 GetTangent( float normalizedT )
662660
}
663661
else
664662
{
665-
if( normalizedT < 0f )
663+
while( normalizedT < 0f )
666664
normalizedT += 1f;
667-
if( normalizedT >= 1f )
665+
while( normalizedT >= 1f )
668666
normalizedT -= 1f;
669667
}
670668

@@ -700,9 +698,9 @@ public Vector3 GetNormal( float normalizedT )
700698
}
701699
else
702700
{
703-
if( normalizedT < 0f )
701+
while( normalizedT < 0f )
704702
normalizedT += 1f;
705-
if( normalizedT >= 1f )
703+
while( normalizedT >= 1f )
706704
normalizedT -= 1f;
707705
}
708706

@@ -756,9 +754,9 @@ public BezierPoint.ExtraData GetExtraData( float normalizedT, ExtraDataLerpFunct
756754
}
757755
else
758756
{
759-
if( normalizedT < 0f )
757+
while( normalizedT < 0f )
760758
normalizedT += 1f;
761-
if( normalizedT >= 1f )
759+
while( normalizedT >= 1f )
762760
normalizedT -= 1f;
763761
}
764762

@@ -815,9 +813,9 @@ public Segment GetSegmentAt( float normalizedT )
815813
}
816814
else
817815
{
818-
if( normalizedT < 0f )
816+
while( normalizedT < 0f )
819817
normalizedT += 1f;
820-
if( normalizedT >= 1f )
818+
while( normalizedT >= 1f )
821819
normalizedT -= 1f;
822820
}
823821

@@ -1503,4 +1501,4 @@ internal void Reset()
15031501
}
15041502
#endif
15051503
}
1506-
}
1504+
}

Plugins/BezierSolution/Other/BezierDataStructures.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ public float GetPercentageAtNormalizedT( float normalizedT )
169169
}
170170
else
171171
{
172-
if( normalizedT < 0f )
172+
while( normalizedT < 0f )
173173
normalizedT += 1f;
174-
if( normalizedT >= 1f )
174+
while( normalizedT >= 1f )
175175
normalizedT -= 1f;
176176
}
177177

@@ -228,9 +228,9 @@ public BezierPoint.ExtraData GetExtraData( float percentage, ExtraDataLerpFuncti
228228
}
229229
else
230230
{
231-
if( percentage < 0f )
231+
while( percentage < 0f )
232232
percentage += 1f;
233-
if( percentage >= 1f )
233+
while( percentage >= 1f )
234234
percentage -= 1f;
235235
}
236236

@@ -256,9 +256,9 @@ private Vector3 LerpArray( Vector3[] array, float percentage )
256256
}
257257
else
258258
{
259-
if( percentage < 0f )
259+
while( percentage < 0f )
260260
percentage += 1f;
261-
if( percentage >= 1f )
261+
while( percentage >= 1f )
262262
percentage -= 1f;
263263
}
264264

@@ -341,4 +341,4 @@ public static ExtraData LerpUnclamped( ExtraData a, ExtraData b, float t )
341341
public override string ToString() { return ( (Vector4) this ).ToString(); }
342342
}
343343
}
344-
}
344+
}

0 commit comments

Comments
 (0)