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-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/****************************************************************************/
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 ~Boundary();
52
54 void reset();
55
57 void add(double x, double y, double z = 0);
58
60 void add(const Position& p);
61
63 void add(const Boundary& p);
64
66 Position getCenter() const;
67
69 double xmin() const;
70
72 double xmax() const;
73
75 double ymin() const;
76
78 double ymax() const;
79
81 double zmin() const;
82
84 double zmax() const;
85
87 double getWidth() const;
88
90 double getHeight() const;
91
93 double getZRange() const;
94
97
99 bool around(const Position& p, double offset = 0) const;
100
102 bool around2D(const Position& p, double offset = 0) const;
103
105 bool around2D(const double x, const double y) const;
106
108 bool overlapsWith(const AbstractPoly& poly, double offset = 0) const;
109
111 bool partialWithin(const AbstractPoly& poly, double offset = 0) const;
112
114 bool crosses(const Position& p1, const Position& p2) const;
115
117
119 bool contains2D(const Boundary& b) const;
120
122 bool overlaps2D(const Boundary& b) const;
123
125 bool isInitialised() const;
126
128 double distanceTo2D(const Position& p) const;
129
131 double distanceTo2D(const Boundary& b) const;
132
136 Boundary& grow(double by);
137
141 Boundary& scale(double by);
142
144 void growWidth(double by);
145
147 void growHeight(double by);
148
150 void flipY();
151
153 void set(double xmin, double ymin, double xmax, double ymax);
154
156 void setOffsets(double xmin, double ymin, double xmax, double ymax);
157
159 void moveby(double x, double y, double z = 0);
160
162 PositionVector getShape(const bool closeShape) const;
163
165 friend std::ostream& operator<<(std::ostream& os, const Boundary& b);
166
168 bool operator==(const Boundary& b) const;
169
171 bool operator!=(const Boundary& b) const;
172
173private:
176
179};
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
Position getCenter() const
Returns the center of the boundary.
Definition Boundary.cpp:112
bool partialWithin(const AbstractPoly &poly, double offset=0) const
Returns whether the boundary is partially within the given polygon.
Definition Boundary.cpp:333
double myZmin
Definition Boundary.h:175
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition Boundary.cpp:78
void moveby(double x, double y, double z=0)
Moves the boundary by the given amount.
Definition Boundary.cpp:436
void growHeight(double by)
Increases the height of the boundary (y-axis)
Definition Boundary.cpp:369
bool isInitialised() const
check if Boundary is Initialised
Definition Boundary.cpp:259
double ymin() const
Returns minimum y-coordinate.
Definition Boundary.cpp:130
double myZmax
Definition Boundary.h:175
void reset()
Resets the boundary.
Definition Boundary.cpp:66
double xmin() const
Returns minimum x-coordinate.
Definition Boundary.cpp:118
Boundary & grow(double by)
extends the boundary by the given amount
Definition Boundary.cpp:343
void flipY()
flips ymin and ymax
Definition Boundary.cpp:375
double distanceTo2D(const Position &p) const
returns the euclidean distance in the x-y-plane
Definition Boundary.cpp:265
double getHeight() const
Returns the height of the boundary (y-axis)
Definition Boundary.cpp:160
bool myWasInitialised
Information whether the boundary was initialised.
Definition Boundary.h:178
bool overlapsWith(const AbstractPoly &poly, double offset=0) const
Returns whether the boundary overlaps with the given polygon.
Definition Boundary.cpp:197
Boundary()
Constructor - the boundary is unset.
Definition Boundary.cpp:35
~Boundary()
Destructor.
Definition Boundary.cpp:62
bool contains2D(const Boundary &b) const
return true if this boundary contains the given boundary (only X-Y)
Definition Boundary.cpp:232
double getWidth() const
Returns the width of the boudary (x-axis)
Definition Boundary.cpp:154
bool operator!=(const Boundary &b) const
Comparison operator not equal.
Definition Boundary.cpp:406
PositionVector getShape(const bool closeShape) const
get position vector (shape) based on this boundary
Definition Boundary.cpp:447
double myYmin
Definition Boundary.h:175
void set(double xmin, double ymin, double xmax, double ymax)
Sets the boundary to the given values.
Definition Boundary.cpp:412
Boundary & scale(double by)
scale the boundary by the given amount
Definition Boundary.cpp:354
double zmin() const
Returns minimum z-coordinate.
Definition Boundary.cpp:142
bool around2D(const Position &p, double offset=0) const
Returns whether the boundary contains the given 2D coordinate (position)
Definition Boundary.cpp:181
void growWidth(double by)
Increases the width of the boundary (x-axis)
Definition Boundary.cpp:362
double myYmax
Definition Boundary.h:175
bool crosses(const Position &p1, const Position &p2) const
Returns whether the boundary crosses the given line.
Definition Boundary.cpp:218
bool around(const Position &p, double offset=0) const
Returns whether the boundary contains the given coordinate.
Definition Boundary.cpp:172
void setOffsets(double xmin, double ymin, double xmax, double ymax)
Sets the boundary to the given values, ignoring min < max constraints.
Definition Boundary.cpp:427
double ymax() const
Returns maximum y-coordinate.
Definition Boundary.cpp:136
double myXmin
The boundaries.
Definition Boundary.h:175
double myXmax
Definition Boundary.h:175
double xmax() const
Returns maximum x-coordinate.
Definition Boundary.cpp:124
friend std::ostream & operator<<(std::ostream &os, const Boundary &b)
Output operator.
Definition Boundary.cpp:386
double zmax() const
Returns maximum z-coordinate.
Definition Boundary.cpp:148
double getZRange() const
Returns the elevation range of the boundary (z-axis)
Definition Boundary.cpp:166
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:243
bool operator==(const Boundary &b) const
Comparison operator equal.
Definition Boundary.cpp:393
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.