KiCad PCB EDA Suite
CITEMLAYERCSG2D Class Reference

#include <citemlayercsg2d.h>

Inheritance diagram for CITEMLAYERCSG2D:
COBJECT2D

Public Member Functions

 CITEMLAYERCSG2D (const COBJECT2D *aObjectA, std::vector< const COBJECT2D * > *aObjectB, const COBJECT2D *aObjectC, const BOARD_ITEM &aBoardItem)
 
 ~CITEMLAYERCSG2D ()
 
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

const COBJECT2Dm_objectA
 
std::vector< const COBJECT2D * > * m_objectB
 
const COBJECT2Dm_objectC
 

Detailed Description

Definition at line 78 of file citemlayercsg2d.h.

Constructor & Destructor Documentation

CITEMLAYERCSG2D::CITEMLAYERCSG2D ( const COBJECT2D aObjectA,
std::vector< const COBJECT2D * > *  aObjectB,
const COBJECT2D aObjectC,
const BOARD_ITEM aBoardItem 
)

Definition at line 34 of file citemlayercsg2d.cpp.

References COBJECT2D::GetBBox(), CBBOX2D::GetCenter(), CBBOX2D::IsInitialized(), COBJECT2D::m_bbox, COBJECT2D::m_centroid, CBBOX2D::Reset(), CBBOX2D::ScaleNextUp(), and CBBOX2D::Set().

37  :
38  COBJECT2D( OBJ2D_CSG, aBoardItem ),
39  m_objectA(aObjectA),
40  m_objectB(aObjectB),
41  m_objectC(aObjectC)
42 {
43  wxASSERT( aObjectA );
44 
45  m_bbox.Reset();
46  m_bbox.Set( aObjectA->GetBBox() );
49 
50  wxASSERT( m_bbox.IsInitialized() );
51 }
bool IsInitialized() const
Function IsInitialized check if this bounding box is already initialized.
Definition: cbbox2d.cpp:79
std::vector< const COBJECT2D * > * m_objectB
const COBJECT2D * m_objectC
const COBJECT2D * m_objectA
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
void Set(const SFVEC2F &aPbMin, const SFVEC2F &aPbMax)
Function Set Set bounding box with new parameters.
Definition: cbbox2d.cpp:61
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 m_centroid
Definition: cobject2d.h:66
const CBBOX2D & GetBBox() const
Definition: cobject2d.h:121
CITEMLAYERCSG2D::~CITEMLAYERCSG2D ( )

Definition at line 54 of file citemlayercsg2d.cpp.

References CSGITEM_EMPTY, CSGITEM_FULL, and m_objectB.

55 {
56  if( ((void*)m_objectB != CSGITEM_EMPTY) &&
57  ((void*)m_objectB != CSGITEM_FULL) )
58  {
59  delete m_objectB;
60  m_objectB = NULL;
61  }
62 }
std::vector< const COBJECT2D * > * m_objectB
#define CSGITEM_EMPTY
This class is used to make constructive solig geometry for items objects on layers.
#define CSGITEM_FULL

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
bool CITEMLAYERCSG2D::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 81 of file citemlayercsg2d.cpp.

References RAYSEG2D::atNormalized(), COBJECT2D::GetObjectType(), COBJECT2D::Intersect(), COBJECT2D::IsPointInside(), m_objectA, m_objectB, RAYSEG2D::m_Start, NextFloatDown(), and OBJ2D_DUMMYBLOCK.

