Skip to content

Commit c550e3b

Browse files
committed
cleanup
1 parent 9c7ff65 commit c550e3b

32 files changed

Lines changed: 245 additions & 240 deletions

Sources/ModelingEvolution.Drawing.Tests/Rotation3Tests.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ public void Rotation3_FromDegrees_CreatesDegreeRotation()
7676
[Fact]
7777
public void Rotation3_FromRadians_ConvertsToInternal()
7878
{
79-
var rotation = Rotation3<double>.FromRadians(Math.PI / 2, 0, 0);
79+
var rotation = Rotation3<double>.FromRadians(
80+
Radian<double>.FromRadian(Math.PI / 2),
81+
Radian<double>.FromRadian(0),
82+
Radian<double>.FromRadian(0));
8083

81-
rotation.Rx.Should().BeApproximately(90, Tolerance);
84+
((double)rotation.Rx).Should().BeApproximately(90, Tolerance);
8285
}
8386

8487
[Fact]
@@ -88,9 +91,9 @@ public void Rotation3_ToRadians_ConvertsCorrectly()
8891

8992
var (rx, ry, rz) = rotation.ToRadians();
9093

91-
rx.Should().BeApproximately(Math.PI / 2, Tolerance);
92-
ry.Should().BeApproximately(Math.PI, Tolerance);
93-
rz.Should().BeApproximately(3 * Math.PI / 2, Tolerance);
94+
((double)rx).Should().BeApproximately(Math.PI / 2, Tolerance);
95+
((double)ry).Should().BeApproximately(Math.PI, Tolerance);
96+
((double)rz).Should().BeApproximately(3 * Math.PI / 2, Tolerance);
9497
}
9598

9699
#endregion
@@ -118,9 +121,9 @@ public void Rotation3_QuaternionConversion_RoundTrips()
118121
var quaternion = original.ToQuaternion();
119122
var backToRotation = Rotation3<double>.FromQuaternion(quaternion);
120123

121-
backToRotation.Rx.Should().BeApproximately(original.Rx, 1e-6);
122-
backToRotation.Ry.Should().BeApproximately(original.Ry, 1e-6);
123-
backToRotation.Rz.Should().BeApproximately(original.Rz, 1e-6);
124+
((double)backToRotation.Rx).Should().BeApproximately((double)original.Rx, 1e-6);
125+
((double)backToRotation.Ry).Should().BeApproximately((double)original.Ry, 1e-6);
126+
((double)backToRotation.Rz).Should().BeApproximately((double)original.Rz, 1e-6);
124127
}
125128

126129
#endregion
@@ -230,7 +233,7 @@ public void Rotation3_Slerp_AtZero_ReturnsFirst()
230233

231234
var result = Rotation3<double>.Slerp(a, b, 0);
232235

233-
result.Rx.Should().BeApproximately(0, 1e-6);
236+
((double)result.Rx).Should().BeApproximately(0, 1e-6);
234237
}
235238

236239
[Fact]
@@ -241,7 +244,7 @@ public void Rotation3_Slerp_AtOne_ReturnsSecond()
241244

242245
var result = Rotation3<double>.Slerp(a, b, 1);
243246

244-
result.Rx.Should().BeApproximately(90, 1e-6);
247+
((double)result.Rx).Should().BeApproximately(90, 1e-6);
245248
}
246249

247250
[Fact]
@@ -252,7 +255,7 @@ public void Rotation3_Slerp_AtHalf_ReturnsMidpoint()
252255

253256
var result = Rotation3<double>.Slerp(a, b, 0.5);
254257

255-
result.Rx.Should().BeApproximately(45, 1e-6);
258+
((double)result.Rx).Should().BeApproximately(45, 1e-6);
256259
}
257260

258261
#endregion

Sources/ModelingEvolution.Drawing.Tests/SpeedTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ public class SpeedTests
1111
public void From_CreatesSpeed()
1212
{
1313
var s = Speed<float>.From(10f);
14-
s.Value.Should().BeApproximately(10f, Tol);
14+
((float)s).Should().BeApproximately(10f, Tol);
1515
}
1616

1717
[Fact]
1818
public void Zero_IsZero()
1919
{
20-
Speed<float>.Zero.Value.Should().Be(0f);
20+
((float)Speed<float>.Zero).Should().Be(0f);
2121
}
2222

2323
[Fact]
2424
public void ImplicitConversion_FromT()
2525
{
2626
Speed<float> s = 42f;
27-
s.Value.Should().BeApproximately(42f, Tol);
27+
((float)s).Should().BeApproximately(42f, Tol);
2828
}
2929

