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
+ }
0 commit comments