KiCad PCB EDA Suite
CTRIANGLE2D Class Reference

#include <ctriangle2d.h>

Inheritance diagram for CTRIANGLE2D:
COBJECT2D

Public Member Functions

 CTRIANGLE2D (const SFVEC2F &aV1, const SFVEC2F &aV2, const SFVEC2F &aV3, const BOARD_ITEM &aBoardItem)
 
const SFVEC2FGetP1 () const
 
const SFVEC2FGetP2 () const
 
const SFVEC2FGetP3 () const
 
bool Overlaps (const CBBOX2D &aBBox) const override
 Function Overlaps. More...
 
bool Intersects (const CBBOX2D &aBBox) const override
 Function Intersects. More...
 
bool Intersect (const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut) const override
 Function Intersect. More...
 
INTERSECTION_RESULT IsBBoxInside (const CBBOX2D &aBBox) const override
 Function IsBBoxInside. More...
 
bool IsPointInside (const SFVEC2F &aPoint) const override
 
const BOARD_ITEMGetBoardItem () const
 
const CBBOX2DGetBBox () const
 
const SFVEC2FGetCentroid () const
 
OBJECT2D_TYPE GetObjectType () const
 

Protected Attributes

CBBOX2D m_bbox
 
SFVEC2F m_centroid
 
OBJECT2D_TYPE m_obj_type
 
const BOARD_ITEMm_boardItem
 

Private Attributes

SFVEC2F p1
 
SFVEC2F p2
 
SFVEC2F p3
 
float m_inv_denominator
 
float m_p2y_minus_p3y
 
float m_p3x_minus_p2x
 
float m_p3y_minus_p1y
 
float m_p1x_minus_p3x
 

Detailed Description

Definition at line 39 of file ctriangle2d.h.

Constructor & Destructor Documentation

CTRIANGLE2D::CTRIANGLE2D ( const SFVEC2F aV1,
const SFVEC2F aV2,
const SFVEC2F aV3,
const BOARD_ITEM aBoardItem 
)

Definition at line 43 of file ctriangle2d.cpp.

References CBBOX2D::GetCenter(), CBBOX2D::IsInitialized(), COBJECT2D::m_bbox, COBJECT2D::m_centroid, m_inv_denominator, m_p1x_minus_p3x, m_p2y_minus_p3y, m_p3x_minus_p2x, m_p3y_minus_p1y, p1, p2, p3, CBBOX2D::Reset(), CBBOX2D::ScaleNextUp(), and CBBOX2D::Union().

47  aBoardItem )
48 {
49  p1 = aV1;
50  p2 = aV2;
51  p3 = aV3;
52 
53  // Pre-Calc values
54  m_inv_denominator = 1.0f / ( (p2.y - p3.y) * (p1.x - p3.x) +
55  (p3.x - p2.x) * (p1.y - p3.y));
56  m_p2y_minus_p3y = (p2.y - p3.y);
57  m_p3x_minus_p2x = (p3.x - p2.x);
58  m_p3y_minus_p1y = (p3.y - p1.y);
59  m_p1x_minus_p3x = (p1.x - p3.x);
60 
61  m_bbox.Reset();
62  m_bbox.Union( aV1 );
63  m_bbox.Union( aV2 );
64  m_bbox.Union( aV3 );
67 
68  wxASSERT( m_bbox.IsInitialized() );
69 }
bool IsInitialized() const
Function IsInitialized check if this bounding box is already initialized.
Definition: cbbox2d.cpp:79
void Union(const SFVEC2F &aPoint)
Function Union recalculate the bounding box adding a point.
Definition: cbbox2d.cpp:95
SFVEC2F p1
Definition: ctriangle2d.h:42
float m_p3x_minus_p2x
Definition: ctriangle2d.h:48
float m_p3y_minus_p1y
Definition: ctriangle2d.h:49
void Reset()
Function Reset reset the bounding box to zero and de-initialized it.
Definition: cbbox2d.cpp:88
COBJECT2D(OBJECT2D_TYPE aObjType, const BOARD_ITEM &aBoardItem)
Definition: cobject2d.cpp:37
float m_p1x_minus_p3x
Definition: ctriangle2d.h:50
float m_inv_denominator
Definition: ctriangle2d.h:46
void ScaleNextUp()
Function ScaleNextUp scales a bounding box to the next float representation making it larger...
Definition: cbbox2d.cpp:164
CBBOX2D m_bbox
Definition: cobject2d.h:65
SFVEC2F GetCenter() const
Function GetCenter return the center point of the bounding box.
Definition: cbbox2d.cpp:121
SFVEC2F p2
Definition: ctriangle2d.h:43
SFVEC2F m_centroid
Definition: cobject2d.h:66
float m_p2y_minus_p3y
Definition: ctriangle2d.h:47
SFVEC2F p3
Definition: ctriangle2d.h:44

