Skip to content
Merged
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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,22 @@ using RhythmGameUtilities;
var value = Utilities.RoundUpToTheNearestMultiplier(12, 10);
```

#### `Utilities.Lerp`
### Common

#### `Common.Lerp`

```csharp
using RhythmGameUtilities;

var value = Utilities.Lerp(0, 10, 0.5f);
var value = Common.Lerp(0, 10, 0.5f);
```

#### `Utilities.InverseLerp`

```csharp
using RhythmGameUtilities;

var value = Utilities.InverseLerp(0, 10, 5);
var value = Common.InverseLerp(0, 10, 5);
```

## Architecture
Expand Down
27 changes: 27 additions & 0 deletions RhythmGameUtilities.Tests/CommonTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using NUnit.Framework;

namespace RhythmGameUtilities.Tests
{

public class CommonTest
{

[Test]
public void TestLerp()
{
Assert.That(Common.Lerp(0, 10, 0), Is.EqualTo(0));
Assert.That(Common.Lerp(0, 10, 0.5f), Is.EqualTo(5));
Assert.That(Common.Lerp(0, 10, 1), Is.EqualTo(10));
}

[Test]
public void TestInverseLerp()
{
Assert.That(Common.InverseLerp(0, 10, 0), Is.EqualTo(0));
Assert.That(Common.InverseLerp(0, 10, 5), Is.EqualTo(0.5f));
Assert.That(Common.InverseLerp(0, 10, 10), Is.EqualTo(1));
}

}

}
17 changes: 0 additions & 17 deletions RhythmGameUtilities.Tests/UtilitiesTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;

Expand Down Expand Up @@ -52,22 +51,6 @@ public void TestRoundUpToTheNearestMultiplier()
Assert.That(Utilities.RoundUpToTheNearestMultiplier(12, 10), Is.EqualTo(20));
}

[Test]
public void TestLerp()
{
Assert.That(Utilities.Lerp(0, 10, 0), Is.EqualTo(0));
Assert.That(Utilities.Lerp(0, 10, 0.5f), Is.EqualTo(5));
Assert.That(Utilities.Lerp(0, 10, 1), Is.EqualTo(10));
}

[Test]
public void TestInverseLerp()
{
Assert.That(Utilities.InverseLerp(0, 10, 0), Is.EqualTo(0));
Assert.That(Utilities.InverseLerp(0, 10, 5), Is.EqualTo(0.5f));
Assert.That(Utilities.InverseLerp(0, 10, 10), Is.EqualTo(1));
}

[Test]
public void TestCalculateBeatBars()
{
Expand Down
44 changes: 44 additions & 0 deletions RhythmGameUtilities/Scripts/Common.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Runtime.InteropServices;

namespace RhythmGameUtilities
{

public static class CommonInternal
{

#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
[DllImport("libRhythmGameUtilities.dylib", CallingConvention = CallingConvention.Cdecl)]
#elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
[DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)]
#endif
public static extern float Lerp(float a, float b, float t);

#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
[DllImport("libRhythmGameUtilities.dylib", CallingConvention = CallingConvention.Cdecl)]
#elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
[DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)]
#endif
public static extern float InverseLerp(float a, float b, float v);

}

public static class Common
{

public static float Lerp(float a, float b, float t)
{
return CommonInternal.Lerp(a, b, t);
}

public static float InverseLerp(float a, float b, float v)
{
return CommonInternal.InverseLerp(a, b, v);
}

}

}
28 changes: 0 additions & 28 deletions RhythmGameUtilities/Scripts/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,6 @@ public static extern int ConvertSecondsToTicksInternal(float seconds, int resolu
#endif
public static extern int RoundUpToTheNearestMultiplier(int value, int multiplier);

#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
[DllImport("libRhythmGameUtilities.dylib", CallingConvention = CallingConvention.Cdecl)]
#elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
[DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)]
#endif
public static extern float Lerp(float a, float b, float t);

#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
[DllImport("libRhythmGameUtilities.dylib", CallingConvention = CallingConvention.Cdecl)]
#elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
[DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)]
#endif
public static extern float InverseLerp(float a, float b, float v);

#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
Expand Down Expand Up @@ -103,16 +85,6 @@ public static int RoundUpToTheNearestMultiplier(int value, int multiplier)
return UtilitiesInternal.RoundUpToTheNearestMultiplier(value, multiplier);
}

public static float Lerp(float a, float b, float t)
{
return UtilitiesInternal.Lerp(a, b, t);
}

public static float InverseLerp(float a, float b, float v)
{
return UtilitiesInternal.InverseLerp(a, b, v);
}

public static List<BeatBar> CalculateBeatBars(Dictionary<int, int> bpmChanges, int resolution = 192, int ts = 4,
bool includeHalfNotes = true)
{
Expand Down
27 changes: 27 additions & 0 deletions UnityPackage/Editor/Tests/CommonTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using NUnit.Framework;

namespace RhythmGameUtilities.Tests
{

public class CommonTest
{

[Test]
public void TestLerp()
{
Assert.That(Common.Lerp(0, 10, 0), Is.EqualTo(0));
Assert.That(Common.Lerp(0, 10, 0.5f), Is.EqualTo(5));
Assert.That(Common.Lerp(0, 10, 1), Is.EqualTo(10));
}

[Test]
public void TestInverseLerp()
{
Assert.That(Common.InverseLerp(0, 10, 0), Is.EqualTo(0));
Assert.That(Common.InverseLerp(0, 10, 5), Is.EqualTo(0.5f));
Assert.That(Common.InverseLerp(0, 10, 10), Is.EqualTo(1));
}

}

}
11 changes: 11 additions & 0 deletions UnityPackage/Editor/Tests/CommonTest.cs.meta

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

17 changes: 0 additions & 17 deletions UnityPackage/Editor/Tests/UtilitiesTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;

Expand Down Expand Up @@ -52,22 +51,6 @@ public void TestRoundUpToTheNearestMultiplier()
Assert.That(Utilities.RoundUpToTheNearestMultiplier(12, 10), Is.EqualTo(20));
}

[Test]
public void TestLerp()
{
Assert.That(Utilities.Lerp(0, 10, 0), Is.EqualTo(0));
Assert.That(Utilities.Lerp(0, 10, 0.5f), Is.EqualTo(5));
Assert.That(Utilities.Lerp(0, 10, 1), Is.EqualTo(10));
}

[Test]
public void TestInverseLerp()
{
Assert.That(Utilities.InverseLerp(0, 10, 0), Is.EqualTo(0));
Assert.That(Utilities.InverseLerp(0, 10, 5), Is.EqualTo(0.5f));
Assert.That(Utilities.InverseLerp(0, 10, 10), Is.EqualTo(1));
}

[Test]
public void TestCalculateBeatBars()
{
Expand Down
8 changes: 5 additions & 3 deletions UnityPackage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,22 @@ using RhythmGameUtilities;
var value = Utilities.RoundUpToTheNearestMultiplier(12, 10);
```

