Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 4774022

Browse files
committed
Fix Matrix/Plane/Quaternion field offset tests, Issue 1002
1 parent 1e1b6f7 commit 4774022

File tree

4 files changed

+51
-36
lines changed

4 files changed

+51
-36
lines changed

src/System.Numerics.Vectors/tests/Matrix3x2Tests.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,19 +1009,22 @@ struct Matrix3x2PlusFloat_2x
10091009

10101010
// A test to make sure the fields are laid out how we expect
10111011
[Fact]
1012-
[ActiveIssue(1002)]
10131012
public unsafe void Matrix3x2FieldOffsetTest()
10141013
{
1015-
Matrix3x2* ptr = (Matrix3x2*)0;
1014+
Matrix3x2 mat = new Matrix3x2();
1015+
float* basePtr = &mat.M11; // Take address of first element
1016+
Matrix3x2* matPtr = &mat; // Take address of whole matrix
10161017

1017-
Assert.Equal(new IntPtr(0), new IntPtr(&ptr->M11));
1018-
Assert.Equal(new IntPtr(4), new IntPtr(&ptr->M12));
1018+
Assert.Equal(new IntPtr(basePtr), new IntPtr(matPtr));
10191019

1020-
Assert.Equal(new IntPtr(8), new IntPtr(&ptr->M21));
1021-
Assert.Equal(new IntPtr(12), new IntPtr(&ptr->M22));
1020+
Assert.Equal(new IntPtr(basePtr + 0), new IntPtr(&mat.M11));
1021+
Assert.Equal(new IntPtr(basePtr + 1), new IntPtr(&mat.M12));
10221022

1023-
Assert.Equal(new IntPtr(16), new IntPtr(&ptr->M31));
1024-
Assert.Equal(new IntPtr(20), new IntPtr(&ptr->M32));
1023+
Assert.Equal(new IntPtr(basePtr + 2), new IntPtr(&mat.M21));
1024+
Assert.Equal(new IntPtr(basePtr + 3), new IntPtr(&mat.M22));
1025+
1026+
Assert.Equal(new IntPtr(basePtr + 4), new IntPtr(&mat.M31));
1027+
Assert.Equal(new IntPtr(basePtr + 5), new IntPtr(&mat.M32));
10251028
}
10261029
}
10271030
}

src/System.Numerics.Vectors/tests/Matrix4x4Tests.cs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,30 +2485,34 @@ struct Matrix4x4PlusFloat_2x
24852485

24862486
// A test to make sure the fields are laid out how we expect
24872487
[Fact]
2488-
[ActiveIssue(1002)]
24892488
public unsafe void Matrix4x4FieldOffsetTest()
24902489
{
2491-
Matrix4x4* ptr = (Matrix4x4*)0;
2490+
Matrix4x4 mat = new Matrix4x4();
24922491

2493-
Assert.Equal(new IntPtr(0), new IntPtr(&ptr->M11));
2494-
Assert.Equal(new IntPtr(4), new IntPtr(&ptr->M12));
2495-
Assert.Equal(new IntPtr(8), new IntPtr(&ptr->M13));
2496-
Assert.Equal(new IntPtr(12), new IntPtr(&ptr->M14));
2492+
float* basePtr = &mat.M11; // Take address of first element
2493+
Matrix4x4* matPtr = &mat; // Take address of whole matrix
24972494

2498-
Assert.Equal(new IntPtr(16), new IntPtr(&ptr->M21));
2499-
Assert.Equal(new IntPtr(20), new IntPtr(&ptr->M22));
2500-
Assert.Equal(new IntPtr(24), new IntPtr(&ptr->M23));
2501-
Assert.Equal(new IntPtr(28), new IntPtr(&ptr->M24));
2495+
Assert.Equal(new IntPtr(basePtr), new IntPtr(matPtr));
25022496

2503-
Assert.Equal(new IntPtr(32), new IntPtr(&ptr->M31));
2504-
Assert.Equal(new IntPtr(36), new IntPtr(&ptr->M32));
2505-
Assert.Equal(new IntPtr(40), new IntPtr(&ptr->M33));
2506-
Assert.Equal(new IntPtr(44), new IntPtr(&ptr->M34));
2497+
Assert.Equal(new IntPtr(basePtr + 0), new IntPtr(&mat.M11));
2498+
Assert.Equal(new IntPtr(basePtr + 1), new IntPtr(&mat.M12));
2499+
Assert.Equal(new IntPtr(basePtr + 2), new IntPtr(&mat.M13));
2500+
Assert.Equal(new IntPtr(basePtr + 3), new IntPtr(&mat.M14));
25072501

2508-
Assert.Equal(new IntPtr(48), new IntPtr(&ptr->M41));
2509-
Assert.Equal(new IntPtr(52), new IntPtr(&ptr->M42));
2510-
Assert.Equal(new IntPtr(56), new IntPtr(&ptr->M43));
2511-
Assert.Equal(new IntPtr(60), new IntPtr(&ptr->M44));
2502+
Assert.Equal(new IntPtr(basePtr + 4), new IntPtr(&mat.M21));
2503+
Assert.Equal(new IntPtr(basePtr + 5), new IntPtr(&mat.M22));
2504+
Assert.Equal(new IntPtr(basePtr + 6), new IntPtr(&mat.M23));
2505+
Assert.Equal(new IntPtr(basePtr + 7), new IntPtr(&mat.M24));
2506+
2507+
Assert.Equal(new IntPtr(basePtr + 8), new IntPtr(&mat.M31));
2508+
Assert.Equal(new IntPtr(basePtr + 9), new IntPtr(&mat.M32));
2509+
Assert.Equal(new IntPtr(basePtr + 10), new IntPtr(&mat.M33));
2510+
Assert.Equal(new IntPtr(basePtr + 11), new IntPtr(&mat.M34));
2511+
2512+
Assert.Equal(new IntPtr(basePtr + 12), new IntPtr(&mat.M41));
2513+
Assert.Equal(new IntPtr(basePtr + 13), new IntPtr(&mat.M42));
2514+
Assert.Equal(new IntPtr(basePtr + 14), new IntPtr(&mat.M43));
2515+
Assert.Equal(new IntPtr(basePtr + 15), new IntPtr(&mat.M44));
25122516
}
25132517
}
25142518
}

