KiCad PCB EDA Suite
CRING2D Class Reference

#include <cring2d.h>

Inheritance diagram for CRING2D:
COBJECT2D

Public Member Functions

const SFVEC2FGetCenter () const
 
float GetInnerRadius () const
 
float GetOuterRadius () const
 
float GetInnerRadiusSquared () const
 
float GetOuterRadiusSquared () const
 
 CRING2D (const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, const BOARD_ITEM &aBoardItem)
 
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 m_center
 
float m_inner_radius
 
float m_outer_radius
 
float m_inner_radius_squared
 
float m_outer_radius_squared
 

Detailed Description

Definition at line 35 of file cring2d.h.

Constructor & Destructor Documentation

◆ CRING2D()

CRING2D::CRING2D ( const SFVEC2F aCenter,
float  aInnerRadius,
float  aOuterRadius,
const BOARD_ITEM aBoardItem 
)

Definition at line 35 of file cring2d.cpp.

37  : COBJECT2D( OBJECT2D_TYPE::RING, aBoardItem )
38 {
39  wxASSERT( aInnerRadius < aOuterRadius );
40 
41  m_center = aCenter;
42  m_inner_radius = aInnerRadius;
43  m_outer_radius = aOuterRadius;
44 
45  m_inner_radius_squared = aInnerRadius * aInnerRadius;
46  m_outer_radius_squared = aOuterRadius * aOuterRadius;
47 
48  m_bbox.Reset();
49  m_bbox.Set( m_center - SFVEC2F( aOuterRadius, aOuterRadius ),
50  m_center + SFVEC2F( aOuterRadius, aOuterRadius ) );
53 
54 
55  wxASSERT( m_bbox.IsInitialized() );
56 }
float m_outer_radius
Definition: cring2d.h:48
SFVEC2F m_center
Definition: cring2d.h:46
float m_outer_radius_squared
Definition: cring2d.h:50
float m_inner_radius_squared
Definition: cring2d.h:49
void Reset()
Function Reset reset the bounding box to zero and de-initialized it.
Definition: cbbox2d.cpp:87
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
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:60
bool IsInitialized() const
Function IsInitialized check if this bounding box is already initialized.
Definition: cbbox2d.cpp:78
void ScaleNextUp()
Function ScaleNextUp scales a bounding box to the next float representation making it larger.
Definition: cbbox2d.cpp:163
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:120
float m_inner_radius
Definition: cring2d.h:47

References CBBOX2D::GetCenter(), CBBOX2D::IsInitialized(), COBJECT2D::m_bbox, m_center, COBJECT2D::m_centroid, m_inner_radius, m_inner_radius_squared, m_outer_radius, m_outer_radius_squared, CBBOX2D::Reset(), RING, CBBOX2D::ScaleNextUp(), and CBBOX2D::Set().

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::createItemsFromContainer(), and C3D_RENDER_RAYTRACING::Reload().

◆ GetCenter()

const SFVEC2F& CRING2D::GetCenter ( ) const
inline

Definition at line 38 of file cring2d.h.

38 { return m_center; }
SFVEC2F m_center
Definition: cring2d.h:46

References m_center.

Referenced by C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer().

◆ GetCentroid()

const SFVEC2F& COBJECT2D::GetCentroid ( ) const
inlineinherited

◆ GetInnerRadius()

float CRING2D::GetInnerRadius ( ) const
inline

Definition at line 39 of file cring2d.h.

39 { return m_inner_radius; }
float m_inner_radius
Definition: cring2d.h:47

References m_inner_radius.

Referenced by C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer().

◆ GetInnerRadiusSquared()

float CRING2D::GetInnerRadiusSquared ( ) const
inline

Definition at line 42 of file cring2d.h.

42 { return m_inner_radius_squared; }
float m_inner_radius_squared
Definition: cring2d.h:49

References m_inner_radius_squared.

◆ GetObjectType()

◆ GetOuterRadius()

float CRING2D::GetOuterRadius ( ) const
inline

Definition at line 40 of file cring2d.h.

