LCOV - code coverage report
Current view: top level - src/utils/geom - Triangle.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 0.0 % 1 0
Test Date: 2025-12-06 15:35:27 Functions: - 0 0

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2025 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    Triangle.h
      15              : /// @author  Pablo Alvarez Lopez
      16              : /// @date    Jan 2025
      17              : ///
      18              : // A simple triangle defined in 3D
      19              : /****************************************************************************/
      20              : #pragma once
      21              : #include <config.h>
      22              : 
      23              : #include <vector>
      24              : 
      25              : #include "PositionVector.h"
      26              : #include "Boundary.h"
      27              : 
      28              : // ===========================================================================
      29              : // class definitions
      30              : // ===========================================================================
      31              : /**
      32              :  * @class Triangle
      33              :  * @brief A simple triangle defined in 3D
      34              :  */
      35            0 : class Triangle {
      36              : 
      37              : public:
      38              :     /// @brief invalid triangle
      39              :     static const Triangle INVALID;
      40              : 
      41              :     /// @brief default constructor
      42              :     Triangle();
      43              : 
      44              :     /// @brief parameter constructor
      45              :     Triangle(const Position& positionA, const Position& positionB, const Position& positionC);
      46              : 
      47              :     /// @brief destructor
      48              :     ~Triangle();
      49              : 
      50              :     /// @brief get triangle boundary
      51              :     const Boundary& getBoundary() const;
      52              : 
      53              :     /// @brief get shape boundary
      54              :     const PositionVector getShape() const;
      55              : 
      56              :     /// @brief check if the given position is within this triangle
      57              :     bool isPositionWithin(const Position& pos) const;
      58              : 
      59              :     /// @brief check if the given position is FULL within this triangle
      60              :     bool isBoundaryFullWithin(const Boundary& boundary) const;
      61              : 
      62              :     /// @brief check if the given shape is within or intersect with this triangle
      63              :     bool intersectWithShape(const PositionVector& shape) const;
      64              : 
      65              :     /// @brief check if the given shape is within or intersect with this triangle
      66              :     bool intersectWithShape(const PositionVector& shape, const Boundary& shapeBoundary) const;
      67              : 
      68              :     /// @brief check if the given circle intersect with this triangle
      69              :     bool intersectWithCircle(const Position& center, const double radius) const;
      70              : 
      71              :     // @brief triangulate using Ear Clipping algorithm
      72              :     static std::vector<Triangle> triangulate(PositionVector shape);
      73              : 
      74              :     /// @brief equalityoperators
      75              :     bool operator==(const Triangle& other) const;
      76              : 
      77              :     /// @brief inequality operator
      78              :     bool operator!=(const Triangle& other) const;
      79              : 
      80              : private:
      81              :     /// @name functions used for triangulation
      82              :     /// @{
      83              :     /// @brief check if the given position is within this triangle
      84              :     static bool isPositionWithin(const Position& A, const Position& B, const Position& C, const Position& pos);
      85              : 
      86              :     /// @brief Check if the triangle (A, B, C) is an ear
      87              :     static bool isEar(const Position& a, const Position& b, const Position& c, const PositionVector& shape);
      88              : 
      89              :     /// @brief calculate cross product of the given points
      90              :     static double crossProduct(const Position& a, const Position& b, const Position& c);
      91              : 
      92              :     /// @}
      93              : 
      94              :     /// @name functions used for check if a shape intersect with the triangle
      95              :     /// @{
      96              :     /// @brief Compute the orientation of ordered triplet (p, q, r)
      97              :     int orientation(const Position& p, const Position& q, const Position& r) const;
      98              : 
      99              :     /// @brief check if point q lies on segment pr
     100              :     bool onSegment(const Position& p, const Position& q, const Position& r) const;
     101              : 
     102              :     /// @brief check if two line segments (p1,q1) and (p2,q2) intersect
     103              :     bool segmentsIntersect(const Position& p1, const Position& q1, const Position& p2, const Position& q2) const;
     104              : 
     105              :     /// @brief check if a line segment (p1, p2) intersects this triangle
     106              :     bool lineIntersectsTriangle(const Position& p1, const Position& p2) const;
     107              : 
     108              :     /// @}
     109              : 
     110              :     /// @brief function to check if line between posA and posB intersect circle
     111              :     bool lineIntersectCircle(const Position& posA, const Position& posB, const Position& center, const double radius) const;
     112              : 
     113              :     /// @brief first triangle position
     114              :     Position myA = Position::INVALID;
     115              : 
     116              :     /// @brief second triangle position
     117              :     Position myB = Position::INVALID;
     118              : 
     119              :     /// @brief third triangle position
     120              :     Position myC = Position::INVALID;
     121              : 
     122              :     /// @brief triangle boundary
     123              :     Boundary myBoundary;
     124              : };
        

Generated by: LCOV version 2.0-1