Skip to content

Commit afe19da

Browse files
committed
RangeFloat replaced with ValueRange within ShapeEngine.
1 parent fb26ca6 commit afe19da

File tree

7 files changed

+35
-22
lines changed

7 files changed

+35
-22
lines changed

ShapeEngine/Core/RangeFloat.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,5 @@ public static bool OverlappingRange(float minA, float maxA, float minB, float ma
9696
return minB <= maxA && minA <= maxB;
9797
}
9898

99-
}
99+
}
100+

ShapeEngine/Core/RangeInt.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace ShapeEngine.Core;
66
/// <summary>
77
/// Deprecated! Will be removed in a future update. Please use ValueRange & ValueRangeInt.
88
/// </summary>
9+
10+
911
public class RangeInt
1012
{
1113
public int Min;
@@ -48,4 +50,5 @@ public int Clamp(int value)
4850
{
4951
return ShapeMath.Clamp(value, Min, Max);
5052
}
51-
}
53+
}
54+

ShapeEngine/Core/Shapes/Rect.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public bool SeperateAxis(Vector2 axisStart, Vector2 axisEnd)
302302
var rProjection = RangeHull(edgeARange, edgeBRange);
303303

304304
var axisRange = Segment.ProjectSegment(axisStart, axisEnd, n);
305-
return !axisRange.OverlappingRange(rProjection);
305+
return !axisRange.OverlapValueRange(rProjection);
306306
}
307307

308308
public Rect Lerp(Rect to, float f)
@@ -1168,7 +1168,7 @@ public static Segments GetEdges(Vector2 tl, Vector2 bl, Vector2 br, Vector2 tr)
11681168
public static Rect Empty => new();
11691169

11701170

