Eclipse SUMO - Simulation of Urban MObility
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 // ===========================================================================
39 class Boundary : public AbstractPoly {
40 public:
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 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  double contains(const Boundary& b) const;
117 
119  bool isInitialised() const;
120 
122  double distanceTo2D(const Position& p) const;
123 
125  double distanceTo2D(const Boundary& b) const;
126 
130  Boundary& grow(double by);
131 
135  Boundary& scale(double by);
136 
138  void growWidth(double by);
139 
141  void growHeight(double by);
142 
144  void flipY();
145 
147  void set(double xmin, double ymin, double xmax, double ymax);
148 
150  void setOffsets(double xmin, double ymin, double xmax, double ymax);
151 
153  void moveby(double x, double y, double z = 0);
154 
156  PositionVector getShape(const bool closeShape) const;
157 
159  friend std::ostream& operator<<(std::ostream& os, const Boundary& b);
160 
162  bool operator==(const Boundary& b) const;
163 
165  bool operator!=(const Boundary& b) const;
166 
167 private:
170 
173 };
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:309
double myZmin
Definition: Boundary.h:169
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:412
void growHeight(double by)
Increases the height of the boundary (y-axis)
Definition: Boundary.cpp:345
bool isInitialised() const
check if Boundary is Initialised
Definition: Boundary.cpp:235
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:130
double myZmax
Definition: Boundary.h:169
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:319
void flipY()
flips ymin and ymax
Definition: Boundary.cpp:351
double distanceTo2D(const Position &p) const
returns the euclidean distance in the x-y-plane
Definition: Boundary.cpp:241
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:172
bool overlapsWith(const AbstractPoly &poly, double offset=0) const
Returns whether the boundary overlaps with the given polygon.
Definition: Boundary.cpp:189
Boundary()
Constructor - the boundary is unset.
Definition: Boundary.cpp:35
~Boundary()
Destructor.
Definition: Boundary.cpp:62
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:382
PositionVector getShape(const bool closeShape) const
get position vector (shape) based on this boundary
Definition: Boundary.cpp:423
double myYmin
Definition: Boundary.h:169
void set(double xmin, double ymin, double xmax, double ymax)
Sets the boundary to the given values.
Definition: Boundary.cpp:388
Boundary & scale(double by)
scale the boundary by the given amount
Definition: Boundary.cpp:330
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.
Definition: Boundary.cpp:181
void growWidth(double by)
Increases the width of the boundary (x-axis)
Definition: Boundary.cpp:338
double myYmax
Definition: Boundary.h:169
bool crosses(const Position &p1, const Position &p2) const
Returns whether the boundary crosses the given line.
Definition: Boundary.cpp:210
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:403
double contains(const Boundary &b) const
return true if this boundary contains the given boundary (only X-Y)
Definition: Boundary.cpp:224
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:136
double myXmin
The boundaries.
Definition: Boundary.h:169
double myXmax
Definition: Boundary.h:169
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:124
double zmax() const
Returns maximum z-coordinate.
Definition: Boundary.cpp:148
friend std::ostream & operator<<(std::ostream &os, const Boundary &b)
Output operator.
Definition: Boundary.cpp:362
double getZRange() const
Returns the elevation range of the boundary (z-axis)
Definition: Boundary.cpp:166
bool operator==(const Boundary &b) const
Comparison operator equal.
Definition: Boundary.cpp:369
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
A list of positions.