Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file BoundaryTest.cpp
15 : /// @author Matthias Heppner
16 : /// @author Michael Behrisch
17 : /// @date 2009-05-27
18 : ///
19 : // Tests the class Boundary
20 : /****************************************************************************/
21 : #include <config.h>
22 :
23 : #include <gtest/gtest.h>
24 : #include <utils/geom/Boundary.h>
25 :
26 :
27 : /* Test the method 'add'*/
28 1 : TEST(Boundary, test_method_add) {
29 1 : Boundary bound;
30 1 : bound.add(1, 2); // Will work for bound.add(2,1) too
31 1 : EXPECT_DOUBLE_EQ(bound.xmax(), 1);
32 1 : EXPECT_DOUBLE_EQ(bound.xmin(), 1);
33 1 : EXPECT_DOUBLE_EQ(bound.ymax(), 2);
34 1 : EXPECT_DOUBLE_EQ(bound.ymin(), 2);
35 1 : }
36 :
37 : /* Test the method 'add' with multiple calls*/
38 1 : TEST(Boundary, test_method_add_multiple) {
39 1 : Boundary bound;
40 1 : bound.add(-1, -2);
41 1 : bound.add(3, 5);
42 1 : bound.add(5, 8);
43 1 : EXPECT_DOUBLE_EQ(bound.xmax(), 5);
44 1 : EXPECT_DOUBLE_EQ(bound.xmin(), -1);
45 1 : EXPECT_DOUBLE_EQ(bound.ymax(), 8);
46 1 : EXPECT_DOUBLE_EQ(bound.ymin(), -2);
47 1 : }
48 :
49 : /* Test the method 'getCenter'*/
50 1 : TEST(Boundary, test_method_getCenter) {
51 1 : Boundary bound(-2, -4, 4, 8);
52 1 : Position pos = bound.getCenter();
53 1 : EXPECT_DOUBLE_EQ(pos.x(), 1);
54 1 : EXPECT_DOUBLE_EQ(pos.y(), 2);
55 1 : }
56 :
57 : /* Test the method 'getWidth' and getHeight*/
58 1 : TEST(Boundary, test_method_getWidthHeight) {
59 1 : Boundary bound(-2, -4, 4, 8);
60 1 : EXPECT_DOUBLE_EQ(bound.getHeight(), 12);
61 1 : EXPECT_DOUBLE_EQ(bound.getWidth(), 6);
62 1 : }
63 :
64 : /* Test the method 'around'*/
65 1 : TEST(Boundary, test_method_around) {
66 1 : Boundary bound(1, 2, 3, 6);
67 1 : EXPECT_TRUE(bound.around(Position(2, 4)));
68 1 : EXPECT_FALSE(bound.around(Position(0, 4)));
69 1 : EXPECT_FALSE(bound.around(Position(2, 7)));
70 1 : EXPECT_TRUE(bound.around(Position(0, 7), 2));
71 1 : }
72 :
73 : /* Test the method 'overlapsWith'*/
74 1 : TEST(Boundary, test_method_overlapsWith) {
75 1 : Boundary bound(1, 2, 3, 6);
76 1 : EXPECT_FALSE(bound.overlapsWith(Boundary(10, 17, 13, 16)));
77 1 : EXPECT_TRUE(bound.overlapsWith(Boundary(-1, -7, 2, 4)));
78 1 : EXPECT_TRUE(bound.overlapsWith(Boundary(1, 2, 3, 6)));
79 1 : EXPECT_TRUE(bound.overlapsWith(Boundary(0, 3, 4, 5)));
80 1 : EXPECT_FALSE(bound.overlapsWith(Boundary(4, 2, 5, 7), 0));
81 1 : EXPECT_TRUE(bound.overlapsWith(Boundary(4, 2, 5, 7), 1));
82 1 : }
83 :
84 : /* Test the method 'crosses'*/
85 1 : TEST(Boundary, test_method_crosses) {
86 1 : Boundary bound(1, 2, 3, 6);
87 1 : EXPECT_TRUE(bound.crosses(Position(3, 2), Position(4, 2)));
88 1 : EXPECT_TRUE(bound.crosses(Position(2, 1), Position(0, 3)));
89 1 : EXPECT_TRUE(bound.crosses(Position(1, 2), Position(3, 6)));
90 1 : EXPECT_FALSE(bound.crosses(Position(0, 0), Position(0, 8)));
91 1 : }
92 :
93 : /* Test the method 'partialWithin'*/
94 1 : TEST(Boundary, test_method_partialWithin) {
95 1 : Boundary bound(1, 2, 3, 6);
96 1 : EXPECT_TRUE(bound.partialWithin(Boundary(1, 2, 1, 2)));
97 1 : EXPECT_FALSE(bound.partialWithin(Boundary(10, 17, 13, 16)));
98 1 : EXPECT_TRUE(bound.partialWithin(Boundary(1, 2, 3, 6)));
99 1 : EXPECT_TRUE(bound.partialWithin(Boundary(4, 2, 5, 7), 1));
100 1 : }
101 :
102 : /* Test the method 'flipY'*/
103 1 : TEST(Boundary, test_method_flipY) {
104 1 : Boundary bound(1, 2, 3, 6);
105 1 : bound.flipY();
106 1 : EXPECT_DOUBLE_EQ(bound.xmax(), 3);
107 1 : EXPECT_DOUBLE_EQ(bound.xmin(), 1);
108 1 : EXPECT_DOUBLE_EQ(bound.ymax(), -2);
109 1 : EXPECT_DOUBLE_EQ(bound.ymin(), -6);
110 1 : }
111 :
112 : /* Test the method 'moveby'*/
113 1 : TEST(Boundary, test_method_moveby) {
114 1 : Boundary bound(1, 2, 3, 6);
115 1 : bound.moveby(2.5, -3.5);
116 1 : EXPECT_DOUBLE_EQ(bound.xmax(), 5.5);
117 1 : EXPECT_DOUBLE_EQ(bound.xmin(), 3.5);
118 1 : EXPECT_DOUBLE_EQ(bound.ymax(), 2.5);
119 1 : EXPECT_DOUBLE_EQ(bound.ymin(), -1.5);
120 1 : }
121 :
122 :
123 :
124 : /* Test the method 'growWidth'*/
125 1 : TEST(Boundary, test_method_growWidth) {
126 1 : Boundary bound(1, 2, 3, 6);
127 1 : bound.growWidth(0.5);
128 1 : EXPECT_DOUBLE_EQ(bound.xmin(), 0.5);
129 1 : EXPECT_DOUBLE_EQ(bound.xmax(), 3.5);
130 1 : }
131 :
132 : /* Test the method 'growHeight'*/
133 1 : TEST(Boundary, test_method_growHeight) {
134 1 : Boundary bound(1, 2, 3, 6);
135 1 : bound.growHeight(0.5);
136 1 : EXPECT_DOUBLE_EQ(bound.ymin(), 1.5);
137 1 : EXPECT_DOUBLE_EQ(bound.ymax(), 6.5);
138 1 : }
|