/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file Boundary.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @date Sept 200218///19// A class that stores a 2D geometrical boundary20/****************************************************************************/21#pragma once22#include <config.h>2324#include <iostream>25#include <utility>2627#include "AbstractPoly.h"28#include "PositionVector.h"293031// ===========================================================================32// class definitions33// ===========================================================================34/**35* @class Boundary36* @brief A class that stores a 2D geometrical boundary37*/38class Boundary : public AbstractPoly {39public:40/// @brief Constructor - the boundary is unset41Boundary();4243/// @brief Constructor - the boundary will be build using the given values44Boundary(double x1, double y1, double x2, double y2);4546/// @brief Constructor - the boundary will be build using the given values including Z47Boundary(double x1, double y1, double z1, double x2, double y2, double z2);4849/// @brief Resets the boundary50void reset();5152/// @brief Makes the boundary include the given coordinate53void add(double x, double y, double z = 0);5455/// @brief Makes the boundary include the given coordinate56void add(const Position& p);5758/// @brief Makes the boundary include the given boundary59void add(const Boundary& p);6061/// @brief Returns the center of the boundary62Position getCenter() const;6364/// @brief Returns minimum x-coordinate65double xmin() const;6667/// @brief Returns maximum x-coordinate68double xmax() const;6970/// @brief Returns minimum y-coordinate71double ymin() const;7273/// @brief Returns maximum y-coordinate74double ymax() const;7576/// @brief Returns minimum z-coordinate77double zmin() const;7879/// @brief Returns maximum z-coordinate80double zmax() const;8182/// @brief Returns the width of the boudary (x-axis)83double getWidth() const;8485/// @brief Returns the height of the boundary (y-axis)86double getHeight() const;8788/// @brief Returns the elevation range of the boundary (z-axis)89double getZRange() const;9091/// @name inherited from AbstractPoly92/// @{9394/// @brief Returns whether the boundary contains the given coordinate95bool around(const Position& p, double offset = 0) const;9697/// @brief Returns whether the boundary contains the given 2D coordinate (position)98bool around2D(const Position& p, double offset = 0) const;99100/// @brief Returns whether the boundary contains the given 2D coordinate (x-y version)101bool around2D(const double x, const double y) const;102103/// @brief Returns whether the boundary overlaps with the given polygon104bool overlapsWith(const AbstractPoly& poly, double offset = 0) const;105106/// @brief Returns whether the boundary is partially within the given polygon107bool partialWithin(const AbstractPoly& poly, double offset = 0) const;108109/// @brief Returns whether the boundary crosses the given line110bool crosses(const Position& p1, const Position& p2) const;111112/// @}113114/// @brief return true if this boundary contains the given boundary (only X-Y)115bool contains2D(const Boundary& b) const;116117/// @brief return true if at least one point of the given boundary is in boundary(only X-Y)118bool overlaps2D(const Boundary& b) const;119120/// @brief check if Boundary is Initialised121bool isInitialised() const;122123/// @brief returns the euclidean distance in the x-y-plane124double distanceTo2D(const Position& p) const;125126/// @brief returns the euclidean distance in the x-y-plane127double distanceTo2D(const Boundary& b) const;128129/**@brief extends the boundary by the given amount130* @return a reference to the instance for further use131*/132Boundary& grow(double by);133134/**@brief scale the boundary by the given amount135* @return a reference to the instance for further use136*/137Boundary& scale(double by);138139/// @brief Increases the width of the boundary (x-axis)140void growWidth(double by);141142/// @brief Increases the height of the boundary (y-axis)143void growHeight(double by);144145/// @brief flips ymin and ymax146void flipY();147148/// @brief Sets the boundary to the given values149void set(double xmin, double ymin, double xmax, double ymax);150151/// @brief Sets the boundary to the given values, ignoring min < max constraints152void setOffsets(double xmin, double ymin, double xmax, double ymax);153154/// @brief Moves the boundary by the given amount155void moveby(double x, double y, double z = 0);156157/// @brief get position vector (shape) based on this boundary158PositionVector getShape(const bool closeShape) const;159160/// @brief Output operator161friend std::ostream& operator<<(std::ostream& os, const Boundary& b);162163/// @brief Comparison operator equal164bool operator==(const Boundary& b) const;165166/// @brief Comparison operator not equal167bool operator!=(const Boundary& b) const;168169private:170/// @brief The boundaries171double myXmin, myXmax, myYmin, myYmax, myZmin, myZmax;172173/// @brief Information whether the boundary was initialised174bool myWasInitialised;175};176177178