Skip to content

Commit

Permalink
Fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Donkie committed Jun 6, 2022
1 parent 00d4d6f commit d08acae
Showing 4 changed files with 25 additions and 15 deletions.
11 changes: 7 additions & 4 deletions I3DShapesTool.Lib/Model/I3D/TransformGroup.cs
Original file line number Diff line number Diff line change
@@ -35,11 +35,14 @@ private void UpdateAbsoluteTransform()

public void SetParent(TransformGroup parent)
{
if(Parent != null)
Parent.Children.Remove(this);
if(parent != Parent)
{
if(Parent != null)
Parent.Children.Remove(this);

Parent = parent;
Parent.Children.Add(this);
Parent = parent;
Parent.Children.Add(this);
}

UpdateAbsoluteTransform();

7 changes: 7 additions & 0 deletions I3DShapesTool.Lib/Tools/Transform.cs
Original file line number Diff line number Diff line change
@@ -37,6 +37,13 @@ public Transform Translate(I3DVector vec)
return t * this;
}

/// <summary>
/// Perform a 3D Euler angle rotation (in degrees)
/// X component of the vector rotates around the X axis, and so on
/// XYZ rotation convention
/// </summary>
/// <param name="rot"></param>
/// <returns></returns>
public Transform Rotate(I3DVector rot)
{
double cosX = Math.Cos(rot.X * DEG2RAD);
16 changes: 8 additions & 8 deletions I3DShapesToolTest/TestTransform.cs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ public void TestTranslate()
public void TestRotateX()
{
Transform t = Transform.Identity
.Rotate(new I3DVector(Math.PI / 2, 0, 0));
.Rotate(new I3DVector(90, 0, 0));

I3DVector v = t * new I3DVector(0, 1, 0);
Assert.Equal(0, v.X, 6);
@@ -35,7 +35,7 @@ public void TestRotateX()
public void TestRotateY()
{
Transform t = Transform.Identity
.Rotate(new I3DVector(0, Math.PI / 2, 0));
.Rotate(new I3DVector(0, 90, 0));

I3DVector v = t * new I3DVector(1, 0, 0);
Assert.Equal(0, v.X, 6);
@@ -47,7 +47,7 @@ public void TestRotateY()
public void TestRotateZ()
{
Transform t = Transform.Identity
.Rotate(new I3DVector(0, 0, Math.PI / 2));
.Rotate(new I3DVector(0, 0, 90));

I3DVector v = t * new I3DVector(1, 0, 0);
Assert.Equal(0, v.X, 6);
@@ -56,15 +56,15 @@ public void TestRotateZ()
}

[Fact]
public void TestRotateXY()
public void TestRotateXYZ()
{
Transform t = Transform.Identity
.Rotate(new I3DVector(Math.PI / 2, Math.PI / 2, 0));
.Rotate(new I3DVector(90, 90, 90));

I3DVector v = t * new I3DVector(1, 0, 0);
I3DVector v = t * new I3DVector(1, 1, 0);
Assert.Equal(0, v.X, 6);
Assert.Equal(1, v.Y, 6);
Assert.Equal(0, v.Z, 6);
Assert.Equal(-1, v.Z, 6);
}

[Fact]
@@ -98,7 +98,7 @@ public void TestScaleTranslateRotate()
Transform t = Transform.Identity
.Scale(new I3DVector(0.5, 0.5, 0.5))
.Translate(new I3DVector(6, 0, 0))
.Rotate(new I3DVector(0, Math.PI / 2, 0));
.Rotate(new I3DVector(0, 90, 0));

I3DVector v = t * new I3DVector(2, 0, 0);
Assert.Equal(0, v.X, 6);
6 changes: 3 additions & 3 deletions I3DShapesToolTest/TestTransformGroup.cs
Original file line number Diff line number Diff line change
@@ -29,15 +29,15 @@ public void TestTransforms()
{
TransformGroup tg1 = new TransformGroup(null, null, I3DVector.Zero, I3DVector.Zero, new I3DVector(0.5, 0.5, 0.5));
TransformGroup tg2 = new TransformGroup(null, null, new I3DVector(6, 0, 0), I3DVector.Zero, I3DVector.One);
TransformGroup tg3 = new TransformGroup(null, null, I3DVector.Zero, new I3DVector(0, Math.PI / 2, 0), I3DVector.One);
TransformGroup tg3 = new TransformGroup(null, null, I3DVector.Zero, new I3DVector(0, 90, 0), I3DVector.One);

tg3.SetParent(tg2);
tg2.SetParent(tg1);

I3DVector v = tg3.AbsoluteTransform * new I3DVector(2, 0, 0);
Assert.Equal(0, v.X, 6);
Assert.Equal(3, v.X, 6);
Assert.Equal(0, v.Y, 6);
Assert.Equal(-7, v.Z, 6);
Assert.Equal(-1, v.Z, 6);
}
}
}

0 comments on commit d08acae

Please sign in to comment.