#### `Utilities.Lerp`
### Common

#### `Common.Lerp`

```csharp
using RhythmGameUtilities;

var value = Utilities.Lerp(0, 10, 0.5f);
var value = Common.Lerp(0, 10, 0.5f);
```

#### `Utilities.InverseLerp`

```csharp
using RhythmGameUtilities;

var value = Utilities.InverseLerp(0, 10, 5);
var value = Common.InverseLerp(0, 10, 5);
```

## Architecture
Expand Down
44 changes: 44 additions & 0 deletions UnityPackage/Scripts/Common.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Runtime.InteropServices;

namespace RhythmGameUtilities
{

public static class CommonInternal
{

#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
[DllImport("libRhythmGameUtilities.dylib", CallingConvention = CallingConvention.Cdecl)]
#elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
[DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)]
#endif
public static extern float Lerp(float a, float b, float t);

#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
[DllImport("libRhythmGameUtilities.dylib", CallingConvention = CallingConvention.Cdecl)]
#elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
[DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)]
#endif
public static extern float InverseLerp(float a, float b, float v);

}

public static class Common
{

public static float Lerp(float a, float b, float t)
{
return CommonInternal.Lerp(a, b, t);
}

public static float InverseLerp(float a, float b, float v)
{
return CommonInternal.InverseLerp(a, b, v);
}

}

}
11 changes: 11 additions & 0 deletions UnityPackage/Scripts/Common.cs.meta

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

28 changes: 0 additions & 28 deletions UnityPackage/Scripts/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,6 @@ public static extern int ConvertSecondsToTicksInternal(float seconds, int resolu
#endif
public static extern int RoundUpToTheNearestMultiplier(int value, int multiplier);

#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
[DllImport("libRhythmGameUtilities.dylib", CallingConvention = CallingConvention.Cdecl)]
#elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
[DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)]
#endif
public static extern float Lerp(float a, float b, float t);

#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
[DllImport("libRhythmGameUtilities.dylib", CallingConvention = CallingConvention.Cdecl)]
#elif LINUX_BUILD || UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX
[DllImport("libRhythmGameUtilities.so", CallingConvention = CallingConvention.Cdecl)]
#endif
public static extern float InverseLerp(float a, float b, float v);

#if WINDOWS_BUILD || UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
[DllImport("libRhythmGameUtilities.dll", CallingConvention = CallingConvention.Cdecl)]
#elif MACOS_BUILD || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
Expand Down Expand Up @@ -103,16 +85,6 @@ public static int RoundUpToTheNearestMultiplier(int value, int multiplier)
return UtilitiesInternal.RoundUpToTheNearestMultiplier(value, multiplier);
}

public static float Lerp(float a, float b, float t)
{
return UtilitiesInternal.Lerp(a, b, t);
}

public static float InverseLerp(float a, float b, float v)
{
return UtilitiesInternal.InverseLerp(a, b, v);
}

public static List<BeatBar> CalculateBeatBars(Dictionary<int, int> bpmChanges, int resolution = 192, int ts = 4,
bool includeHalfNotes = true)
{
Expand Down
Loading