using Chernobyl.Mathematics.Movement;
using Chernobyl.Mathematics.Vectors;
using NUnit.Framework;
namespace Chernobyl.Mathematics.Geometry
{
///
/// Tests for types.
///
public abstract class LineSegmentTests
{
// Tests:
// Transform
// Two sets of tests: when parented and when not parented.
// Position is the center point.
// Z axis is in the proper direction.
// Z axis scale is the length between point 1 and point 2.
//-----------------------------------------------------------------
// Transform Not Parented Tests
//-----------------------------------------------------------------
[Test, Description("A test to ensure LineSegment is properly positioned " +
"at the center of two end points.")]
public void PositionTest()
{
Vector3 expected = new Vector3(2.5f, 0, 0);
MatrixTransform point1 = new MatrixTransform();
MatrixTransform point2 = new MatrixTransform();
point2.Translate(expected.X * 2, 0, 0);
ILineSegment line = CreateLineSegment(point1, point2);
Assert.AreEqual(expected, line.Position, "The Position is not what was expected.");
}
[Test, Description("A test to ensure LineSegment's X axis is properly " +
"scaled so that its length is the distance between its two end points.")]
public void ScaleTest()
{
Vector3 expected = new Vector3(5, 0, 0);
MatrixTransform point1 = new MatrixTransform();
MatrixTransform point2 = new MatrixTransform();
point2.Translate(expected);
ILineSegment line = CreateLineSegment(point1, point2);
Assert.AreEqual(expected.X, line.XScale, "The Scale is not what was expected.");
}
[Test, Description("A test to ensure LineSegment is properly " +
"rotated so that its X axis is parallel to the line between its two " +
"end points.")]
public void RotationTest()
{
Vector3 expectedX = new Vector3(5, 0, 0);
MatrixTransform point1 = new MatrixTransform();
MatrixTransform point2 = new MatrixTransform();
point2.Translate(expectedX);
ILineSegment line = CreateLineSegment(point1, point2);
Assert.AreEqual(expectedX, line.WorldMatrix.Column0.Xyz,
"The X axis is not what was expectedX.");
Assert.AreEqual(Vector3.UnitY, line.WorldMatrix.Column1.Xyz,
"The Y axis is not what was expectedX.");
Assert.AreEqual(-Vector3.UnitZ, line.WorldMatrix.Column2.Xyz,
"The Z axis is not what was expectedX.");
}
///
/// Creates a new instance that will be
/// tested.
///
/// The first end point in the line.
/// The second end point in the line.
/// The whose end points are
/// defined by and .
protected abstract ILineSegment CreateLineSegment(ITransform point1, ITransform point2);
}
}