LCOV - code coverage report
Current view: top level - src/utils/geom - Boundary.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 1 1
Test Date: 2024-11-22 15:46:21 Functions: - 0 0

            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      6460498 : 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 (position)
     102              :     bool around2D(const Position& p, double offset = 0) const;
     103              : 
     104              :     /// @brief Returns whether the boundary contains the given 2D coordinate (x-y version)
     105              :     bool around2D(const double x, const double y) const;
     106              : 
     107              :     /// @brief Returns whether the boundary overlaps with the given polygon
     108              :     bool overlapsWith(const AbstractPoly& poly, double offset = 0) const;
     109              : 
     110              :     /// @brief Returns whether the boundary is partially within the given polygon
     111              :     bool partialWithin(const AbstractPoly& poly, double offset = 0) const;
     112              : 
     113              :     /// @brief Returns whether the boundary crosses the given line
     114              :     bool crosses(const Position& p1, const Position& p2) const;
     115              : 
     116              :     /// @}
     117              : 
     118              :     /// @brief return true if this boundary contains the given boundary (only X-Y)
     119              :     bool contains2D(const Boundary& b) const;
     120              : 
     121              :     /// @brief return true if at least one point of the given boundary is in boundary(only X-Y)
     122              :     bool overlaps2D(const Boundary& b) const;
     123              : 
     124              :     /// @brief check if Boundary is Initialised
     125              :     bool isInitialised() const;
     126              : 
     127              :     /// @brief returns the euclidean distance in the x-y-plane
     128              :     double distanceTo2D(const Position& p) const;
     129              : 
     130              :     /// @brief returns the euclidean distance in the x-y-plane
     131              :     double distanceTo2D(const Boundary& b) const;
     132              : 
     133              :     /**@brief extends the boundary by the given amount
     134              :      * @return a reference to the instance for further use
     135              :      */
     136              :     Boundary& grow(double by);
     137              : 
     138              :     /**@brief scale the boundary by the given amount
     139              :      * @return a reference to the instance for further use
     140              :      */
     141              :     Boundary& scale(double by);
     142              : 
     143              :     /// @brief Increases the width of the boundary (x-axis)
     144              :     void growWidth(double by);
     145              : 
     146              :     /// @brief Increases the height of the boundary (y-axis)
     147              :     void growHeight(double by);
     148              : 
     149              :     /// @brief flips ymin and ymax
     150              :     void flipY();
     151              : 
     152              :     /// @brief Sets the boundary to the given values
     153              :     void set(double xmin, double ymin, double xmax, double ymax);
     154              : 
     155              :     /// @brief Sets the boundary to the given values, ignoring min < max constraints
     156              :     void setOffsets(double xmin, double ymin, double xmax, double ymax);
     157              : 
     158              :     /// @brief Moves the boundary by the given amount
     159              :     void moveby(double x, double y, double z = 0);
     160              : 
     161              :     /// @brief get position vector (shape) based on this boundary
     162              :     PositionVector getShape(const bool closeShape) const;
     163              : 
     164              :     /// @brief Output operator
     165              :     friend std::ostream& operator<<(std::ostream& os, const Boundary& b);
     166              : 
     167              :     /// @brief Comparison operator equal
     168              :     bool operator==(const Boundary& b) const;
     169              : 
     170              :     /// @brief Comparison operator not equal
     171              :     bool operator!=(const Boundary& b) const;
     172              : 
     173              : private:
     174              :     /// @brief The boundaries
     175              :     double myXmin, myXmax, myYmin, myYmax, myZmin, myZmax;
     176              : 
     177              :     /// @brief Information whether the boundary was initialised
     178              :     bool myWasInitialised;
     179              : };
        

Generated by: LCOV version 2.0-1