84 {
85  wxASSERT( aOutT );
86  wxASSERT( aNormalOut );
87 
89  return false;
90 
91  float currentRayDist;
92  SFVEC2F currentRayPos;
93  SFVEC2F currentNormal;
94 
95  if( m_objectA->IsPointInside( aSegRay.m_Start ) )
96  {
97  // start ray point off where it is now (at the origin)
98  currentRayDist = 0.0f;
99  currentRayPos = aSegRay.m_Start;
100  }
101  else
102  {
103  //move ray point to start of main object
104  if( !m_objectA->Intersect( aSegRay, &currentRayDist, &currentNormal ) )
105  return false;
106 
107  currentRayPos = aSegRay.atNormalized( NextFloatDown( currentRayDist ) );
108  }
109 
110  //wxASSERT( (currentRayDist >= 0.0f) && (currentRayDist <= 1.0f) );
111 
112 
113  // move through the union of subtracted regions
114  bool hitSubRegion = false;
115 
116  if( m_objectB )
117  {
118  while(1)
119  {
120  bool wasInsideSubVol = false;
121 
122  //check against all subbed objects
123  for( unsigned int i = 0; i < m_objectB->size(); ++i )
124  {
125  if( ((const COBJECT2D *)(*m_objectB)[i])->IsPointInside( currentRayPos ) )
126  {
127  hitSubRegion = true;
128 
129  // ray point is inside a subtracted region, so move it to the end of the
130  // subtracted region
131  float hitDist;
132  if( !((const COBJECT2D *)(*m_objectB)[i])->Intersect( aSegRay,
133  &hitDist,
134  &currentNormal ) )
135  return false; // ray hit main object but did not leave subtracted volume
136 
137  wxASSERT( hitDist <= 1.0f );
138 
139  if( hitDist > currentRayDist )
140  currentRayDist = hitDist;
141 
142  currentRayDist += 0.0001f;
143 
144  // ray has left this specific subtracted object volume
145  currentRayPos = aSegRay.atNormalized( currentRayDist );
146 
147  if( m_objectA->IsPointInside( currentRayPos ) )
148  {
149  wasInsideSubVol = true;
150 
151  break;
152  }
153  }
154  }
155 
156  if( !wasInsideSubVol )
157  break; // ray has succesfully passed through all subtracted regions
158 
159  if( currentRayDist >= 1.0f )
160  break;
161  }
162  }
163 
164  //ray is not inside any of the specific subtracted regions
165 
166  if( hitSubRegion )
167  {
168  //if( !m_objectA->IsPointInside( currentRayPos ) )
169  // return false; // ray got right through the hole in the object!
170 
171  currentNormal *= -1.0f;
172  }
173  else
174  {
175  //ray just hit the main object without hitting any holes
176  }
177 
178  *aNormalOut = currentNormal;
179  *aOutT = currentRayDist;
180 
181  return true;
182 }
std::vector< const COBJECT2D * > * m_objectB
const COBJECT2D * m_objectA
virtual bool Intersect(const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut) const =0
Function Intersect.
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
float NextFloatDown(float v)
Definition: 3d_fastmath.h:157
OBJECT2D_TYPE GetObjectType() const
Definition: cobject2d.h:125
SFVEC2F atNormalized(float t) const
Function atNormalized - returns the position at t t - value 0.0 ...
Definition: ray.h:115
SFVEC2F m_Start
Definition: ray.h:88
virtual bool IsPointInside(const SFVEC2F &aPoint) const =0
bool CITEMLAYERCSG2D::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

Implements COBJECT2D.

Definition at line 65 of file citemlayercsg2d.cpp.

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

66 {
67  return m_bbox.Intersects( aBBox );
68  // !TODO: improove this implementation
69  //return false;
70 }
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 CITEMLAYERCSG2D::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 185 of file citemlayercsg2d.cpp.

References INTR_MISSES.

186 {
187 
188  // !TODO:
189 
190  return INTR_MISSES;
191 }
bool CITEMLAYERCSG2D::IsPointInside ( const SFVEC2F aPoint) const
overridevirtual

Implements COBJECT2D.

Definition at line 194 of file citemlayercsg2d.cpp.

References CSGITEM_EMPTY, COBJECT2D::IsPointInside(), m_objectA, and m_objectB.

195 {
196  // Perform the operation (A - B) /\ C
197 
198  if( m_objectA->IsPointInside( aPoint ) )
199  {
200 
201  if( m_objectB != CSGITEM_EMPTY)
202  for( unsigned int i = 0; i< m_objectB->size(); i++ )
203  {
204  if( (*m_objectB)[i]->IsPointInside( aPoint ) )
205  return false;
206  }
207 
208  // !TODO: not yet implemented
209  //if( m_objectC && m_objectC != CSGITEM_FULL )
210  // return m_objectC->IsPointInside( aPoint );
211 
212  return true;
213  }
214 
215  return false;
216 }
std::vector< const COBJECT2D * > * m_objectB
const COBJECT2D * m_objectA
#define CSGITEM_EMPTY
This class is used to make constructive solig geometry for items objects on layers.
virtual bool IsPointInside(const SFVEC2F &aPoint) const =0
bool CITEMLAYERCSG2D::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 73 of file citemlayercsg2d.cpp.

74 {
75  // NOT IMPLEMENTED
76  return false;
77 }

Member Data Documentation

const BOARD_ITEM& COBJECT2D::m_boardItem
protectedinherited

Definition at line 69 of file cobject2d.h.

Referenced by COBJECT2D::GetBoardItem().

OBJECT2D_TYPE COBJECT2D::m_obj_type
protectedinherited

Definition at line 67 of file cobject2d.h.

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

const COBJECT2D* CITEMLAYERCSG2D::m_objectA
private

Definition at line 81 of file citemlayercsg2d.h.

Referenced by Intersect(), and IsPointInside().

std::vector<const COBJECT2D *>* CITEMLAYERCSG2D::m_objectB
private

Definition at line 82 of file citemlayercsg2d.h.

Referenced by Intersect(), IsPointInside(), and ~CITEMLAYERCSG2D().

const COBJECT2D* CITEMLAYERCSG2D::m_objectC
private

Definition at line 83 of file citemlayercsg2d.h.


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