40 { return m_outer_radius; }
float m_outer_radius
Definition: cring2d.h:48

References m_outer_radius.

Referenced by C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer().

◆ GetOuterRadiusSquared()

float CRING2D::GetOuterRadiusSquared ( ) const
inline

Definition at line 43 of file cring2d.h.

43 { return m_outer_radius_squared; }
float m_outer_radius_squared
Definition: cring2d.h:50

References m_outer_radius_squared.

◆ Intersect()

bool CRING2D::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 73 of file cring2d.cpp.

76 {
77  // This code used directly from Steve Marschner's CS667 framework
78  // http://cs665pd.googlecode.com/svn/trunk/photon/sphere.cpp
79 
80  // Compute some factors used in computation
81  const float qx = (aSegRay.m_Start.x - m_center.x);
82  const float qy = (aSegRay.m_Start.y - m_center.y);
83 
84  const float qd = qx * aSegRay.m_Dir.x + qy * aSegRay.m_Dir.y;
85  const float qq = qx * qx + qy * qy;
86 
87  // solving the quadratic equation for t at the pts of intersection
88  // dd*t^2 + (2*qd)*t + (qq-r^2) = 0
89 
90  const float discriminantsqr = qd * qd - qq;
91  const float discriminantsqr_outer = discriminantsqr + m_outer_radius_squared;
92 
93  // If the discriminant is less than zero, there is no intersection
94  if( discriminantsqr_outer < FLT_EPSILON )
95  return false;
96 
97  // Otherwise check and make sure that the intersections occur on the ray (t
98  // > 0) and return the closer one
99  const float discriminant = sqrt( discriminantsqr_outer );
100  float t = (-qd - discriminant);
101 
102  if( (t > FLT_EPSILON) && (t < aSegRay.m_Length) )
103  {
104  if( aNormalOut )
105  {
106  SFVEC2F hitPoint = aSegRay.at( t );
107  *aNormalOut = (hitPoint - m_center) / m_outer_radius;
108  }
109  }
110  else
111  {
112  const float discriminantsqr_inter = discriminantsqr + m_inner_radius_squared;
113 
114  if( discriminantsqr_inter > FLT_EPSILON )
115  {
116  const float discriminant_inner = sqrt( discriminantsqr_inter );
117 
118  const float t2_inner = (-qd + discriminant_inner);
119 
120  if( (t2_inner > FLT_EPSILON) && (t2_inner < aSegRay.m_Length) )
121  {
122  t = t2_inner;
123 
124  if( aNormalOut )
125  {
126  const SFVEC2F hitPoint = aSegRay.at( t2_inner );
127 
128  *aNormalOut = (m_center - hitPoint) / m_inner_radius;
129  }
130  }
131  else
132  return false;
133  }
134  else
135  return false;
136  }
137 
138  wxASSERT( (t > 0.0f) && (t <= aSegRay.m_Length) );
139 
140  // Convert the intersection to a normalized 0.0 .. 1.0
141  if( aOutT )
142  *aOutT = t / aSegRay.m_Length;
143 
144  return true;
145 }
float m_outer_radius
Definition: cring2d.h:48
SFVEC2F m_center
Definition: cring2d.h:46
float m_outer_radius_squared
Definition: cring2d.h:50
float m_inner_radius_squared
Definition: cring2d.h:49
SFVEC2F m_Dir
Definition: ray.h:115
SFVEC2F at(float t) const
Definition: ray.h:141
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
float m_Length
Definition: ray.h:117
SFVEC2F m_Start
Definition: ray.h:112
float m_inner_radius
Definition: cring2d.h:47

References RAYSEG2D::at(), m_center, RAYSEG2D::m_Dir, m_inner_radius, m_inner_radius_squared, RAYSEG2D::m_Length, m_outer_radius, m_outer_radius_squared, and RAYSEG2D::m_Start.

◆ Intersects()

bool CRING2D::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 66 of file cring2d.cpp.

