Line2D.h 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: Line2D.h /////////////////////////////////////////////////////////////////////////////////
  24. // Author: Colin Day, January 2002
  25. // Desc: 2D line helping stuff
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #pragma once
  28. #ifndef __LINE2D_H_
  29. #define __LINE2D_H_
  30. typedef std::vector<ICoord2D> Coord2DVector;
  31. typedef std::vector<ICoord3D> Coord3DVector;
  32. // PROTOTYPES /////////////////////////////////////////////////////////////////////////////////////
  33. extern Bool ClipLine2D( ICoord2D *p1, ICoord2D *p2, ICoord2D *c1, ICoord2D *c2,
  34. IRegion2D *clipRegion );
  35. ///< IntersectLine2D will take two segments delimited by ab and cd and will return whether
  36. ///< they intersect within the length of ab. They will also return the intersection point out
  37. ///< intersection if it is non-NULL.
  38. extern Bool IntersectLine2D( const Coord2D *a, const Coord2D *b,
  39. const Coord2D *c, const Coord2D *d,
  40. Coord2D *intersection = NULL);
  41. ///< PointInsideRect2D will return true iff inputPoint lies iside of the rectangle specified
  42. ///< by bl, tl, br, tr.
  43. extern Bool PointInsideRect2D( const Coord2D *bl, const Coord2D *tl,
  44. const Coord2D *br, const Coord2D *tr,
  45. const Coord2D *inputPoint);
  46. ///< Checks if a point is inside a perfect rectangle (top left and bottom right)
  47. extern Bool Coord3DInsideRect2D( const Coord3D *inputPoint, const Coord2D *tl, const Coord2D *br );
  48. ///< Scales a rect by a factor either growing or shrinking it.
  49. extern void ScaleRect2D( Coord2D *tl, Coord2D *br, Real scaleFactor );
  50. /** PointInsideRect3D will return true iff inputPoint lies iside of the rectangle specified
  51. by bl, tl, br, tr. It does not actually consider the Z value, it is merely a convenience function
  52. for calling PointInsideRect2D */
  53. extern Bool PointInsideRect3D( const Coord3D *bl, const Coord3D *tl,
  54. const Coord3D *br, const Coord3D *tr,
  55. const Coord3D *inputPoint);
  56. ///< This function will take the ptToTest and will perform even-odd checking against the area.
  57. ///< If the area is not closed, it will be closed for this check.
  58. extern Bool PointInsideArea2D( const Coord2D *ptToTest,
  59. const Coord2D *area,
  60. Int numPointsInArea);
  61. ///< This function will take the ptToTest and will perform even-odd checking against the area.
  62. ///< The area and the ptToTest will be flattened first, so a 2-D check will be sufficient.
  63. ///< This function is only for convenience so that points do not need to first be flattened.
  64. extern Bool PointInsideArea2D( const Coord3D *ptToTest,
  65. const Coord3D *area,
  66. Int numPointsInArea);
  67. ///< This function will find the shortest distance between the given segment (ab) and the pt.
  68. ///< It will also give the intersection points on the segment (ab) if desired.
  69. ///< outU will return the U value determined. This is a shortcut for panning
  70. extern void ShortestDistancePointToSegment2D( const Coord2D *a, const Coord2D *b, const Coord2D *pt,
  71. Real *outDistance, Coord2D *outPosition, Real *outU );
  72. #endif // __LINE2D_H_