Skip to content

Commit c30f894

Browse files
authored
Add tests for new C# bindings (#5539)
* WIP: Add tests for new C# bindings * WIP: Update tests * WIP: Update tests * WIP: Update tests * WIP: Update tests * WIP: Update tests * WIP: Update tests * WIP: Update tests * Fix output path * Revert "Fix output path" This reverts commit a763b5c. * WIP: Update tests * WIP: Update tests * WIP: Update tests * WIP: Update tests
1 parent 10d0464 commit c30f894

25 files changed

+1984
-15
lines changed

source/MRDotNet2Test/MRDotNet2Test.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@
2626
<Nullable>enable</Nullable>
2727
</PropertyGroup>
2828

29+
<ItemGroup>
30+
<PackageReference Include="NUnitLite" Version="4.4.0" />
31+
</ItemGroup>
32+
2933
</Project>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using NUnit.Framework;
2+
using static MR;
3+
4+
namespace MRTest
5+
{
6+
[TestFixture]
7+
internal class AffineXfTests
8+
{
9+
[Test]
10+
public void TestDefaultConstructor()
11+
{
12+
var a = new AffineXf3f();
13+
Assert.That( a.A == new Matrix3f() );
14+
Assert.That( a.B == new Vector3f() );
15+
}
16+
17+
[Test]
18+
public void TestConstructor()
19+
{
20+
var A = new Matrix3f( new Vector3f( 1, 2, 3 ), new Vector3f( 4, 5, 6 ), new Vector3f( 7, 8, 9 ) );
21+
var b = new Vector3f( 10, 11, 12 );
22+
23+
var a = new AffineXf3f( A, b );
24+
Assert.That( a.A == A );
25+
Assert.That( a.B == b );
26+
}
27+
28+
[Test]
29+
public void TestLinearConstructor()
30+
{
31+
var A = new Matrix3f( new Vector3f( 1, 2, 3 ), new Vector3f( 4, 5, 6 ), new Vector3f( 7, 8, 9 ) );
32+
var a = AffineXf3f.Linear( A );
33+
Assert.That( a.A == A );
34+
Assert.That( a.B == new Vector3f() );
35+
}
36+
37+
[Test]
38+
public void TestTranslationConstructor()
39+
{
40+
var b = new Vector3f( 10, 11, 12 );
41+
var a = AffineXf3f.Translation( b );
42+
Assert.That( a.A == new Matrix3f() );
43+
Assert.That( a.B == b );
44+
}
45+
46+
[Test]
47+
public void TestMultiplication()
48+
{
49+
var A = new Matrix3f( new Vector3f( 1, 2, 3 ), new Vector3f( 4, 5, 6 ), new Vector3f( 7, 8, 9 ) );
50+
var b = new Vector3f( 10, 11, 12 );
51+
var xf = new AffineXf3f( A, b );
52+
53+
var res = xf * xf;
54+
Assert.That( res.A == A * A );
55+
Assert.That( res.B == A * b + b );
56+
}
57+
58+
}
59+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using NUnit.Framework;
2+
using static MR;
3+
4+
namespace MRTest
5+
{
6+
[TestFixture]
7+
internal class BitSetTests
8+
{
9+
[Test]
10+
public void TestDefaultConstructor()
11+
{
12+
var a = new BitSet();
13+
Assert.That( a.Size(), Is.EqualTo(0) );
14+
}
15+
16+
[Test]
17+
public void TestConstructor()
18+
{
19+
var a = new BitSet( 20 );
20+
Assert.That(a.Size(), Is.EqualTo(20));
21+
}
22+
23+
[Test]
24+
public void TestSet()
25+
{
26+
var a = new BitSet( 10 );
27+
a.Set( 5 );
28+
Assert.That( a.Test( 5 ) );
29+
Assert.That( !a.Test( 4 ) );
30+
}
31+
32+
[Test]
33+
public void TestFindLast()
34+
{
35+
var a = new BitSet( 10 );
36+
a.Set( 5 );
37+
Assert.That( a.FindLast(), Is.EqualTo(5) );
38+
}
39+
40+
[Test]
41+
public void TestAutoResize()
42+
{
43+
var a = new BitSet();
44+
a.AutoResizeSet(6);
45+
Assert.That( a.Size() == 7 );
46+
}
47+
48+
[Test]
49+
public void TestSubtraction()
50+
{
51+
var a = new BitSet( 10 );
52+
a.Set( 5 );
53+
a.Set(6);
54+
var b = new BitSet( 10 );
55+
b.Set( 6 );
56+
var c = a - b;
57+
Assert.That( c.Test( 5 ) );
58+
Assert.That( !c.Test( 6 ) );
59+
}
60+
61+
[Test]
62+
public void TestUnion()
63+
{
64+
var a = new BitSet( 10 );
65+
a.Set( 5 );
66+
var b = new BitSet( 10 );
67+
b.Set( 6 );
68+
var c = a | b;
69+
Assert.That( c.Test( 5 ) );
70+
Assert.That( c.Test( 6 ) );
71+
}
72+
}
73+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System;
2+
using System.IO;
3+
using NUnit.Framework;
4+
using static MR;
5+
6+
namespace MRTest
7+
{
8+
[TestFixture]
9+
internal class BooleanTests
10+
{
11+
[Test]
12+
public void TestOperations()
13+
{
14+
const float PI = 3.14159265f;
15+
Mesh meshA = MakeTorus(1.1f, 0.5f, 8, 8);
16+
Mesh meshB = MakeTorus(1.0f, 0.2f, 8, 8);
17+
meshB.Transform( AffineXf3f.Linear( Matrix3f.Rotation( Vector3f.PlusZ(), Vector3f.PlusY() ) ) );
18+
19+
const float shiftStep = 0.2f;
20+
const float angleStep = PI;
21+
var baseAxis = new Vector3f[] { Vector3f.PlusX(), Vector3f.PlusY(), Vector3f.PlusZ() };
22+
23+
for (int maskTrans = 0; maskTrans < 8; ++maskTrans)
24+
{
25+
for (int maskRot = 0; maskRot < 8; ++maskRot)
26+
{
27+
for (float shift = 0.01f; shift < 0.2f; shift += shiftStep)
28+
{
29+
Vector3f shiftVec = new Vector3f();
30+
for (int i = 0; i < 3; ++i)
31+
if ( ( maskTrans & ( 1 << i ) ) > 0 )
32+
shiftVec += shift * baseAxis[i];
33+
34+
for (float angle = PI * 0.01f; angle < PI * 7.0f / 18.0f; angle += angleStep)
35+
{
36+
Matrix3f rotation = new Matrix3f();
37+
for (int i = 0; i < 3; ++i)
38+
if ( ( maskRot & (1 << i) ) > 0 )
39+
rotation = Matrix3f.Rotation( baseAxis[i], angle ) * rotation;
40+
41+
BooleanParameters parameters = new BooleanParameters();
42+
parameters.RigidB2A = AffineXf3f.Translation(shiftVec) * AffineXf3f.Linear(rotation);
43+
44+
Assert.DoesNotThrow(() => Boolean(meshA, meshB, BooleanOperation.Union, parameters));
45+
Assert.DoesNotThrow(() => Boolean(meshA, meshB, BooleanOperation.Intersection, parameters));
46+
}
47+
}
48+
}
49+
}
50+
}
51+
52+
[Test]
53+
public void TestMapper()
54+
{
55+
Mesh meshA = MakeTorus(1.1f, 0.5f, 8, 8);
56+
Mesh meshB = MakeTorus(1.0f, 0.2f, 8, 8);
57+
meshB.Transform(AffineXf3f.Linear(Matrix3f.Rotation(Vector3f.PlusZ(), Vector3f.PlusY())));
58+
59+
var parameters = new BooleanParameters();
60+
parameters.Mapper = new BooleanResultMapper();
61+
var booleanResult = Boolean(meshA, meshB, BooleanOperation.Union, parameters);
62+
63+
var validPointsA = meshA.Topology.GetValidVerts();
64+
var validPointsB = meshB.Topology.GetValidVerts();
65+
var validFacesA = meshA.Topology.GetValidFaces();
66+
var validFacesB = meshB.Topology.GetValidFaces();
67+
68+
var old2NewVerts = parameters.Mapper.GetMaps(BooleanResultMapper.MapObject.A).Old2newVerts;
69+
var vMapA = parameters.Mapper.Map(validPointsA, BooleanResultMapper.MapObject.A);
70+
var vMapB = parameters.Mapper.Map(validPointsB, BooleanResultMapper.MapObject.B);
71+
72+
Assert.That(vMapA.Size(), Is.EqualTo(60) );
73+
Assert.That(vMapA.Count(), Is.EqualTo(60));
74+
Assert.That(vMapB.Size(), Is.EqualTo(204) );
75+
Assert.That(vMapB.Count(), Is.EqualTo(48));
76+
77+
78+
var fMapA = parameters.Mapper.Map(validFacesA, BooleanResultMapper.MapObject.A);
79+
var fMapB = parameters.Mapper.Map(validFacesB, BooleanResultMapper.MapObject.B);
80+
81+
Assert.That(fMapA.Size(), Is.EqualTo(224) );
82+
Assert.That(fMapA.Count(), Is.EqualTo(224));
83+
Assert.That(fMapB.Size(), Is.EqualTo(416) );
84+
Assert.That(fMapB.Count(), Is.EqualTo(192));
85+
86+
var newFaces = parameters.Mapper.NewFaces();
87+
Assert.That(newFaces.Size(), Is.EqualTo(416) );
88+
Assert.That(newFaces.Count(), Is.EqualTo(252));
89+
90+
var mapsA = parameters.Mapper.GetMaps( BooleanResultMapper.MapObject.A );
91+
Assert.That(!mapsA.Identity);
92+
Assert.That( mapsA.Old2newVerts.Size(), Is.EqualTo(160) );
93+
Assert.That( mapsA.Cut2newFaces.Size(), Is.EqualTo(348) );
94+
Assert.That( mapsA.Cut2origin.Size(), Is.EqualTo(348) );
95+
96+
var mapsB = parameters.Mapper.GetMaps( BooleanResultMapper.MapObject.B );
97+
Assert.That(!mapsB.Identity);
98+
Assert.That( mapsB.Old2newVerts.Size(), Is.EqualTo(160) );
99+
Assert.That( mapsB.Cut2newFaces.Size(), Is.EqualTo(384) );
100+
Assert.That( mapsB.Cut2origin.Size(), Is.EqualTo(384) );
101+
}
102+
}
103+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using NUnit.Framework;
2+
using static MR;
3+
4+
namespace MRTest
5+
{
6+
[TestFixture]
7+
internal class Box3Tests
8+
{
9+
[Test]
10+
public void TestDefaultConstructor()
11+
{
12+
var box = new Box3f();
13+
Assert.That(!box.Valid());
14+
}
15+
16+
[Test]
17+
public void TestBox()
18+
{
19+
var box = new Box3f(new Vector3f(1, 2, 3), new Vector3f(4, 5, 6));
20+
Assert.That(box.Min.X == 1);
21+
Assert.That(box.Min.Y == 2);
22+
Assert.That(box.Min.Z == 3);
23+
24+
Assert.That(box.Max.X == 4);
25+
Assert.That(box.Max.Y == 5);
26+
Assert.That(box.Max.Z == 6);
27+
28+
var center = box.Center();
29+
Assert.That(center.X == 2.5);
30+
Assert.That(center.Y == 3.5);
31+
Assert.That(center.Z == 4.5);
32+
33+
var size = box.Size();
34+
Assert.That(size.X == 3);
35+
Assert.That(size.Y == 3);
36+
Assert.That(size.Z == 3);
37+
38+
float diagonal = box.Diagonal();
39+
Assert.That(diagonal, Is.EqualTo(5.19).Within(0.01));
40+
41+
float volume = box.Volume();
42+
Assert.That(volume, Is.EqualTo(27).Within(0.01));
43+
}
44+
}
45+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.IO;
3+
using NUnit.Framework;
4+
using static MR;
5+
6+
namespace MRTest
7+
{
8+
[TestFixture]
9+
internal class ConvexHullTests
10+
{
11+
[Test]
12+
public void TestConvexHull()
13+
{
14+
var meshA = MakeCube(Vector3f.Diagonal(1), Vector3f.Diagonal(-0.5f));
15+
var meshB = MakeCube(Vector3f.Diagonal(1), Vector3f.Diagonal(0.0f));
16+
var union = Boolean(meshA, meshB, BooleanOperation.Union);
17+
var convexHull = MakeConvexHull(union.Mesh);
18+
19+
Assert.That(convexHull.Points.Size() == 14);
20+
}
21+
}
22+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.IO;
3+
using NUnit.Framework;
4+
using static MR;
5+
6+
namespace MRTest
7+
{
8+
[TestFixture]
9+
internal class DecimateTests
10+
{
11+
[Test]
12+
public void TestDecimate()
13+
{
14+
Mesh sphere = MakeSphere( new SphereParams( 0.5f, 30000 ) );
15+
16+
var savedRegion = new FaceBitSet((Const_BitSet)sphere.Topology.GetValidFaces());
17+
18+
var parameters = new DecimateSettings();
19+
var region = new FaceBitSet((Const_BitSet)sphere.Topology.GetValidFaces());
20+
if ( region is not null )
21+
parameters.Region = region;
22+
23+
parameters.MaxTriangleAspectRatio = 80;
24+
25+
var decimateResult = DecimateMesh(sphere, parameters);
26+
Assert.That(parameters.Region is not null && !parameters.Region.Equals( savedRegion ) );
27+
Assert.That(decimateResult.FacesDeleted > 0);
28+
Assert.That(decimateResult.VertsDeleted > 0);
29+
}
30+
31+
[Test]
32+
public void TestRemesh()
33+
{
34+
var sphere = MakeSphere( new SphereParams( 0.5f, 300 ) );
35+
Assert.That(sphere.Topology.GetValidFaces().Count(), Is.EqualTo(596));
36+
var parameters = new RemeshSettings();
37+
parameters.TargetEdgeLen = 0.1f;
38+
var remeshResult = Remesh(sphere, parameters);
39+
Assert.That(sphere.Topology.GetValidFaces().Count(), Is.EqualTo(716));
40+
}
41+
}
42+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using NUnit.Framework;
2+
using static MR;
3+
4+
namespace MRTest
5+
{
6+
[TestFixture]
7+
internal class ExpandShrinkTests
8+
{
9+
[Test]
10+
public void TestExpandShrink()
11+
{
12+
var mesh = MakeSphere(new SphereParams(1.0f, 3000));
13+
var region = Expand(mesh.Topology, new FaceId(0), 3);
14+
Assert.That(region.Count, Is.EqualTo(75));
15+
Expand(mesh.Topology, region, 3);
16+
Assert.That(region.Count, Is.GreaterThan(75));
17+
Shrink(mesh.Topology, region, 3);
18+
Assert.That(region.Count, Is.EqualTo(75));
19+
}
20+
21+
[Test]
22+
public void TestExpandShrinkVerts()
23+
{
24+
var mesh = MakeSphere(new SphereParams(1.0f, 3000));
25+
var region = Expand(mesh.Topology, new VertId(0), 3);
26+
Assert.That(region.Count, Is.EqualTo(37));
27+
Expand(mesh.Topology, region, 3);
28+
Assert.That(region.Count, Is.GreaterThan(37));
29+
Shrink(mesh.Topology, region, 3);
30+
Assert.That(region.Count, Is.EqualTo(37));
31+
}
32+
33+
}
34+
}

0 commit comments

Comments
 (0)