3030
[Fact]
@@ -39,37 +39,37 @@ public void Addition()
3939
{
4040
var a = Speed<float>.From(10f);
4141
var b = Speed<float>.From(5f);
42-
(a + b).Value.Should().BeApproximately(15f, Tol);
42+
((float)(a + b)).Should().BeApproximately(15f, Tol);
4343
}
4444

4545
[Fact]
4646
public void Subtraction()
4747
{
4848
var a = Speed<float>.From(10f);
4949
var b = Speed<float>.From(3f);
50-
(a - b).Value.Should().BeApproximately(7f, Tol);
50+
((float)(a - b)).Should().BeApproximately(7f, Tol);
5151
}
5252

5353
[Fact]
5454
public void Negation()
5555
{
5656
var s = Speed<float>.From(10f);
57-
(-s).Value.Should().BeApproximately(-10f, Tol);
57+
((float)(-s)).Should().BeApproximately(-10f, Tol);
5858
}
5959

6060
[Fact]
6161
public void MultiplyByScalar()
6262
{
6363
var s = Speed<float>.From(5f);
64-
(s * 3f).Value.Should().BeApproximately(15f, Tol);
65-
(3f * s).Value.Should().BeApproximately(15f, Tol);
64+
((float)(s * 3f)).Should().BeApproximately(15f, Tol);
65+
((float)(3f * s)).Should().BeApproximately(15f, Tol);
6666
}
6767

6868
[Fact]
6969
public void DivideByScalar()
7070
{
7171
var s = Speed<float>.From(15f);
72-
(s / 3f).Value.Should().BeApproximately(5f, Tol);
72+
((float)(s / 3f)).Should().BeApproximately(5f, Tol);
7373
}
7474

7575
[Fact]
@@ -90,7 +90,7 @@ public void DistanceIn_SpeedTimesTime()
9090
public void Abs_ReturnsPositive()
9191
{
9292
var s = Speed<float>.From(-10f);
93-
s.Abs().Value.Should().BeApproximately(10f, Tol);
93+
((float)s.Abs()).Should().BeApproximately(10f, Tol);
9494
}
9595

9696
[Fact]
@@ -117,7 +117,7 @@ public void Parse_RoundTrip()
117117
{
118118
var s = Speed<float>.From(42.5f);
119119
Speed<float>.TryParse("42.5", null, out var parsed).Should().BeTrue();
120-
parsed.Value.Should().BeApproximately(42.5f, Tol);
120+
((float)parsed).Should().BeApproximately(42.5f, Tol);
121121
}
122122

123123
[Fact]

Sources/ModelingEvolution.Drawing.Tests/Triangle3Tests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ public void Triangle3_ToPose_HorizontalTriangle_ZAxisPointsUp()
162162
// Check that Z-axis of pose points along (0,0,1)
163163
var rotation = pose.Rotation;
164164
// For a horizontal surface, Rx and Ry should be near 0
165-
rotation.Rx.Should().BeApproximately(0, 1);
166-
rotation.Ry.Should().BeApproximately(0, 1);
165+
((double)rotation.Rx).Should().BeApproximately(0, 1);
166+
((double)rotation.Ry).Should().BeApproximately(0, 1);
167167
}
168168

169169
#endregion

Sources/ModelingEvolution.Drawing.Tests/Velocity3Tests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void Ctor_Components()
2020
public void Speed_IsMagnitude()
2121
{
2222
var v = new Velocity3<float>(3, 4, 0);
23-
v.Speed.Value.Should().BeApproximately(5f, Tol);
23+
((float)v.Speed).Should().BeApproximately(5f, Tol);
2424
}
2525

2626
[Fact]
@@ -80,6 +80,6 @@ public void ImplicitConversion_FromVector3()
8080
public void Zero_IsZero()
8181
{
8282
var v = Velocity3<float>.Zero;
83-
v.Speed.Value.Should().BeApproximately(0f, Tol);
83+
((float)v.Speed).Should().BeApproximately(0f, Tol);
8484
}
8585
}

Sources/ModelingEvolution.Drawing/Degree.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,6 @@ public static implicit operator Degree<T>(Radian<T> src)
191191
return new Degree<T>(tmp);
192192
}
193193

194-
/// <summary>
195-
/// Gets the underlying numeric value of this degree measurement.
196-
/// </summary>
197-
/// <returns>The numeric value in degrees.</returns>
198-
public T GetValue()
199-
{
200-
return _val;
201-
}
202-
203194

204195
/// <summary>
205196
/// Compares this degree value to another degree value.

