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