Member Function Documentation

const BOARD_ITEM& COBJECT2D::GetBoardItem ( ) const
inlineinherited

Definition at line 75 of file cobject2d.h.

References COBJECT2D::m_boardItem.

Referenced by C3D_RENDER_RAYTRACING::reload().

75 { return m_boardItem; }
const BOARD_ITEM & m_boardItem
Definition: cobject2d.h:69
const SFVEC2F& COBJECT2D::GetCentroid ( ) const
inlineinherited
const SFVEC2F& CTRIANGLE2D::GetP1 ( ) const
inline

Definition at line 58 of file ctriangle2d.h.

References p1.

Referenced by C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer().

58 { return p1; }
SFVEC2F p1
Definition: ctriangle2d.h:42
const SFVEC2F& CTRIANGLE2D::GetP2 ( ) const
inline

Definition at line 59 of file ctriangle2d.h.

References p2.

Referenced by C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer().

59 { return p2; }
SFVEC2F p2
Definition: ctriangle2d.h:43
const SFVEC2F& CTRIANGLE2D::GetP3 ( ) const
inline

Definition at line 60 of file ctriangle2d.h.

References p3.

Referenced by C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer().

60 { return p3; }
SFVEC2F p3
Definition: ctriangle2d.h:44
bool CTRIANGLE2D::Intersect ( const RAYSEG2D aSegRay,
float *  aOutT,
SFVEC2F aNormalOut 
) const
overridevirtual

Function Intersect.

Intersect

Parameters
aSegRay
aOutTa value between 0.0 and 1.0 in relation to the time of the hit of the segment
aNormalOut
Returns

Implements COBJECT2D.

Definition at line 88 of file ctriangle2d.cpp.

91 {
92  wxASSERT( aOutT );
93  wxASSERT( aNormalOut );
94  return false;
95 }
bool CTRIANGLE2D::Intersects ( const CBBOX2D aBBox) const
overridevirtual

Function Intersects.

Intersects - a.Intersects(b) ⇔ !a.Disjoint(b) ⇔ !(a ∩ b = ∅) It intersects if the result intersection is not null

Parameters
aBBox
Returns

TODO: Optimize

Implements COBJECT2D.

Definition at line 72 of file ctriangle2d.cpp.

References CBBOX2D::Intersects(), and COBJECT2D::m_bbox.

73 {
74  if( !m_bbox.Intersects( aBBox ) )
75  return false;
77  return true;
78 }
bool Intersects(const CBBOX2D &aBBox) const
Function Intersects test if a bounding box intersects this box.
Definition: cbbox2d.cpp:213
CBBOX2D m_bbox
Definition: cobject2d.h:65
INTERSECTION_RESULT CTRIANGLE2D::IsBBoxInside ( const CBBOX2D aBBox) const
overridevirtual

Function IsBBoxInside.

Tests if the bouding is out, intersects or is complety inside

Parameters
aBBox- The bounding box to test
Returns
INTERSECTION_RESULT

Implements COBJECT2D.

Definition at line 98 of file ctriangle2d.cpp.

References CBBOX2D::Intersects(), INTR_MISSES, and COBJECT2D::m_bbox.

99 {
100  if( !m_bbox.Intersects( aBBox ) )
101  return INTR_MISSES;
102  // !TODO:
103  return INTR_MISSES;
104 }
bool Intersects(const CBBOX2D &aBBox) const
Function Intersects test if a bounding box intersects this box.
Definition: cbbox2d.cpp:213
CBBOX2D m_bbox
Definition: cobject2d.h:65
bool CTRIANGLE2D::IsPointInside ( const SFVEC2F aPoint) const
overridevirtual

Implements COBJECT2D.

Definition at line 107 of file ctriangle2d.cpp.

References m_inv_denominator, m_p1x_minus_p3x, m_p2y_minus_p3y, m_p3x_minus_p2x, m_p3y_minus_p1y, and p3.

