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 2 : TEST(Boundary, test_method_add) {
29 2 : Boundary bound;
30 2 : bound.add(1, 2); // Will work for bound.add(2,1) too
31 2 : EXPECT_DOUBLE_EQ(bound.xmax(), 1);
32 2 : EXPECT_DOUBLE_EQ(bound.xmin(), 1);
33 2 : EXPECT_DOUBLE_EQ(bound.ymax(), 2);
34 2 : EXPECT_DOUBLE_EQ(bound.ymin(), 2);
35 2 : }
36 :
37 : /* Test the method 'add' with multiple calls*/
38 2 : TEST(Boundary, test_method_add_multiple) {
39 2 : Boundary bound;
40 2 : bound.add(-1, -2);
41 2 : bound.add(3, 5);
42 2 : bound.add(5, 8);
43 2 : EXPECT_DOUBLE_EQ(bound.xmax(), 5);
44 2 : EXPECT_DOUBLE_EQ(bound.xmin(), -1);
45 2 : EXPECT_DOUBLE_EQ(bound.ymax(), 8);
46 2 : EXPECT_DOUBLE_EQ(bound.ymin(), -2);
47 2 : }
48 :
49 : /* Test the method 'getCenter'*/
50 2 : TEST(Boundary, test_method_getCenter) {
51 2 : Boundary bound(-2, -4, 4, 8);
52 2 : Position pos = bound.getCenter();
53 2 : EXPECT_DOUBLE_EQ(pos.x(), 1);
54 2 : EXPECT_DOUBLE_EQ(pos.y(), 2);
55 2 : }
56 :
57 : /* Test the method 'getWidth' and getHeight*/
58 2 : TEST(Boundary, test_method_getWidthHeight) {
59 2 : Boundary bound(-2, -4, 4, 8);
60 2 : EXPECT_DOUBLE_EQ(bound.getHeight(), 12);
61 2 : EXPECT_DOUBLE_EQ(bound.getWidth(), 6);
62 2 : }
63 :
64 : /* Test the method 'around'*/
65 2 : TEST(Boundary, test_method_around) {
66 2 : Boundary bound(1, 2, 3, 6);
67 2 : EXPECT_TRUE(bound.around(Position(2, 4)));
68 2 : EXPECT_FALSE(bound.around(Position(0, 4)));
69 2 : EXPECT_FALSE(bound.around(Position(2, 7)));
70 2 : EXPECT_TRUE(bound.around(Position(0, 7), 2));
71 2 : }
72 :
73 : /* Test the method 'overlapsWith'*/
74 2 : TEST(Boundary, test_method_overlapsWith) {
75 2 : Boundary bound(1, 2, 3, 6);
76 2 : EXPECT_FALSE(bound.overlapsWith(Boundary(10, 17, 13, 16)));
77 4 : EXPECT_TRUE(bound.overlapsWith(Boundary(-1, -7, 2, 4)));
78 4 : EXPECT_TRUE(bound.overlapsWith(Boundary(1, 2, 3, 6)));
79 4 : EXPECT_TRUE(bound.overlapsWith(Boundary(0, 3, 4, 5)));
80 2 : EXPECT_FALSE(bound.overlapsWith(Boundary(4, 2, 5, 7), 0));
81 4 : EXPECT_TRUE(bound.overlapsWith(Boundary(4, 2, 5, 7), 1));
82 2 : }
83 :
84 : /* Test the method 'crosses'*/
85 2 : TEST(Boundary, test_method_crosses) {
86 2 : Boundary bound(1, 2, 3, 6);
87 2 : EXPECT_TRUE(bound.crosses(Position(3, 2), Position(4, 2)));
88 2 : EXPECT_TRUE(bound.crosses(Position(2, 1), Position(0, 3)));
89 2 : EXPECT_TRUE(bound.crosses(Position(1, 2), Position(3, 6)));
90 2 : EXPECT_FALSE(bound.crosses(Position(0, 0), Position(0, 8)));
91 2 : }
92 :
93 : /* Test the method 'partialWithin'*/
94 2 : TEST(Boundary, test_method_partialWithin) {
95 2 : Boundary bound(1, 2, 3, 6);
96 4 : EXPECT_TRUE(bound.partialWithin(Boundary(1, 2, 1, 2)));
97 2 : EXPECT_FALSE(bound.partialWithin(Boundary(10, 17, 13, 16)));
98 4 : EXPECT_TRUE(bound.partialWithin(Boundary(1, 2, 3, 6)));
99 4 : EXPECT_TRUE(bound.partialWithin(Boundary(4, 2, 5, 7), 1));
100 2 : }
101 :
102 : /* Test the method 'flipY'*/
103 2 : TEST(Boundary, test_method_flipY) {
104 2 : Boundary bound(1, 2, 3, 6);
105 2 : bound.flipY();
106 2 : EXPECT_DOUBLE_EQ(bound.xmax(), 3);
107 2 : EXPECT_DOUBLE_EQ(bound.xmin(), 1);
108 2 : EXPECT_DOUBLE_EQ(bound.ymax(), -2);
109 2 : EXPECT_DOUBLE_EQ(bound.ymin(), -6);
110 2 : }
111 :
112 : /* Test the method 'moveby'*/
113 2 : TEST(Boundary, test_method_moveby) {
114 2 : Boundary bound(1, 2, 3, 6);
115 2 : bound.moveby(2.5, -3.5);
116 2 : EXPECT_DOUBLE_EQ(bound.xmax(), 5.5);
117 2 : EXPECT_DOUBLE_EQ(bound.xmin(), 3.5);
118 2 : EXPECT_DOUBLE_EQ(bound.ymax(), 2.5);
119 2 : EXPECT_DOUBLE_EQ(bound.ymin(), -1.5);
120 2 : }
121 :
122 :
123 :
124 : /* Test the method 'growWidth'*/
125 2 : TEST(Boundary, test_method_growWidth) {
126 2 : Boundary bound(1, 2, 3, 6);
127 2 : bound.growWidth(0.5);
128 2 : EXPECT_DOUBLE_EQ(bound.xmin(), 0.5);
129 2 : EXPECT_DOUBLE_EQ(bound.xmax(), 3.5);
130 2 : }
131 :
132 : /* Test the method 'growHeight'*/
133 2 : TEST(Boundary, test_method_growHeight) {
134 2 : Boundary bound(1, 2, 3, 6);
135 2 : bound.growHeight(0.5);
136 2 : EXPECT_DOUBLE_EQ(bound.ymin(), 1.5);
137 2 : EXPECT_DOUBLE_EQ(bound.ymax(), 6.5);
138 2 : }
|