Sources/ModelingEvolution.Drawing/Point3Converter.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ public override Rotation3<T> Read(ref Utf8JsonReader reader, Type typeToConvert,
144144
public override void Write(Utf8JsonWriter writer, Rotation3<T> value, JsonSerializerOptions options)
145145
{
146146
writer.WriteStartArray();
147-
WriteValue(writer, value.Rx);
148-
WriteValue(writer, value.Ry);
149-
WriteValue(writer, value.Rz);
147+
WriteValue(writer, (T)value.Rx);
148+
WriteValue(writer, (T)value.Ry);
149+
WriteValue(writer, (T)value.Rz);
150150
writer.WriteEndArray();
151151
}
152152
}
@@ -208,9 +208,9 @@ public override void Write(Utf8JsonWriter writer, Pose3<T> value, JsonSerializer
208208
WriteValue(writer, value.X);
209209
WriteValue(writer, value.Y);
210210
WriteValue(writer, value.Z);
211-
WriteValue(writer, value.Rx);
212-
WriteValue(writer, value.Ry);
213-
WriteValue(writer, value.Rz);
211+
WriteValue(writer, (T)value.Rx);
212+
WriteValue(writer, (T)value.Ry);
213+
WriteValue(writer, (T)value.Rz);
214214
writer.WriteEndArray();
215215
}
216216
}

