Skip to content

Commit 8fef834

Browse files
rafalmaciagclaude
andcommitted
Add Joints6.IsBetween(min, max) for joint limit checking
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2dbeaf7 commit 8fef834

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

Sources/ModelingEvolution.Drawing.Tests/Joints6Tests.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,46 @@ public void IsWithin_OutsideTolerance_ReturnsFalse()
255255
a.IsWithin(b, Degree<double>.Create(1.0)).Should().BeFalse();
256256
}
257257

258+
[Fact]
259+
public void IsBetween_AllWithinRange_ReturnsTrue()
260+
{
261+
var value = MakeJoints(10, 20, 30, 40, 50, 60);
262+
var min = MakeJoints(0, 10, 20, 30, 40, 50);
263+
var max = MakeJoints(20, 30, 40, 50, 60, 70);
264+
265+
value.IsBetween(min, max).Should().BeTrue();
266+
}
267+
268+
[Fact]
269+
public void IsBetween_OnBoundary_ReturnsTrue()
270+
{
271+
var value = MakeJoints(0, 10, 20, 30, 40, 50);
272+
var min = MakeJoints(0, 10, 20, 30, 40, 50);
273+
var max = MakeJoints(20, 30, 40, 50, 60, 70);
274+
275+
value.IsBetween(min, max).Should().BeTrue();
276+
}
277+
278+
[Fact]
279+
public void IsBetween_OneJointBelow_ReturnsFalse()
280+
{
281+
var value = MakeJoints(-1, 20, 30, 40, 50, 60);
282+
var min = MakeJoints(0, 10, 20, 30, 40, 50);
283+
var max = MakeJoints(20, 30, 40, 50, 60, 70);
284+
285+
value.IsBetween(min, max).Should().BeFalse();
286+
}
287+
288+
[Fact]
289+
public void IsBetween_OneJointAbove_ReturnsFalse()
290+
{
291+
var value = MakeJoints(10, 20, 30, 40, 50, 71);
292+
var min = MakeJoints(0, 10, 20, 30, 40, 50);
293+
var max = MakeJoints(20, 30, 40, 50, 60, 70);
294+
295+
value.IsBetween(min, max).Should().BeFalse();
296+
}
297+
258298
#endregion
259299

260300
#region ToArray / FromArray / CopyTo / FromSpan

Sources/ModelingEvolution.Drawing/Joints6.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,20 @@ public readonly Degree<T> MaxAbsDelta(Joints6<T> other)
186186
[MethodImpl(MethodImplOptions.AggressiveInlining)]
187187
public readonly bool IsWithin(Joints6<T> other, Degree<T> tolerance) => MaxAbsDelta(other) <= tolerance;
188188

189+
/// <summary>
190+
/// Returns true if every joint angle is between the corresponding min and max values (inclusive).
191+
/// </summary>
192+
/// <param name="min">The minimum allowed angles per joint.</param>
193+
/// <param name="max">The maximum allowed angles per joint.</param>
194+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
195+
public readonly bool IsBetween(Joints6<T> min, Joints6<T> max) =>
196+
_j1 >= min._j1 && _j1 <= max._j1 &&
197+
_j2 >= min._j2 && _j2 <= max._j2 &&
198+
_j3 >= min._j3 && _j3 <= max._j3 &&
199+
_j4 >= min._j4 && _j4 <= max._j4 &&
200+
_j5 >= min._j5 && _j5 <= max._j5 &&
201+
_j6 >= min._j6 && _j6 <= max._j6;
202+
189203
/// <summary>
190204
/// Copies the joint angles into a new array of Degree{T}.
191205
/// </summary>

0 commit comments

Comments
 (0)