-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathBoundsTests.cs
More file actions
146 lines (119 loc) · 3.74 KB
/
BoundsTests.cs
File metadata and controls
146 lines (119 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System.IO;
using NUnit.Framework;
using Obj2Tiles.Library.Geometry;
using Shouldly;
namespace Obj2Tiles.Library.Test;
/// <summary>
/// Tests for Box3 bounding box and mesh Bounds calculation.
/// </summary>
public class BoundsTests
{
private const string TestDataPath = "TestData";
[Test]
public void Bounds_Triangle_Correct()
{
var mesh = MeshUtils.LoadMesh(Path.Combine(TestDataPath, "triangle.obj"));
var bounds = mesh.Bounds;
bounds.Min.X.ShouldBe(0.0);
bounds.Min.Y.ShouldBe(0.0);
bounds.Min.Z.ShouldBe(0.0);
bounds.Max.X.ShouldBe(1.0);
bounds.Max.Y.ShouldBe(1.0);
bounds.Max.Z.ShouldBe(0.0);
}
[Test]
public void Bounds_Cube3D_SymmetricAroundOrigin()
{
var mesh = MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube-3d.obj"));
var bounds = mesh.Bounds;
bounds.Min.X.ShouldBe(-1.0);
bounds.Min.Y.ShouldBe(-1.0);
bounds.Min.Z.ShouldBe(-1.0);
bounds.Max.X.ShouldBe(1.0);
bounds.Max.Y.ShouldBe(1.0);
bounds.Max.Z.ShouldBe(1.0);
bounds.Width.ShouldBe(2.0);
bounds.Height.ShouldBe(2.0);
bounds.Depth.ShouldBe(2.0);
}
[Test]
public void Bounds_Center_IsCorrect()
{
var mesh = MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube-3d.obj"));
var center = mesh.Bounds.Center;
center.X.ShouldBe(0.0);
center.Y.ShouldBe(0.0);
center.Z.ShouldBe(0.0);
}
[Test]
public void Bounds_AfterSplit_SubsetsOfOriginal()
{
var mesh = MeshUtils.LoadMesh(Path.Combine(TestDataPath, "cube-3d.obj"));
var originalBounds = mesh.Bounds;
var xutils = new VertexUtilsX();
mesh.Split(xutils, 0.0, out var left, out var right);
var lb = left.Bounds;
lb.Min.X.ShouldBeGreaterThanOrEqualTo(originalBounds.Min.X - 1e-9);
lb.Max.X.ShouldBeLessThanOrEqualTo(0.0 + 1e-9);
var rb = right.Bounds;
rb.Min.X.ShouldBeGreaterThanOrEqualTo(0.0 - 1e-9);
rb.Max.X.ShouldBeLessThanOrEqualTo(originalBounds.Max.X + 1e-9);
}
// --- Box3 Split ---
[Test]
public void Box3_SplitX_CoversFull()
{
var box = new Box3(-1, -1, -1, 1, 1, 1);
var halves = box.Split(Axis.X);
halves.Length.ShouldBe(2);
halves[0].Min.X.ShouldBe(-1.0);
halves[0].Max.X.ShouldBe(0.0);
halves[1].Min.X.ShouldBe(0.0);
halves[1].Max.X.ShouldBe(1.0);
// Y and Z unchanged
halves[0].Min.Y.ShouldBe(-1.0);
halves[0].Max.Y.ShouldBe(1.0);
}
[Test]
public void Box3_SplitY_CoversFull()
{
var box = new Box3(-1, -1, -1, 1, 1, 1);
var halves = box.Split(Axis.Y);
halves[0].Max.Y.ShouldBe(0.0);
halves[1].Min.Y.ShouldBe(0.0);
}
[Test]
public void Box3_SplitZ_CoversFull()
{
var box = new Box3(-1, -1, -1, 1, 1, 1);
var halves = box.Split(Axis.Z);
halves[0].Max.Z.ShouldBe(0.0);
halves[1].Min.Z.ShouldBe(0.0);
}
[Test]
public void Box3_SplitAtPosition_Correct()
{
var box = new Box3(0, 0, 0, 10, 10, 10);
var halves = box.Split(Axis.X, 3.0);
halves[0].Max.X.ShouldBe(3.0);
halves[1].Min.X.ShouldBe(3.0);
}
[Test]
public void Box3_Center_Calculation()
{
var box = new Box3(2, 4, 6, 8, 10, 12);
var center = box.Center;
center.X.ShouldBe(5.0);
center.Y.ShouldBe(7.0);
center.Z.ShouldBe(9.0);
}
[Test]
public void Box3_Equality()
{
var a = new Box3(0, 0, 0, 1, 1, 1);
var b = new Box3(0, 0, 0, 1, 1, 1);
var c = new Box3(0, 0, 0, 2, 1, 1);
(a == b).ShouldBeTrue();
(a != c).ShouldBeTrue();
}
}