Sources/ModelingEvolution.Drawing/Pose3.cs

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public T Z
9797
/// <summary>
9898
/// Gets or sets the rotation around X axis in degrees.
9999
/// </summary>
100-
public T Rx
100+
public Degree<T> Rx
101101
{
102102
readonly get => _rotation.Rx;
103103
set => _rotation.Rx = value;
@@ -106,7 +106,7 @@ public T Rx
106106
/// <summary>
107107
/// Gets or sets the rotation around Y axis in degrees.
108108
/// </summary>
109-
public T Ry
109+
public Degree<T> Ry
110110
{
111111
readonly get => _rotation.Ry;
112112
set => _rotation.Ry = value;
@@ -115,7 +115,7 @@ public T Ry
115115
/// <summary>
116116
/// Gets or sets the rotation around Z axis in degrees.
117117
/// </summary>
118-
public T Rz
118+
public Degree<T> Rz
119119
{
120120
readonly get => _rotation.Rz;
121121
set => _rotation.Rz = value;
@@ -217,12 +217,12 @@ public Pose3<U> Truncating<U>()
217217

218218
/// <summary>
219219
/// Creates a pose from three points defining a surface plane using the right-hand rule.
220-
/// Z direction is determined by (b-a) × (c-a). Reversing point order reverses Z direction.
220+
/// Z direction is determined by (b-a) x (c-a). Reversing point order reverses Z direction.
221221
/// </summary>
222222
/// <param name="a">First point - becomes the origin, also defines X-axis direction with b.</param>
223223
/// <param name="b">Second point - defines X-axis direction from a.</param>
224-
/// <param name="c">Third point - completes the plane; a→b→c order determines Z via right-hand rule.</param>
225-
/// <returns>A pose where origin is at a, X-axis along ab, Z-axis per right-hand rule.</returns>
224+
/// <param name="c">Third point - completes the plane; a-b-c order determines Z via right-hand rule.</param>
225+
/// <returns>A pose where origin is at a, X-axis along a-b, Z-axis per right-hand rule.</returns>
226226
/// <exception cref="ArgumentException">Thrown when points a, b, c are collinear.</exception>
227227
public static Pose3<T> FromSurface(Point3<T> a, Point3<T> b, Point3<T> c)
228228
{
@@ -232,7 +232,7 @@ public static Pose3<T> FromSurface(Point3<T> a, Point3<T> b, Point3<T> c)
232232
var ab = b - a;
233233
var ac = c - a;
234234

235-
// Plane normal via right-hand rule: Z = (b-a) × (c-a)
235+
// Plane normal via right-hand rule: Z = (b-a) x (c-a)
236236
var zAxis = Vector3<T>.Cross(ab, ac);
237237
var normalLength = zAxis.Length;
238238

@@ -241,10 +241,10 @@ public static Pose3<T> FromSurface(Point3<T> a, Point3<T> b, Point3<T> c)
241241

242242
zAxis = zAxis / normalLength; // Normalize
243243

244-
// X-axis along edge ab, normalized
244+
// X-axis along edge a-b, normalized
245245
var xAxis = ab.Normalize();
246246

247-
// Y-axis completes right-hand system: Y = Z × X
247+
// Y-axis completes right-hand system: Y = Z x X
248248
var yAxis = Vector3<T>.Cross(zAxis, xAxis);
249249

250250
// Convert orthonormal basis to Euler angles (ZYX convention)
@@ -296,10 +296,10 @@ public static Pose3<T> FromSurface(Point3<T> a, Point3<T> b, Point3<T> c, Point3
296296
// Z-axis points toward h
297297
var zAxis = d > T.Zero ? normal : -normal;
298298

299-
// X-axis along edge ab, normalized
299+
// X-axis along edge a-b, normalized
300300
var xAxis = ab.Normalize();
301301

302-
// Y-axis completes right-hand system: Y = Z × X
302+
// Y-axis completes right-hand system: Y = Z x X
303303
var yAxis = Vector3<T>.Cross(zAxis, xAxis);
304304

305305
// Convert orthonormal basis to Euler angles (ZYX convention)
@@ -314,17 +314,7 @@ public static Pose3<T> FromSurface(Point3<T> a, Point3<T> b, Point3<T> c, Point3
314314
/// </summary>
315315
private static Rotation3<T> RotationFromAxes(Vector3<T> xAxis, Vector3<T> yAxis, Vector3<T> zAxis)
316316
{
317-
// We want Rotation3 R such that R.Rotate(e_i) = axis_i
318-
// This requires extracting Euler angles from the TRANSPOSE of matrix [X|Y|Z]
319-
// R^T[i,j] = R[j,i], so:
320-
// R^T[0,2] = xAxis.Z
321-
// R^T[1,2] = yAxis.Z
322-
// R^T[2,2] = zAxis.Z
323-
// R^T[0,1] = xAxis.Y
324-
// R^T[0,0] = xAxis.X
325-
326317
var one = T.One;
327-
var rad2Deg = T.CreateTruncating(180) / T.Pi;
328318
var epsilon = T.CreateTruncating(1e-6);
329319

330320
// Clamp to [-1, 1] to avoid NaN from asin
@@ -345,12 +335,16 @@ private static Rotation3<T> RotationFromAxes(Vector3<T> xAxis, Vector3<T> yAxis,
345335
}
346336
else
347337
{
348-
// Gimbal lock - pitch is ±90°
338+
// Gimbal lock - pitch is +/-90 deg
349339
rx = T.Atan2(-zAxis.Y, yAxis.Y);
350340
rz = T.Zero;
351341
}
352342

353-
return new Rotation3<T>(rx * rad2Deg, ry * rad2Deg, rz * rad2Deg);
343+
// rx, ry, rz are in radians — convert via Radian<T> → Degree<T>
344+
return new Rotation3<T>(
345+
(Degree<T>)Radian<T>.FromRadian(rx),
346+
(Degree<T>)Radian<T>.FromRadian(ry),
347+
(Degree<T>)Radian<T>.FromRadian(rz));
354348
}
355349

356350
#endregion
@@ -361,7 +355,7 @@ public static implicit operator Pose3<T>((T x, T y, T z, T rx, T ry, T rz) tuple
361355
new(tuple.x, tuple.y, tuple.z, tuple.rx, tuple.ry, tuple.rz);
362356

363357
public static implicit operator (T x, T y, T z, T rx, T ry, T rz)(Pose3<T> pose) =>
364-
(pose.X, pose.Y, pose.Z, pose.Rx, pose.Ry, pose.Rz);
358+
(pose.X, pose.Y, pose.Z, (T)pose.Rx, (T)pose.Ry, (T)pose.Rz);
365359

366360
/// <summary>
367361
/// Deconstructs into position and rotation.
@@ -380,9 +374,9 @@ public readonly void Deconstruct(out T x, out T y, out T z, out T rx, out T ry,
380374
x = X;
381375
y = Y;
382376
z = Z;
383-
rx = Rx;
384-
ry = Ry;
385-
rz = Rz;
377+
rx = (T)Rx;
378+
ry = (T)Ry;
379+
rz = (T)Rz;
386380
}
387381

388382
#endregion
@@ -394,7 +388,7 @@ public readonly void Deconstruct(out T x, out T y, out T z, out T rx, out T ry,
394388
public override readonly int GetHashCode() => HashCode.Combine(_position, _rotation);
395389

396390
public override readonly string ToString() =>
397-
$"{{X={X}, Y={Y}, Z={Z}, Rx={Rx}, Ry={Ry}, Rz={Rz}}}";
391+
$"{{X={X}, Y={Y}, Z={Z}, Rx={(T)Rx}, Ry={(T)Ry}, Rz={(T)Rz}}}";
398392

399393
#endregion
400394

Sources/ModelingEvolution.Drawing/PosePath3JsonConverter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public override void Write(Utf8JsonWriter writer, PosePath3<T> value, JsonSerial
5555
_writeNumber(writer, pose.X);
5656
_writeNumber(writer, pose.Y);
5757
_writeNumber(writer, pose.Z);
58-
_writeNumber(writer, pose.Rx);
59-
_writeNumber(writer, pose.Ry);
60-
_writeNumber(writer, pose.Rz);
58+
_writeNumber(writer, (T)pose.Rx);
59+
_writeNumber(writer, (T)pose.Ry);
60+
_writeNumber(writer, (T)pose.Rz);
6161
}
6262
writer.WriteEndArray();
6363
}

0 commit comments

Comments
 (0)