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

Definition at line 34 of file citemlayercsg2d.cpp.

37  : COBJECT2D( OBJECT2D_TYPE::CSG, aBoardItem ),
38  m_objectA( aObjectA ),
39  m_objectB( aObjectB ),
40  m_objectC( aObjectC )
41 {
42  wxASSERT( aObjectA );
43 
44  m_bbox.Reset();
45  m_bbox.Set( aObjectA->GetBBox() );
48 
49  wxASSERT( m_bbox.IsInitialized() );
50 }
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
bool IsInitialized() const
Function IsInitialized check if this bounding box is already initialized.
Definition: cbbox2d.cpp:79
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 m_centroid
Definition: cobject2d.h:66
SFVEC2F GetCenter() const
Function GetCenter return the center point of the bounding box.
Definition: cbbox2d.cpp:121
const CBBOX2D & GetBBox() const
Definition: cobject2d.h:121

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

◆ ~CITEMLAYERCSG2D()

CITEMLAYERCSG2D::~CITEMLAYERCSG2D ( )

Definition at line 53 of file citemlayercsg2d.cpp.

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

References CSGITEM_EMPTY, CSGITEM_FULL, m_objectB, and NULL.

Member Function Documentation

◆ GetBBox()

◆ GetBoardItem()

const BOARD_ITEM& COBJECT2D::GetBoardItem ( ) const
inlineinherited

Definition at line 75 of file cobject2d.h.

75 { return m_boardItem; }
const BOARD_ITEM & m_boardItem
Definition: cobject2d.h:69

References COBJECT2D::m_boardItem.

Referenced by C3D_RENDER_RAYTRACING::reload().

◆ GetCentroid()

const SFVEC2F& COBJECT2D::GetCentroid ( ) const
inlineinherited

◆ GetObjectType()

◆ Intersect()

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 80 of file citemlayercsg2d.cpp.

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

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

◆ Intersects()

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 64 of file citemlayercsg2d.cpp.

65 {
66  return m_bbox.Intersects( aBBox );
67  // !TODO: improove this implementation
68  //return false;
69 }
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

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

◆ IsBBoxInside()

INTERSECTION_RESULT CITEMLAYERCSG2D::IsBBoxInside ( const CBBOX2D aBBox) const
overridevirtual

Function IsBBoxInside.

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

Returns
INTERSECTION_RESULT

Implements COBJECT2D.

Definition at line 184 of file citemlayercsg2d.cpp.

185 {
186 
187  // !TODO:
188 
190 }

References MISSES.

◆ IsPointInside()

bool CITEMLAYERCSG2D::IsPointInside ( const SFVEC2F aPoint) const
overridevirtual

Implements COBJECT2D.

Definition at line 193 of file citemlayercsg2d.cpp.

194 {
195  // Perform the operation (A - B) /\ C
196 
197  if( m_objectA->IsPointInside( aPoint ) )
198  {
199 
200  if( m_objectB != CSGITEM_EMPTY)
201  for( unsigned int i = 0; i< m_objectB->size(); i++ )
202  {
203  if( (*m_objectB)[i]->IsPointInside( aPoint ) )
204  return false;
205  }
206 
207  // !TODO: not yet implemented
208  //if( m_objectC && m_objectC != CSGITEM_FULL )
209  // return m_objectC->IsPointInside( aPoint );
210 
211  return true;
212  }
213 
214  return false;
215 }
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

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

◆ Overlaps()

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 72 of file citemlayercsg2d.cpp.

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

Member Data Documentation

◆ m_bbox

◆ m_boardItem

const BOARD_ITEM& COBJECT2D::m_boardItem
protectedinherited

Definition at line 69 of file cobject2d.h.

Referenced by COBJECT2D::GetBoardItem().

◆ m_centroid

◆ m_obj_type

OBJECT2D_TYPE COBJECT2D::m_obj_type
protectedinherited

Definition at line 67 of file cobject2d.h.

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

◆ m_objectA

const COBJECT2D* CITEMLAYERCSG2D::m_objectA
private

Definition at line 81 of file citemlayercsg2d.h.

Referenced by Intersect(), and IsPointInside().

◆ m_objectB

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

Definition at line 82 of file citemlayercsg2d.h.

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

◆ m_objectC

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: