Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
Boundary.h
Go to the documentation of this file.
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/****************************************************************************/
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// ===========================================================================
39class Boundary : public AbstractPoly {
40public:
42 Boundary();
43
45 Boundary(double x1, double y1, double x2, double y2);
46
48 Boundary(double x1, double y1, double z1, double x2, double y2, double z2);
49
51 void reset();
52
54 void add(double x, double y, double z = 0);
55
57 void add(const Position& p);
58
60 void add(const Boundary& p);
61
63 Position getCenter() const;
64
66 double xmin() const;
67
69 double xmax() const;
70
72 double ymin() const;
73
75 double ymax() const;
76
78 double zmin() const;
79
81 double zmax() const;
82
84 double getWidth() const;
85
87 double getHeight() const;
88
90 double getZRange() const;
91
94
96 bool around(const Position& p, double offset = 0) const;
97
99 bool around2D(const Position& p, double offset = 0) const;
100
102 bool around2D(const double x, const double y) const;
103
105 bool overlapsWith(const AbstractPoly& poly, double offset = 0) const;
106
108 bool partialWithin(const AbstractPoly& poly, double offset = 0) const;
109
111 bool crosses(const Position& p1, const Position& p2) const;
112
114
116 bool contains2D(const Boundary& b) const;
117
119 bool overlaps2D(const Boundary& b) const;
120
122 bool isInitialised() const;
123
125 double distanceTo2D(const Position& p) const;
126
128 double distanceTo2D(const Boundary& b) const;
129
133 Boundary& grow(double by);
134
138 Boundary& scale(double by);
139
141 void growWidth(double by);
142
144 void growHeight(double by);
145
147 void flipY();
148
150 void set(double xmin, double ymin, double xmax, double ymax);
151
153 void setOffsets(double xmin, double ymin, double xmax, double ymax);
154
156 void moveby(double x, double y, double z = 0);
157
159 PositionVector getShape(const bool closeShape) const;
160
162 friend std::ostream& operator<<(std::ostream& os, const Boundary& b);
163
165 bool operator==(const Boundary& b) const;
166
168 bool operator!=(const Boundary& b) const;
169
170private:
173
176};
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
Position getCenter() const
Returns the center of the boundary.
Definition Boundary.cpp:109
bool partialWithin(const AbstractPoly &poly, double offset=0) const
Returns whether the boundary is partially within the given polygon.
Definition Boundary.cpp:330
double myZmin
Definition Boundary.h:172
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition Boundary.cpp:75
void moveby(double x, double y, double z=0)
Moves the boundary by the given amount.
Definition Boundary.cpp:433
void growHeight(double by)
Increases the height of the boundary (y-axis)
Definition Boundary.cpp:366
bool isInitialised() const
check if Boundary is Initialised
Definition Boundary.cpp:256
double ymin() const
Returns minimum y-coordinate.
Definition Boundary.cpp:127
double myZmax
Definition Boundary.h:172
void reset()
Resets the boundary.
Definition Boundary.cpp:63
double xmin() const
Returns minimum x-coordinate.
Definition Boundary.cpp:115
Boundary & grow(double by)
extends the boundary by the given amount
Definition Boundary.cpp:340
void flipY()
flips ymin and ymax
Definition Boundary.cpp:372
double distanceTo2D(const Position &p) const
returns the euclidean distance in the x-y-plane
Definition Boundary.cpp:262
double getHeight() const
Returns the height of the boundary (y-axis)
Definition Boundary.cpp:157
bool myWasInitialised
Information whether the boundary was initialised.
Definition Boundary.h:175
bool overlapsWith(const AbstractPoly &poly, double offset=0) const
Returns whether the boundary overlaps with the given polygon.
Definition Boundary.cpp:194
Boundary()
Constructor - the boundary is unset.
Definition Boundary.cpp:35
bool contains2D(const Boundary &b) const
return true if this boundary contains the given boundary (only X-Y)
Definition Boundary.cpp:229
double getWidth() const
Returns the width of the boudary (x-axis)
Definition Boundary.cpp:151
bool operator!=(const Boundary &b) const
Comparison operator not equal.
Definition Boundary.cpp:403
PositionVector getShape(const bool closeShape) const
get position vector (shape) based on this boundary
Definition Boundary.cpp:444
double myYmin
Definition Boundary.h:172
void set(double xmin, double ymin, double xmax, double ymax)
Sets the boundary to the given values.
Definition Boundary.cpp:409
Boundary & scale(double by)
scale the boundary by the given amount
Definition Boundary.cpp:351
double zmin() const
Returns minimum z-coordinate.
Definition Boundary.cpp:139
bool around2D(const Position &p, double offset=0) const
Returns whether the boundary contains the given 2D coordinate (position)
Definition Boundary.cpp:178
void growWidth(double by)
Increases the width of the boundary (x-axis)
Definition Boundary.cpp:359
double myYmax
Definition Boundary.h:172
bool crosses(const Position &p1, const Position &p2) const
Returns whether the boundary crosses the given line.
Definition Boundary.cpp:215
bool around(const Position &p, double offset=0) const
Returns whether the boundary contains the given coordinate.
Definition Boundary.cpp:169
void setOffsets(double xmin, double ymin, double xmax, double ymax)
Sets the boundary to the given values, ignoring min < max constraints.
Definition Boundary.cpp:424
double ymax() const
Returns maximum y-coordinate.
Definition Boundary.cpp:133
double myXmin
The boundaries.
Definition Boundary.h:172
double myXmax
Definition Boundary.h:172
double xmax() const
Returns maximum x-coordinate.
Definition Boundary.cpp:121
friend std::ostream & operator<<(std::ostream &os, const Boundary &b)
Output operator.
Definition Boundary.cpp:383
double zmax() const
Returns maximum z-coordinate.
Definition Boundary.cpp:145
double getZRange() const
Returns the elevation range of the boundary (z-axis)
Definition Boundary.cpp:163
bool overlaps2D(const Boundary &b) const
return true if at least one point of the given boundary is in boundary(only X-Y)
Definition Boundary.cpp:240
bool operator==(const Boundary &b) const
Comparison operator equal.
Definition Boundary.cpp:390
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.