Skip to content

Commit 5bec75d

Browse files
committed
Add processors to wrap numbers between 0 and 1
1 parent 4f07a69 commit 5bec75d

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

Runtime/Processors.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using UnityEngine;
1+
using UnityEngine;
22

33
namespace Zigurous.Math
44
{
@@ -304,6 +304,36 @@ public static uint Wrap(uint input, uint min, uint max)
304304
}
305305
}
306306

307+
/// <summary>
308+
/// Wraps the input to the range [0..1]. If the value exceeds 1 it wraps
309+
/// around to 0, and if the value is less than 0 it wraps back to 1.
310+
/// </summary>
311+
public static float Wrap01(float input)
312+
{
313+
if (input < 0.0f) {
314+
return 1.0f + input % 1.0f;
315+
} else if (input > 1.0f) {
316+
return input % 1.0f;
317+
} else {
318+
return input;
319+
}
320+
}
321+
322+
/// <summary>
323+
/// Wraps the input to the range [0..1]. If the value exceeds 1 it wraps
324+
/// around to 0, and if the value is less than 0 it wraps back to 1.
325+
/// </summary>
326+
public static double Wrap01(double input)
327+
{
328+
if (input < 0.0) {
329+
return 1.0 + input % 1.0;
330+
} else if (input > 1.0) {
331+
return input % 1.0;
332+
} else {
333+
return input;
334+
}
335+
}
336+
307337
}
308338

309339
}

0 commit comments

Comments
 (0)