mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2025-02-20 11:58:28 +08:00
Some Calc comments. Cardinals enum
This commit is contained in:
parent
95c2d5f12f
commit
17fc10eb7c
@ -5,12 +5,14 @@ namespace Strawberry
|
||||
{
|
||||
static public class Calc
|
||||
{
|
||||
//Move toward a target value without crossing it
|
||||
[Inline]
|
||||
static public float Approach(float value, float target, float maxDelta)
|
||||
{
|
||||
return value > target ? Math.Max(value - maxDelta, target) : Math.Min(value + maxDelta, target);
|
||||
}
|
||||
|
||||
//Convert from a value between arbitrary min and max to between 0 and 1
|
||||
[Inline]
|
||||
static public float Map(float value, float oldMin, float oldMax)
|
||||
{
|
||||
@ -18,28 +20,33 @@ namespace Strawberry
|
||||
}
|
||||
|
||||
[Inline]
|
||||
//Convert from a value between arbitrary min and max to between any other min and max
|
||||
static public float Map(float value, float oldMin, float oldMax, float newMin, float newMax)
|
||||
{
|
||||
return newMin + (newMax - newMin) * Map(value, oldMin, oldMax);
|
||||
}
|
||||
|
||||
[Inline]
|
||||
//Convert from a value between arbitrary min and max to between 0 and 1, and clamp it between 0 and 1
|
||||
static public float ClampedMap(float value, float oldMin, float oldMax)
|
||||
{
|
||||
return Math.Clamp((value - oldMin) / (oldMax - oldMin), 0, 1);
|
||||
}
|
||||
|
||||
[Inline]
|
||||
//Convert from a value between arbitrary min and max to between any other min and max, and clamp it within that range
|
||||
static public float ClampedMap(float value, float oldMin, float oldMax, float newMin, float newMax)
|
||||
{
|
||||
return newMin + (newMax - newMin) * ClampedMap(value, oldMin, oldMax);
|
||||
}
|
||||
|
||||
[Inline]
|
||||
static public void Log()
|
||||
{
|
||||
Debug.WriteLine("***");
|
||||
}
|
||||
|
||||
[Inline]
|
||||
static public void Log<T>(T v)
|
||||
{
|
||||
String string = scope String;
|
||||
|
70
src/Struct/Cardinals.bf
Normal file
70
src/Struct/Cardinals.bf
Normal file
@ -0,0 +1,70 @@
|
||||
namespace Strawberry
|
||||
{
|
||||
public enum Cardinals
|
||||
{
|
||||
case Right;
|
||||
case Down;
|
||||
case Left;
|
||||
case Up;
|
||||
|
||||
public Cardinals Opposite()
|
||||
{
|
||||
switch (this)
|
||||
{
|
||||
case .Right:
|
||||
return .Left;
|
||||
case .Left:
|
||||
return .Right;
|
||||
case .Up:
|
||||
return .Down;
|
||||
case .Down:
|
||||
return .Up;
|
||||
}
|
||||
}
|
||||
|
||||
public Cardinals NextClockwise()
|
||||
{
|
||||
switch (this)
|
||||
{
|
||||
case .Right:
|
||||
return .Down;
|
||||
case .Left:
|
||||
return .Up;
|
||||
case .Up:
|
||||
return .Right;
|
||||
case .Down:
|
||||
return .Left;
|
||||
}
|
||||
}
|
||||
|
||||
public Cardinals NextCounterClockwise()
|
||||
{
|
||||
switch (this)
|
||||
{
|
||||
case .Right:
|
||||
return .Up;
|
||||
case .Left:
|
||||
return .Down;
|
||||
case .Up:
|
||||
return .Left;
|
||||
case .Down:
|
||||
return .Right;
|
||||
}
|
||||
}
|
||||
|
||||
static public implicit operator Point(Cardinals c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case .Right:
|
||||
return Point.Right;
|
||||
case .Left:
|
||||
return Point.Left;
|
||||
case .Up:
|
||||
return Point.Up;
|
||||
case .Down:
|
||||
return Point.Down;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user