67 {
68  // !TODO: check the inside for a great improovment
70 }
SFVEC2F m_center
Definition: cring2d.h:46
float m_outer_radius_squared
Definition: cring2d.h:50
bool Intersects(const CBBOX2D &aBBox) const
Function Intersects test if a bounding box intersects this box.
Definition: cbbox2d.cpp:212

References CBBOX2D::Intersects(), m_center, and m_outer_radius_squared.

◆ IsBBoxInside()

INTERSECTION_RESULT CRING2D::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 148 of file cring2d.cpp.

149 {
150  /*
151  if( !m_bbox.Overlaps( aBBox ) )
152  return INTERSECTION_RESULT::MISSES;
153 
154  SFVEC2F v[4];
155 
156  v[0] = aBBox.Min() - m_center;
157  v[1] = aBBox.Max() - m_center;
158  v[2] = SFVEC2F( aBBox.Min().x, aBBox.Max().y ) - m_center;
159  v[3] = SFVEC2F( aBBox.Max().x, aBBox.Min().y ) - m_center;
160 
161  float s[4];
162 
163  s[0] = v[0].x * v[0].x + v[0].y * v[0].y;
164  s[1] = v[1].x * v[1].x + v[1].y * v[1].y;
165  s[2] = v[2].x * v[2].x + v[2].y * v[2].y;
166  s[3] = v[3].x * v[3].x + v[3].y * v[3].y;
167 
168  bool isInside[4];
169 
170  isInside[0] = s[0] <= m_radius_squared;
171  isInside[1] = s[1] <= m_radius_squared;
172  isInside[2] = s[2] <= m_radius_squared;
173  isInside[3] = s[3] <= m_radius_squared;
174 
175  // Check if all points are inside the circle
176  if( isInside[0] &&
177  isInside[1] &&
178  isInside[2] &&
179  isInside[3] )
180  return INTERSECTION_RESULT::FULL_INSIDE;
181 
182  // Check if any point is inside the circle
183  if( isInside[0] ||
184  isInside[1] ||
185  isInside[2] ||
186  isInside[3] )
187  return INTERSECTION_RESULT::INTERSECTS;
188 */
190 }

References MISSES.

◆ IsPointInside()

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

Implements COBJECT2D.

Definition at line 193 of file cring2d.cpp.

194 {
195  const SFVEC2F v = m_center - aPoint;
196 
197  const float dot = glm::dot( v, v );
198 
199  if( (dot <= m_outer_radius_squared) &&
200  (dot >= m_inner_radius_squared) )
201  return true;
202 
203  return false;
204 }
SFVEC2F m_center
Definition: cring2d.h:46
float m_outer_radius_squared
Definition: cring2d.h:50
float m_inner_radius_squared
Definition: cring2d.h:49
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45

References m_center, m_inner_radius_squared, and m_outer_radius_squared.

◆ Overlaps()

bool CRING2D::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 59 of file cring2d.cpp.

60 {
61  // NOT IMPLEMENTED
62  return false;
63 }

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_center

SFVEC2F CRING2D::m_center
private

Definition at line 46 of file cring2d.h.

Referenced by CRING2D(), GetCenter(), Intersect(), Intersects(), and IsPointInside().

◆ m_centroid

◆ m_inner_radius

float CRING2D::m_inner_radius
private

Definition at line 47 of file cring2d.h.

Referenced by CRING2D(), GetInnerRadius(), and Intersect().

◆ m_inner_radius_squared

float CRING2D::m_inner_radius_squared
private

Definition at line 49 of file cring2d.h.

Referenced by CRING2D(), GetInnerRadiusSquared(), Intersect(), and IsPointInside().

◆ 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_outer_radius

float CRING2D::m_outer_radius
private

Definition at line 48 of file cring2d.h.

Referenced by CRING2D(), GetOuterRadius(), and Intersect().

◆ m_outer_radius_squared

float CRING2D::m_outer_radius_squared
private

Definition at line 50 of file cring2d.h.

Referenced by CRING2D(), GetOuterRadiusSquared(), Intersect(), Intersects(), and IsPointInside().


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