1171-
private static RangeFloat RangeHull(RangeFloat a, RangeFloat b)
1171+
private static ValueRange RangeHull(ValueRange a, ValueRange b)
11721172
{
11731173
return new
11741174
(
@@ -2135,8 +2135,8 @@ public readonly bool OverlapShape(Rect b)
21352135
var bTopLeft = new Vector2(b.X, b.Y);
21362136
var bBottomRight = bTopLeft + new Vector2(b.Width, b.Height);
21372137
return
2138-
RangeFloat.OverlappingRange(aTopLeft.X, aBottomRight.X, bTopLeft.X, bBottomRight.X) &&
2139-
RangeFloat.OverlappingRange(aTopLeft.Y, aBottomRight.Y, bTopLeft.Y, bBottomRight.Y);
2138+
ValueRange.OverlapValueRange(aTopLeft.X, aBottomRight.X, bTopLeft.X, bBottomRight.X) &&
2139+
ValueRange.OverlapValueRange(aTopLeft.Y, aBottomRight.Y, bTopLeft.Y, bBottomRight.Y);
21402140
}
21412141
public readonly bool OverlapShape(Polygon poly)
21422142
{

ShapeEngine/Core/Shapes/Segment.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,10 @@ public static bool IsPointOnLine(Vector2 point, Vector2 start, Vector2 dir)
375375
{
376376
return IsPointOnRay(point, start, dir) || IsPointOnRay(point, start, -dir);
377377
}
378-
public static RangeFloat ProjectSegment(Vector2 aPos, Vector2 aEnd, Vector2 onto)
378+
public static ValueRange ProjectSegment(Vector2 aPos, Vector2 aEnd, Vector2 onto)
379379
{
380-
Vector2 unitOnto = Vector2.Normalize(onto);
381-
RangeFloat r = new(ShapeVec.Dot(unitOnto, aPos), ShapeVec.Dot(unitOnto, aEnd));
380+
var unitOnto = Vector2.Normalize(onto);
381+
ValueRange r = new(ShapeVec.Dot(unitOnto, aPos), ShapeVec.Dot(unitOnto, aEnd));
382382
return r;
383383
}
384384
public static bool SegmentOnOneSide(Vector2 axisPos, Vector2 axisDir, Vector2 segmentStart, Vector2 segmentEnd)
@@ -499,7 +499,7 @@ public static bool OverlapSegmentSegment(Vector2 aStart, Vector2 aEnd, Vector2 b
499499
{
500500
var rangeA = ProjectSegment(aStart, aEnd, axisADir);
501501
var rangeB = ProjectSegment(bStart, bEnd, axisADir);
502-
return rangeA.OverlappingRange(rangeB); // Rect.OverlappingRange(rangeA, rangeB);
502+
return rangeA.OverlapValueRange(rangeB); // Rect.OverlappingRange(rangeA, rangeB);
503503
}
504504
return true;
505505
}
@@ -1177,28 +1177,30 @@ public bool OverlapShape(Quad q)
11771177
public bool OverlapShape(Rect r)
11781178
{
11791179
if (!r.OverlapRectLine(Start, Displacement)) return false;
1180-
RangeFloat rectRange = new
1180+
var rectRange = new ValueRange
11811181
(
11821182
r.X,
11831183
r.X + r.Width
11841184
);
1185-
RangeFloat segmentRange = new
1185+
var segmentRange = new ValueRange
11861186
(
11871187
Start.X,
11881188
End.X
11891189
);
11901190

1191-
if (!rectRange.OverlappingRange(segmentRange)) return false;
1191+
if (!rectRange.OverlapValueRange(segmentRange)) return false;
11921192

1193-
rectRange.Min = r.Y;
1194-
rectRange.Max = r.Y + r.Height;
1195-
rectRange.Sort();
1193+
rectRange = new(r.Y, r.Y + r.Height);
1194+
// rectRange.Min = r.Y;
1195+
// rectRange.Max = r.Y + r.Height;
1196+
// rectRange.Sort();
11961197

1197-
segmentRange.Min = Start.Y;
1198-
segmentRange.Max = End.Y;
1199-
segmentRange.Sort();
1198+
segmentRange = new(Start.Y, End.Y);
1199+
// segmentRange.Min = Start.Y;
1200+
// segmentRange.Max = End.Y;
1201+
// segmentRange.Sort();
12001202

1201-
return rectRange.OverlappingRange(segmentRange);
1203+
return rectRange.OverlapValueRange(segmentRange);
12021204
}
12031205
public bool OverlapShape(Polygon poly)
12041206
{

ShapeEngine/Core/ValueRange.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,11 @@ public ValueRange(float max)
6464
public float Clamp(float value) => ShapeMath.Clamp(value, Min, Max);
6565

6666
public bool OverlapValueRange(ValueRange other) => other.Min <= Max && Min <= other.Max;
67+
68+
public static bool OverlapValueRange(float aMin, float aMax, float bMin, float bMax)
69+
{
70+
var aRange = new ValueRange(aMin, aMax);
71+
var bRange = new ValueRange(bMin, bMax);
72+
return aRange.OverlapValueRange(bRange);
73+
}
6774
}

ShapeEngine/Screen/CameraFollowerSingle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class CameraFollowerSingle : ICameraFollower
1212
public ICameraFollowTarget? Target { get; private set; } = null;
1313
public ICameraFollowTarget? NewTarget { get; private set; } = null;
1414
// public bool Active { get; private set; } = false;
15-
public RangeFloat BoundaryDis;
15+
public ValueRange BoundaryDis;
1616
public float Speed;
1717

1818
private float changeTargetDuration = 0f;

ShapeEngine/Text/FontDimensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace ShapeEngine.Text;
66

77
public readonly struct FontDimensions
88
{
9-
public static RangeFloat FontSizeRange = new(10, 150);
9+
public static ValueRange FontSizeRange = new(10, 150);
1010

1111
public readonly Font Font;
1212
public float BaseSize => Font.BaseSize;

0 commit comments

Comments
 (0)