Skip to content

Commit ca6619c

Browse files
committed
Add Box/Boxd data structures
1 parent b0d81dd commit ca6619c

File tree

9 files changed

+839
-22
lines changed

9 files changed

+839
-22
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System.Linq;
2+
using System.Numerics;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
using Sledge.Formats.Geometric;
5+
6+
namespace Sledge.Formats.Tests.Geometry;
7+
8+
[TestClass]
9+
public class TestBox
10+
{
11+
[TestMethod]
12+
public void TestConstructors()
13+
{
14+
var a = new Vector3(-10, -20, -30);
15+
var b = new Vector3(10, 20, 30);
16+
var box = new Box(a, b);
17+
Assert.AreEqual(a, box.Start);
18+
Assert.AreEqual(b, box.End);
19+
Assert.AreEqual(box, new Box(a with { X = b.X }, b with { X = a.X }));
20+
Assert.AreEqual(box, new Box(a with { Y = b.Y }, b with { Y = a.Y }));
21+
Assert.AreEqual(box, new Box(a with { Z = b.Z }, b with { Z = a.Z }));
22+
Assert.AreEqual(box, new Box(new[] { box, box, box }));
23+
24+
Assert.AreEqual(Vector3.Zero, box.Center);
25+
Assert.AreEqual(b.X * 2, box.Width);
26+
Assert.AreEqual(b.Y * 2, box.Length);
27+
Assert.AreEqual(b.Z * 2, box.Height);
28+
Assert.AreEqual(b.X * 2, box.SmallestDimension);
29+
Assert.AreEqual(b.Z * 2, box.LargestDimension);
30+
Assert.AreEqual(b * 2, box.Dimensions);
31+
}
32+
33+
[TestMethod]
34+
public void TestIsEmpty()
35+
{
36+
Assert.IsTrue(Box.Empty.IsEmpty());
37+
Assert.IsTrue(new Box(Vector3.One, Vector3.One).IsEmpty());
38+
Assert.IsFalse(new Box(Vector3.One, Vector3.One * 2).IsEmpty());
39+
Assert.IsFalse(new Box(Vector3.One, Vector3.One * 2).IsEmpty(1));
40+
Assert.IsTrue(new Box(Vector3.One, Vector3.One * 2).IsEmpty(1.01f));
41+
}
42+
43+
[TestMethod]
44+
public void TestGetBoxPoints()
45+
{
46+
var a = new Vector3(-10, -20, -30);
47+
var b = new Vector3(10, 20, 30);
48+
var box = new Box(a, b);
49+
var expected = new[]
50+
{
51+
a, b,
52+
a with { X = b.X },
53+
a with { Y = b.Y },
54+
a with { Z = b.Z },
55+
b with { X = a.X },
56+
b with { Y = a.Y },
57+
b with { Z = a.Z },
58+
};
59+
CollectionAssert.AreEquivalent(expected, box.GetBoxPoints().ToList());
60+
}
61+
62+
[TestMethod]
63+
public void TestGetBoxPlanes()
64+
{
65+
var a = new Vector3(-10, -20, -30);
66+
var b = new Vector3(10, 20, 30);
67+
var box = new Box(a, b);
68+
var expected = new[]
69+
{
70+
new Plane(Vector3.UnitX, b.X),
71+
new Plane(Vector3.UnitY, b.Y),
72+
new Plane(Vector3.UnitZ, b.Z),
73+
new Plane(-Vector3.UnitX, -a.X),
74+
new Plane(-Vector3.UnitY, -a.Y),
75+
new Plane(-Vector3.UnitZ, -a.Z),
76+
};
77+
CollectionAssert.AreEquivalent(expected, box.GetBoxPlanes().ToList());
78+
}
79+
}

Sledge.Formats.Tests/Geometry/TestPlane.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using Microsoft.VisualStudio.TestTools.UnitTesting;
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
72
using Sledge.Formats.Geometric;
83
using Sledge.Formats.Geometric.Precision;
94

Sledge.Formats.Tests/Geometry/TestPolygon.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Numerics;
5-
using System.Text;
6-
using System.Threading.Tasks;
1+
using System.Numerics;
72
using Microsoft.VisualStudio.TestTools.UnitTesting;
83
using Sledge.Formats.Geometric;
94
using Sledge.Formats.Geometric.Precision;

Sledge.Formats.Tests/Geometry/TestPolyhedron.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
1+
using System.Linq;
42
using System.Numerics;
5-
using System.Text;
6-
using System.Threading.Tasks;
73
using Microsoft.VisualStudio.TestTools.UnitTesting;
8-
using Sledge.Formats.Geometric;
94
using Sledge.Formats.Geometric.Precision;
105

116
namespace Sledge.Formats.Tests.Geometry;

0 commit comments

Comments
 (0)