src/System.Numerics.Vectors/tests/PlaneTests.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,17 @@ struct PlanePlusFloat_2x
363363

364364
// A test to make sure the fields are laid out how we expect
365365
[Fact]
366-
[ActiveIssue(1002)]
367366
public unsafe void PlaneFieldOffsetTest()
368367
{
369-
Plane* ptr = (Plane*)0;
368+
Plane plane = new Plane();
370369

371-
Assert.Equal(new IntPtr(0), new IntPtr(&ptr->Normal));
372-
Assert.Equal(new IntPtr(12), new IntPtr(&ptr->D));
370+
float* basePtr = &plane.Normal.X; // Take address of first element
371+
Plane* planePtr = &plane; // Take address of whole Plane
372+
373+
Assert.Equal(new IntPtr(basePtr), new IntPtr(planePtr));
374+
375+
Assert.Equal(new IntPtr(basePtr + 0), new IntPtr(&plane.Normal));
376+
Assert.Equal(new IntPtr(basePtr + 3), new IntPtr(&plane.D));
373377
}
374378
}
375379
}

src/System.Numerics.Vectors/tests/QuaternionTests.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -967,15 +967,19 @@ struct QuaternionPlusFloat_2x
967967

968968
// A test to make sure the fields are laid out how we expect
969969
[Fact]
970-
[ActiveIssue(1002)]
971970
public unsafe void QuaternionFieldOffsetTest()
972971
{
973-
Quaternion* ptr = (Quaternion*)0;
972+
Quaternion quat = new Quaternion();
974973

975-
Assert.Equal(new IntPtr(0), new IntPtr(&ptr->X));
976-
Assert.Equal(new IntPtr(4), new IntPtr(&ptr->Y));
977-
Assert.Equal(new IntPtr(8), new IntPtr(&ptr->Z));
978-
Assert.Equal(new IntPtr(12), new IntPtr(&ptr->W));
974+
float* basePtr = &quat.X; // Take address of first element
975+
Quaternion* quatPtr = &quat; // Take address of whole Quaternion
976+
977+
Assert.Equal(new IntPtr(basePtr), new IntPtr(quatPtr));
978+
979+
Assert.Equal(new IntPtr(basePtr + 0), new IntPtr(&quat.X));
980+
Assert.Equal(new IntPtr(basePtr + 1), new IntPtr(&quat.Y));
981+
Assert.Equal(new IntPtr(basePtr + 2), new IntPtr(&quat.Z));
982+
Assert.Equal(new IntPtr(basePtr + 3), new IntPtr(&quat.W));
979983
}
980984
}
981985
}

0 commit comments

Comments
 (0)