108 {
109  // http://totologic.blogspot.co.uk/2014/01/accurate-point-in-triangle-test.html
110 
111  SFVEC2F point_minus_p3 = aPoint - p3;
112 
113  // barycentric coordinate system
114  const float a = ( m_p2y_minus_p3y * point_minus_p3.x +
115  m_p3x_minus_p2x * point_minus_p3.y ) * m_inv_denominator;
116 
117  if( 0.0f > a || a > 1.0f )
118  return false;
119 
120  const float b = ( m_p3y_minus_p1y * point_minus_p3.x +
121  m_p1x_minus_p3x * point_minus_p3.y ) * m_inv_denominator;
122 
123  if( 0.0f > b || b > 1.0f )
124  return false;
125 
126  const float c = 1.0f - a - b;
127 
128  return 0.0f <= c && c <= 1.0f;
129 /*
130  return 0.0f <= a && a <= 1.0f &&
131  0.0f <= b && b <= 1.0f &&
132  0.0f <= c && c <= 1.0f;*/
133 }
float m_p3x_minus_p2x
Definition: ctriangle2d.h:48
float m_p3y_minus_p1y
Definition: ctriangle2d.h:49
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
float m_p1x_minus_p3x
Definition: ctriangle2d.h:50
float m_inv_denominator
Definition: ctriangle2d.h:46
float m_p2y_minus_p3y
Definition: ctriangle2d.h:47
SFVEC2F p3
Definition: ctriangle2d.h:44
bool CTRIANGLE2D::Overlaps ( const CBBOX2D aBBox) const
overridevirtual

Function Overlaps.

Test if the box overlaps the object Conformance The function overlaps implements function Overlaps from the OGC Simple Feature Specification. http://www.opengeospatial.org/standards/sfa a.Overlaps(b) ⇔ ( dim(I(a)) = dim(I(b)) = dim(I(a) ∩ I(b))) ∧ (a ∩ b ≠ a) ∧ (a ∩ b ≠ b) It means that the result dimension of an overlap is the same dimentions of the bounding box (so the overlap cannot be a point or a line) and one of the boxes cannot full contain the other box.

Parameters
aBBox- The bounding box to test
Returns
true if the BBox intersects the object or is inside it

Implements COBJECT2D.

Definition at line 81 of file ctriangle2d.cpp.

82 {
83  // NOT IMPLEMENTED
84  return false;
85 }

Member Data Documentation

const BOARD_ITEM& COBJECT2D::m_boardItem
protectedinherited

Definition at line 69 of file cobject2d.h.

Referenced by COBJECT2D::GetBoardItem().

float CTRIANGLE2D::m_inv_denominator
private

Definition at line 46 of file ctriangle2d.h.

Referenced by CTRIANGLE2D(), and IsPointInside().

OBJECT2D_TYPE COBJECT2D::m_obj_type
protectedinherited

Definition at line 67 of file cobject2d.h.

Referenced by COBJECT2D::COBJECT2D(), and COBJECT2D::GetObjectType().

float CTRIANGLE2D::m_p1x_minus_p3x
private

Definition at line 50 of file ctriangle2d.h.

Referenced by CTRIANGLE2D(), and IsPointInside().

float CTRIANGLE2D::m_p2y_minus_p3y
private

Definition at line 47 of file ctriangle2d.h.

Referenced by CTRIANGLE2D(), and IsPointInside().

float CTRIANGLE2D::m_p3x_minus_p2x
private

Definition at line 48 of file ctriangle2d.h.

Referenced by CTRIANGLE2D(), and IsPointInside().

float CTRIANGLE2D::m_p3y_minus_p1y
private

Definition at line 49 of file ctriangle2d.h.

Referenced by CTRIANGLE2D(), and IsPointInside().

SFVEC2F CTRIANGLE2D::p1
private

Definition at line 42 of file ctriangle2d.h.

Referenced by CTRIANGLE2D(), and GetP1().

SFVEC2F CTRIANGLE2D::p2
private

Definition at line 43 of file ctriangle2d.h.

Referenced by CTRIANGLE2D(), and GetP2().

SFVEC2F CTRIANGLE2D::p3
private

Definition at line 44 of file ctriangle2d.h.

Referenced by CTRIANGLE2D(), GetP3(), and IsPointInside().


The documentation for this class was generated from the following files: