1 module tests.geometry_utils_test;
2 
3 import geometry_utils;
4 import Math = math;
5 import vector_2d;
6 import vector_3d;
7 import tests.dunit_tests;
8 import std.stdio;
9 
10 /*
11  * The MIT License
12  *
13  * Copyright (c) 2015-2021 Richard Greenlees
14  #$#$% Translated by jordan4ibanez
15  *
16  * Permission is hereby granted, free of charge, to any person obtaining a copy
17  * of this software and associated documentation files (the "Software"), to deal
18  * in the Software without restriction, including without limitation the rights
19  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20  * copies of the Software, and to permit persons to whom the Software is
21  * furnished to do so, subject to the following conditions:
22  *
23  * The above copyright notice and this permission notice shall be included in
24  * all copies or substantial portions of the Software.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32  * THE SOFTWARE.
33  */
34 
35 
36 /**
37  * Tests for the {@link GeometryUtils} class.
38  *
39  * @author Jarosław Piotrowski
40  */
41 unittest {
42 
43     writeln("\nBEGINNING TEST OF GEOMETRY UTILS\n");
44     
45     Vector3d pos1 = Vector3d(-1.0f,  1.0f, 0.0f);
46     Vector3d pos2 = Vector3d( 1.0f, -1.0f, 0.0f);
47     Vector3d pos3 = Vector3d( 1.0f,  1.0f, 0.0f);
48 
49     Vector2d uv1 = Vector2d(0.0f, 1.0f);
50     Vector2d uv2 = Vector2d(1.0f, 0.0f);
51     Vector2d uv3 = Vector2d(1.0f, 1.0f);
52 
53     Vector3d t = Vector3d(1, 0, 0);
54     Vector3d b = Vector3d(0, 1, 0);
55 
56     Vector3d vecTangent = Vector3d();
57     Vector3d vecBitangent = Vector3d();
58 
59     tangent(pos1, uv1, pos2, uv2, pos3, uv3, vecTangent);
60     assertEquals(t, vecTangent);
61 
62     bitangent(pos1, uv1, pos2, uv2, pos3, uv3, vecBitangent);
63     assertEquals(b, vecBitangent);
64 
65     tangentBitangent(pos1, uv1, pos2, uv2, pos3, uv3, vecTangent, vecBitangent);
66     assertEquals(t, vecTangent);
67     assertEquals(b, vecBitangent);    
68 
69     writeln("PASSED!");
70 
71 }