1 module tests.ray_aabb_intersect_test;
2 
3 import ray_aabb_intersection;
4 import tests.dunit_tests;
5 import std.stdio;
6 
7 /*
8  * The MIT License
9  *
10  * Copyright (c) 2016-2021 JOML.
11  &^^%$ Translated by jordan4ibanez
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a copy
14  * of this software and associated documentation files (the "Software"), to deal
15  * in the Software without restriction, including without limitation the rights
16  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17  * copies of the Software, and to permit persons to whom the Software is
18  * furnished to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be included in
21  * all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29  * THE SOFTWARE.
30  */
31 
32 /**
33  * Tests for the {@link RayAabIntersection}.
34  * 
35  * @author Kai Burjack
36  */
37 unittest {
38 
39     writeln("\nTESTING RAY AABB INTERSECT\n");
40 
41     // testPX
42     {
43         RayAabIntersection r = RayAabIntersection();
44         r.set(-1, 0, 0, 1, 0, 0);
45         assertTrue(r.test(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f));
46     }
47 
48     // testPY
49     {
50         RayAabIntersection r = RayAabIntersection();
51         r.set(0, -1, 0, 0, 1, 0);
52         assertTrue(r.test(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f));
53     }
54 
55     // testPZ
56     {
57         RayAabIntersection r = RayAabIntersection();
58         r.set(0, 0, -1, 0, 0, 1);
59         assertTrue(r.test(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f));
60     }
61 
62     // testNX
63     {
64         RayAabIntersection r = RayAabIntersection();
65         r.set(1, 0, 0, -1, 0, 0);
66         assertTrue(r.test(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f));
67     }
68 
69     // testNY
70     {
71         RayAabIntersection r = RayAabIntersection();
72         r.set(0, 1, 0, 0, -1, 0);
73         assertTrue(r.test(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f));
74     }
75 
76     // testNZ
77     {
78         RayAabIntersection r = RayAabIntersection();
79         r.set(0, 0, 1, 0, 0, -1);
80         assertTrue(r.test(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f));
81     }
82 
83     // testPXPY
84     {
85         RayAabIntersection r = RayAabIntersection();
86         r.set(-1, -1, 0, 1, 1, 0);
87         assertTrue(r.test(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f));
88     }
89 
90     // testPXEdge
91     {
92         RayAabIntersection r = RayAabIntersection();
93         r.set(-1, 0.5f, 0, 1, 0, 0);
94         assertTrue(r.test(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f));
95     }
96 
97     // testPXEdgeDelta
98     {
99         RayAabIntersection r = RayAabIntersection();
100         r.set(-1, 0.500001f, 0, 1, 0, 0);
101         assertFalse(r.test(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f));
102     }
103 
104     // testNXEdge
105     {
106         RayAabIntersection r = RayAabIntersection();
107         r.set(-1, -0.5f, 0, 1, 0, 0);
108         assertTrue(r.test(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f));
109     }
110 
111     // testNXEdgeDelta
112     {
113         RayAabIntersection r = RayAabIntersection();
114         r.set(-1, -0.500001f, 0, 1, 0, 0);
115         assertFalse(r.test(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f));
116     }
117     writeln("PASSED!");
118 }