gwnavruntime/math/integersegmentutils.h Source File

integersegmentutils.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 
8 // primary contact: LASI - secondary contact: NOBODY
9 #ifndef Navigation_IntegerSegmentUtils_H
10 #define Navigation_IntegerSegmentUtils_H
11 
13 
14 
15 namespace Kaim
16 {
17 
18 // Order cuts depending on their distance from edge start
19 class CutSorter
20 {
21 public:
22  CutSorter(const Vec2i& edgeStart) : m_edgeStart(edgeStart) {}
23  bool operator() (const Vec2i& cut1, const Vec2i& cut2) const
24  {
25  return (cut1 - m_edgeStart).GetSquareLength() > (cut2 - m_edgeStart).GetSquareLength();
26  }
27 
28 public:
29  Vec2i m_edgeStart;
30 };
31 
32 namespace IntegerSegment
33 {
34  static KyInt32 RoundedDivide(KyInt64 num, KyInt64 denum);
35 
36  // Generic template functions
37  // returns true iff pt coordinate is between start and end
38  template <typename T> //T E { Vec{2,3}i, Vec2LL }
39  static bool Between(const T& pt, const T& edgeStart, const T& edgeEnd);
40 
41  // returns true if [ edgeStart, edgeEnd ] is vertical
42  template <typename T> //T E { Vec{2,3}i, Vec2LL }
43  static bool IsVertical(const T& edgeStart, const T& edgeEnd);
44 
45  // returns true if [ edgeStart, edgeEnd ] is horizontal
46  template <typename T> //T E { Vec{2,3}i, Vec2LL }
47  static bool IsHorizontal(const T& edgeStart, const T& edgeEnd);
48 
49  // returns true if edge1 with derivative (dx1, dy1) has a slope inferior to edge2 (dx2, dy2)
50  template <typename T> //T E { Int32/64 }
51  static bool LessSlopeUnit(T dx1, T dy1, T dx2, T dy2);
52 
53  template <typename T> //T E { Vec{2,3}i, Vec2LL }
54  static bool LessSlope(const Vec2i& a, const Vec2i& b, const Vec2i& c);
55 
56  template <typename T> //T E { KyInt32, KyInt64 }
57  static bool ArePointsAligned(const Vec2i& a, const Vec2i& b, const Vec2i& c);
58 
59 
60  //return -1 below, 0 on and 1 above line
61  template <typename T>
62  static KyInt32 OnAboveOrBelow(const Vec2i& pt, const Vec2i& edgeStart, const Vec2i& edgeEnd);
63 
64  // NB1: When relevant, the intersection point is snapped to the lower left corner of the pixel where the
65  // "Real" (precise) intersection occurs. This is not a simple integer conversion by truncation.
66  bool SegmentVsSegment2d_hp(const Vec2i& a, const Vec2i& b, const Vec2i& c, const Vec2i& d, Vec2i& intersection);
67 
68  bool SegmentVsSegment2d_rounded(const Vec2i& a, const Vec2i& b, const Vec2i& c, const Vec2i& d, Vec2i& intersection);
69  bool SegmentVsSegment2dWithBoxes_rounded(const Vec2i& a, const Vec2i& b, const Vec2i& c, const Vec2i& d, const Box2i& boxAB, const Box2i& boxCD, Vec2i& intersection);
70 
71  template <typename T>
72  bool SegmentVsSegment2d(const T& a, const T& b, const T& c, const T& d);
73 
74  bool EvalPosAtZ(const Vec2i& a, const Vec2i& b, KyFloat32 altA, KyFloat32 altB, KyFloat32 targetAlt, Vec2i& pos);
75 } // namespace IntegerSegment
76 
77 } //namespace Kaim
78 
79 
81 
82 
83 #endif // Navigation_IntegerSegmentUtils_H
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
Definition: gamekitcrowddispersion.h:20
__int64 KyInt64
Type used internally to represent a 64-bit integer.
Definition: types.h:37
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43