1 module doml.tests.vector_2d_test;
2 
3 import doml.tests.dunit_tests;
4 import Math = doml.math;
5 import doml.vector_2d;
6 import std.stdio;
7 
8 /*
9  * The MIT License
10  *
11  * Copyright (c) 2015-2021 JOML.
12  %$%# Translated by jordan4ibanez
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a copy
15  * of this software and associated documentation files (the "Software"), to deal
16  * in the Software without restriction, including without limitation the rights
17  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18  * copies of the Software, and to permit persons to whom the Software is
19  * furnished to do so, subject to the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be included in
22  * all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30  * THE SOFTWARE.
31  */
32 
33 
34 /**
35  * Test class for {@link Vector2d}.
36  * @author Sebastian Fellner
37  */
38 unittest {
39 
40     writeln("\nBEGINNING VECTOR2D TESTING\n");
41 
42     writeln("TESTING ANGLE VECTOR2D TO VECTOR2D");
43     {
44         Vector2d testVec1 = Vector2d(-9.37, 5.892);
45         Vector2d testVec2 = Vector2d();
46         
47         // angle(v, v) should give 0
48         double angle = testVec1.angle(testVec1);
49         assertEquals(0, angle, MANY_OPS_AROUND_ZERO_PRECISION_DOUBLE);
50         
51         // angle(v, -v) should give Math.PI
52         testVec1.negate(testVec2);
53         angle = testVec1.angle(testVec2);
54         assertEquals(Math.PI, angle, MANY_OPS_AROUND_ZERO_PRECISION_DOUBLE);
55     }
56 
57     writeln("PASSED!");
58 
59     writeln("BEGIN PERPINDICULAR");
60     {
61         Vector2d testVec1 = Vector2d(-9.37, 5.892);
62         assertVector2dEquals(Vector2d(testVec1).perpendicular(),Vector2d(5.892,9.37),0.000001);
63     }
64     writeln("PASSED!");
65 }