mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-07-31 15:58:27 -04:00
* Move all unit tests to Engine/Tests * Fix Margin.EdgeSubtract * Fix Capsule.Contains * EnvironmentVariables.Remove if it's null * Fixed ray trace never returning startedsolid * Fix HistoryList.Navigate on empty list * Fix GameObject.WorldPosition accepting NaNs * Fix flex: initial expanding to the wrong grow/shrink * Translation.TryConvert shouldn't throw on invalid enum strings * Skip sound file tests on machines with no audio device
52 lines
1.0 KiB
C#
52 lines
1.0 KiB
C#
namespace MathTests;
|
|
|
|
[TestClass]
|
|
public class MatrixTest
|
|
{
|
|
/// <summary>
|
|
/// Matrix.FromTransform should build a matrix that maps local points to the
|
|
/// same world positions the Transform itself produces.
|
|
/// </summary>
|
|
[TestMethod]
|
|
public void FromTransform()
|
|
{
|
|
var transform = new Transform(
|
|
new Vector3( 100, 420, 340 ),
|
|
Rotation.From( 90, 0, 45 ),
|
|
2.0f
|
|
);
|
|
|
|
var mat = Matrix.FromTransform( transform );
|
|
|
|
var points = new[]
|
|
{
|
|
Vector3.Zero,
|
|
new Vector3( 1, 0, 0 ),
|
|
new Vector3( -5, 3, 12 )
|
|
};
|
|
|
|
foreach ( var point in points )
|
|
{
|
|
var expected = transform.PointToWorld( point );
|
|
var actual = mat.Transform( point );
|
|
|
|
Assert.IsTrue( expected.AlmostEqual( actual, 0.01f ), $"{point}: expected {expected}, got {actual}" );
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ToTransform()
|
|
{
|
|
var transform = new Transform(
|
|
new Vector3( 100, 420, 340 ),
|
|
Rotation.From( 90, 0, 45 ),
|
|
2.0f
|
|
);
|
|
|
|
var mat = Matrix.FromTransform( transform );
|
|
var tx = mat.ExtractTransform();
|
|
|
|
Assert.IsTrue( transform.AlmostEqual( tx ) );
|
|
}
|
|
}
|