LCOV - code coverage report
Current view: top level - source/simulation2/helpers - PathGoal.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 1 1 100.0 %
Date: 2023-01-19 00:18:29 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* Copyright (C) 2018 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #ifndef INCLUDED_PATHGOAL
      19             : #define INCLUDED_PATHGOAL
      20             : 
      21             : #include "maths/FixedVector2D.h"
      22             : #include "simulation2/helpers/Position.h"
      23             : 
      24             : /**
      25             :  * Pathfinder goal.
      26             :  * The goal can be either a point, a circle, or a square (rectangle).
      27             :  * For circles/squares, any point inside the shape is considered to be
      28             :  * part of the goal.
      29             :  * Also, it can be an 'inverted' circle/square, where any point outside
      30             :  * the shape is part of the goal.
      31             :  */
      32          10 : class PathGoal
      33             : {
      34             : public:
      35             :     enum Type {
      36             :         POINT,           // single point
      37             :         CIRCLE,          // the area inside a circle
      38             :         INVERTED_CIRCLE, // the area outside a circle
      39             :         SQUARE,          // the area inside a square
      40             :         INVERTED_SQUARE  // the area outside a square
      41             :     } type;
      42             : 
      43             :     entity_pos_t x, z; // position of center
      44             : 
      45             :     entity_pos_t hw, hh; // if [INVERTED_]SQUARE, then half width & height; if [INVERTED_]CIRCLE, then hw is radius
      46             : 
      47             :     CFixedVector2D u, v; // if [INVERTED_]SQUARE, then orthogonal unit axes
      48             : 
      49             :     entity_pos_t maxdist; // maximum distance wanted between two path waypoints
      50             : 
      51             :     /**
      52             :      * Returns true if the given navcell contains a part of the goal area.
      53             :      */
      54             :     bool NavcellContainsGoal(int i, int j) const;
      55             : 
      56             :     /**
      57             :      * Returns true if any navcell (i, j) where
      58             :      * min(i0,i1) <= i <= max(i0,i1)
      59             :      * min(j0,j1) <= j <= max(j0,j1),
      60             :      * contains a part of the goal area.
      61             :      * If so, arguments i and j (if not NULL) are set to the goal navcell nearest
      62             :      * to (i0, j0), assuming the rect has either width or height = 1.
      63             :      */
      64             :     bool NavcellRectContainsGoal(int i0, int j0, int i1, int j1, int* i, int* j) const;
      65             : 
      66             :     /**
      67             :      * Returns true if the rectangle defined by (x0,z0)-(x1,z1) (inclusive)
      68             :      * contains a part of the goal area.
      69             :      */
      70             :     bool RectContainsGoal(entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1) const;
      71             : 
      72             :     /**
      73             :      * Returns the minimum distance from the point pos to any point on the goal shape.
      74             :      */
      75             :     fixed DistanceToPoint(CFixedVector2D pos) const;
      76             : 
      77             :     /**
      78             :      * Returns the coordinates of the point on the goal that is closest to the point pos.
      79             :      */
      80             :     CFixedVector2D NearestPointOnGoal(CFixedVector2D pos) const;
      81             : };
      82             : 
      83             : #endif // INCLUDED_PATHGOAL

Generated by: LCOV version 1.13