Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/geom/Boundary.h
169678 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 Boundary.h
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date Sept 2002
19
///
20
// A class that stores a 2D geometrical boundary
21
/****************************************************************************/
22
#pragma once
23
#include <config.h>
24
25
#include <iostream>
26
#include <utility>
27
28
#include "AbstractPoly.h"
29
#include "PositionVector.h"
30
31
32
// ===========================================================================
33
// class definitions
34
// ===========================================================================
35
/**
36
* @class Boundary
37
* @brief A class that stores a 2D geometrical boundary
38
*/
39
class Boundary : public AbstractPoly {
40
public:
41
/// @brief Constructor - the boundary is unset
42
Boundary();
43
44
/// @brief Constructor - the boundary will be build using the given values
45
Boundary(double x1, double y1, double x2, double y2);
46
47
/// @brief Constructor - the boundary will be build using the given values including Z
48
Boundary(double x1, double y1, double z1, double x2, double y2, double z2);
49
50
/// @brief Resets the boundary
51
void reset();
52
53
/// @brief Makes the boundary include the given coordinate
54
void add(double x, double y, double z = 0);
55
56
/// @brief Makes the boundary include the given coordinate
57
void add(const Position& p);
58
59
/// @brief Makes the boundary include the given boundary
60
void add(const Boundary& p);
61
62
/// @brief Returns the center of the boundary
63
Position getCenter() const;
64
65
/// @brief Returns minimum x-coordinate
66
double xmin() const;
67
68
/// @brief Returns maximum x-coordinate
69
double xmax() const;
70
71
/// @brief Returns minimum y-coordinate
72
double ymin() const;
73
74
/// @brief Returns maximum y-coordinate
75
double ymax() const;
76
77
/// @brief Returns minimum z-coordinate
78
double zmin() const;
79
80
/// @brief Returns maximum z-coordinate
81
double zmax() const;
82
83
/// @brief Returns the width of the boudary (x-axis)
84
double getWidth() const;
85
86
/// @brief Returns the height of the boundary (y-axis)
87
double getHeight() const;
88
89
/// @brief Returns the elevation range of the boundary (z-axis)
90
double getZRange() const;
91
92
/// @name inherited from AbstractPoly
93
/// @{
94
95
/// @brief Returns whether the boundary contains the given coordinate
96
bool around(const Position& p, double offset = 0) const;
97
98
/// @brief Returns whether the boundary contains the given 2D coordinate (position)
99
bool around2D(const Position& p, double offset = 0) const;
100
101
/// @brief Returns whether the boundary contains the given 2D coordinate (x-y version)
102
bool around2D(const double x, const double y) const;
103
104
/// @brief Returns whether the boundary overlaps with the given polygon
105
bool overlapsWith(const AbstractPoly& poly, double offset = 0) const;
106
107
/// @brief Returns whether the boundary is partially within the given polygon
108
bool partialWithin(const AbstractPoly& poly, double offset = 0) const;
109
110
/// @brief Returns whether the boundary crosses the given line
111
bool crosses(const Position& p1, const Position& p2) const;
112
113
/// @}
114
115
/// @brief return true if this boundary contains the given boundary (only X-Y)
116
bool contains2D(const Boundary& b) const;
117
118
/// @brief return true if at least one point of the given boundary is in boundary(only X-Y)
119
bool overlaps2D(const Boundary& b) const;
120
121
/// @brief check if Boundary is Initialised
122
bool isInitialised() const;
123
124
/// @brief returns the euclidean distance in the x-y-plane
125
double distanceTo2D(const Position& p) const;
126
127
/// @brief returns the euclidean distance in the x-y-plane
128
double distanceTo2D(const Boundary& b) const;
129
130
/**@brief extends the boundary by the given amount
131
* @return a reference to the instance for further use
132
*/
133
Boundary& grow(double by);
134
135
/**@brief scale the boundary by the given amount
136
* @return a reference to the instance for further use
137
*/
138
Boundary& scale(double by);
139
140
/// @brief Increases the width of the boundary (x-axis)
141
void growWidth(double by);
142
143
/// @brief Increases the height of the boundary (y-axis)
144
void growHeight(double by);
145
146
/// @brief flips ymin and ymax
147
void flipY();
148
149
/// @brief Sets the boundary to the given values
150
void set(double xmin, double ymin, double xmax, double ymax);
151
152
/// @brief Sets the boundary to the given values, ignoring min < max constraints
153
void setOffsets(double xmin, double ymin, double xmax, double ymax);
154
155
/// @brief Moves the boundary by the given amount
156
void moveby(double x, double y, double z = 0);
157
158
/// @brief get position vector (shape) based on this boundary
159
PositionVector getShape(const bool closeShape) const;
160
161
/// @brief Output operator
162
friend std::ostream& operator<<(std::ostream& os, const Boundary& b);
163
164
/// @brief Comparison operator equal
165
bool operator==(const Boundary& b) const;
166
167
/// @brief Comparison operator not equal
168
bool operator!=(const Boundary& b) const;
169
170
private:
171
/// @brief The boundaries
172
double myXmin, myXmax, myYmin, myYmax, myZmin, myZmax;
173
174
/// @brief Information whether the boundary was initialised
175
bool myWasInitialised;
176
};
177
178