STriangle2.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <ionCore.h>
5 
6 
7 namespace ion
8 {
9 
12  template <typename T>
13  class STriangle2
14  {
15 
16  public:
17 
19 
21  {}
22 
23  STriangle2(vec2<T> const & v1, vec2<T> const & v2, vec2<T> const & v3)
24  {
25  Vertices[0] = v1;
26  Vertices[1] = v2;
27  Vertices[2] = v3;
28  }
29 
30  static T Sign(vec2<T> const & p1, vec2<T> const & p2, vec2<T> const & p3)
31  {
32  return (p1.X - p3.X) * (p2.Y - p3.Y) - (p2.X - p3.X) * (p1.Y - p3.Y);
33  }
34 
35  bool PointInside(vec2<T> const & pt) const
36  {
37  bool b1, b2, b3;
38 
39  b1 = Sign(pt, Vertices[0], Vertices[1]) < 0.0f;
40  b2 = Sign(pt, Vertices[1], Vertices[2]) < 0.0f;
41  b3 = Sign(pt, Vertices[2], Vertices[0]) < 0.0f;
42 
43  return ((b1 == b2) && (b2 == b3));
44  }
45 
46  };
47 
52 
53  typedef STriangle2f tri2f;
54  typedef STriangle2d tri2d;
55  typedef STriangle2i tri2i;
56  typedef STriangle2u tri2u;
57 
58 }
2D vector
Definition: vec2.h:17
STriangle2< float > STriangle2f
Definition: STriangle2.h:48
STriangle2d tri2d
Definition: STriangle2.h:54
bool PointInside(vec2< T > const &pt) const
Definition: STriangle2.h:35
STriangle2(vec2< T > const &v1, vec2< T > const &v2, vec2< T > const &v3)
Definition: STriangle2.h:23
STriangle2< int > STriangle2i
Definition: STriangle2.h:50
STriangle2< ion::uint > STriangle2u
Definition: STriangle2.h:51
STriangle2< double > STriangle2d
Definition: STriangle2.h:49
2D triangle
Definition: STriangle2.h:13
static T Sign(vec2< T > const &p1, vec2< T > const &p2, vec2< T > const &p3)
Definition: STriangle2.h:30
T X
Definition: vec2.h:20
STriangle2()
Definition: STriangle2.h:20
STriangle2u tri2u
Definition: STriangle2.h:56
Definition: CCatmullRomAdvancedSplineInterpolator.h:7
STriangle2i tri2i
Definition: STriangle2.h:55
vec2< T > Vertices[3]
Definition: STriangle2.h:18
T Y
Definition: vec2.h:21
STriangle2f tri2f
Definition: STriangle2.h:53