Line data Source code
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 : /****************************************************************************/ 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 5853161 : 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 Destructor 51 : ~Boundary(); 52 : 53 : /// @brief Resets the boundary 54 : void reset(); 55 : 56 : /// @brief Makes the boundary include the given coordinate 57 : void add(double x, double y, double z = 0); 58 : 59 : /// @brief Makes the boundary include the given coordinate 60 : void add(const Position& p); 61 : 62 : /// @brief Makes the boundary include the given boundary 63 : void add(const Boundary& p); 64 : 65 : /// @brief Returns the center of the boundary 66 : Position getCenter() const; 67 : 68 : /// @brief Returns minimum x-coordinate 69 : double xmin() const; 70 : 71 : /// @brief Returns maximum x-coordinate 72 : double xmax() const; 73 : 74 : /// @brief Returns minimum y-coordinate 75 : double ymin() const; 76 : 77 : /// @brief Returns maximum y-coordinate 78 : double ymax() const; 79 : 80 : /// @brief Returns minimum z-coordinate 81 : double zmin() const; 82 : 83 : /// @brief Returns maximum z-coordinate 84 : double zmax() const; 85 : 86 : /// @brief Returns the width of the boudary (x-axis) 87 : double getWidth() const; 88 : 89 : /// @brief Returns the height of the boundary (y-axis) 90 : double getHeight() const; 91 : 92 : /// @brief Returns the elevation range of the boundary (z-axis) 93 : double getZRange() const; 94 : 95 : /// @name inherited from AbstractPoly 96 : /// @{ 97 : 98 : /// @brief Returns whether the boundary contains the given coordinate 99 : bool around(const Position& p, double offset = 0) const; 100 : 101 : /// @brief Returns whether the boundary contains the given 2D coordinate 102 : bool around2D(const Position& p, double offset = 0) 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 : double contains(const Boundary& b) const; 117 : 118 : /// @brief check if Boundary is Initialised 119 : bool isInitialised() const; 120 : 121 : /// @brief returns the euclidean distance in the x-y-plane 122 : double distanceTo2D(const Position& p) const; 123 : 124 : /// @brief returns the euclidean distance in the x-y-plane 125 : double distanceTo2D(const Boundary& b) const; 126 : 127 : /**@brief extends the boundary by the given amount 128 : * @return a reference to the instance for further use 129 : */ 130 : Boundary& grow(double by); 131 : 132 : /**@brief scale the boundary by the given amount 133 : * @return a reference to the instance for further use 134 : */ 135 : Boundary& scale(double by); 136 : 137 : /// @brief Increases the width of the boundary (x-axis) 138 : void growWidth(double by); 139 : 140 : /// @brief Increases the height of the boundary (y-axis) 141 : void growHeight(double by); 142 : 143 : /// @brief flips ymin and ymax 144 : void flipY(); 145 : 146 : /// @brief Sets the boundary to the given values 147 : void set(double xmin, double ymin, double xmax, double ymax); 148 : 149 : /// @brief Sets the boundary to the given values, ignoring min < max constraints 150 : void setOffsets(double xmin, double ymin, double xmax, double ymax); 151 : 152 : /// @brief Moves the boundary by the given amount 153 : void moveby(double x, double y, double z = 0); 154 : 155 : /// @brief get position vector (shape) based on this boundary 156 : PositionVector getShape(const bool closeShape) const; 157 : 158 : /// @brief Output operator 159 : friend std::ostream& operator<<(std::ostream& os, const Boundary& b); 160 : 161 : /// @brief Comparison operator equal 162 : bool operator==(const Boundary& b) const; 163 : 164 : /// @brief Comparison operator not equal 165 : bool operator!=(const Boundary& b) const; 166 : 167 : private: 168 : /// @brief The boundaries 169 : double myXmin, myXmax, myYmin, myYmax, myZmin, myZmax; 170 : 171 : /// @brief Information whether the boundary was initialised 172 : bool myWasInitialised; 173 : };