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 ( const SFVEC2F aCenter,
float  aInnerRadius,
float  aOuterRadius,
const BOARD_ITEM aBoardItem 
)

Definition at line 35 of file cring2d.cpp.

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(), CBBOX2D::ScaleNextUp(), and CBBOX2D::Set().

36  : COBJECT2D( OBJ2D_RING, aBoardItem )
37 {
38  wxASSERT( aInnerRadius < aOuterRadius );
39 
40  m_center = aCenter;
41  m_inner_radius = aInnerRadius;
42  m_outer_radius = aOuterRadius;
43 
44  m_inner_radius_squared = aInnerRadius * aInnerRadius;
45  m_outer_radius_squared = aOuterRadius * aOuterRadius;
46 
47  m_bbox.Reset();
48  m_bbox.Set( m_center - SFVEC2F( aOuterRadius, aOuterRadius ),
49  m_center + SFVEC2F( aOuterRadius, aOuterRadius ) );
52 
53 
54  wxASSERT( m_bbox.IsInitialized() );
55 }
bool IsInitialized() const
Function IsInitialized check if this bounding box is already initialized.
Definition: cbbox2d.cpp:79
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:88
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: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
float m_inner_radius
Definition: cring2d.h:47

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& CRING2D::GetCenter ( ) const
inline

Definition at line 38 of file cring2d.h.

References m_center.

Referenced by C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer().

38 { return m_center; }
SFVEC2F m_center
Definition: cring2d.h:46
const SFVEC2F& COBJECT2D::GetCentroid ( ) const
inlineinherited
float CRING2D::GetInnerRadius ( ) const
inline

Definition at line 39 of file cring2d.h.

References m_inner_radius.

Referenced by C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer().

39 { return m_inner_radius; }
float m_inner_radius
Definition: cring2d.h:47
float CRING2D::GetInnerRadiusSquared ( ) const
inline

Definition at line 42 of file cring2d.h.

References m_inner_radius_squared.

42 { return m_inner_radius_squared; }
float m_inner_radius_squared
Definition: cring2d.h:49
float CRING2D::GetOuterRadius ( ) const
inline

Definition at line 40 of file cring2d.h.

References m_outer_radius.

Referenced by C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer().

40 { return m_outer_radius; }
float m_outer_radius
Definition: cring2d.h:48
float CRING2D::GetOuterRadiusSquared ( ) const
inline

Definition at line 43 of file cring2d.h.

References m_outer_radius_squared.

43 { return m_outer_radius_squared; }
float m_outer_radius_squared
Definition: cring2d.h:50
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 72 of file cring2d.cpp.

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.

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

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

66 {
67  // !TODO: check the inside for a great improovment
69 }
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:213
INTERSECTION_RESULT CRING2D::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 140 of file cring2d.cpp.

References INTR_MISSES.

141 {
142  /*
143  if( !m_bbox.Overlaps( aBBox ) )
144  return INTR_MISSES;
145 
146  SFVEC2F v[4];
147 
148  v[0] = aBBox.Min() - m_center;
149  v[1] = aBBox.Max() - m_center;
150  v[2] = SFVEC2F( aBBox.Min().x, aBBox.Max().y ) - m_center;
151  v[3] = SFVEC2F( aBBox.Max().x, aBBox.Min().y ) - m_center;
152 
153  float s[4];
154 
155  s[0] = v[0].x * v[0].x + v[0].y * v[0].y;
156  s[1] = v[1].x * v[1].x + v[1].y * v[1].y;
157  s[2] = v[2].x * v[2].x + v[2].y * v[2].y;
158  s[3] = v[3].x * v[3].x + v[3].y * v[3].y;
159 
160  bool isInside[4];
161 
162  isInside[0] = s[0] <= m_radius_squared;
163  isInside[1] = s[1] <= m_radius_squared;
164  isInside[2] = s[2] <= m_radius_squared;
165  isInside[3] = s[3] <= m_radius_squared;
166 
167  // Check if all points are inside the circle
168  if( isInside[0] &&
169  isInside[1] &&
170  isInside[2] &&
171  isInside[3] )
172  return INTR_FULL_INSIDE;
173 
174  // Check if any point is inside the circle
175  if( isInside[0] ||
176  isInside[1] ||
177  isInside[2] ||
178  isInside[3] )
179  return INTR_INTERSECTS;
180 */
181  return INTR_MISSES;
182 }
bool CRING2D::IsPointInside ( const SFVEC2F aPoint) const
overridevirtual

Implements COBJECT2D.

Definition at line 185 of file cring2d.cpp.

References m_center, m_inner_radius_squared, and m_outer_radius_squared.

186 {
187  const SFVEC2F v = m_center - aPoint;
188 
189  const float dot = glm::dot( v, v );
190 
191  if( (dot <= m_outer_radius_squared) &&
192  (dot >= m_inner_radius_squared) )
193  return true;
194 
195  return false;
196 }
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
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 58 of file cring2d.cpp.

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

Member Data Documentation

const BOARD_ITEM& COBJECT2D::m_boardItem
protectedinherited

Definition at line 69 of file cobject2d.h.

Referenced by COBJECT2D::GetBoardItem().

SFVEC2F CRING2D::m_center
private

Definition at line 46 of file cring2d.h.

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

float CRING2D::m_inner_radius
private

Definition at line 47 of file cring2d.h.

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

float CRING2D::m_inner_radius_squared
private

Definition at line 49 of file cring2d.h.

Referenced by CRING2D(), GetInnerRadiusSquared(), Intersect(), 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 CRING2D::m_outer_radius
private

Definition at line 48 of file cring2d.h.

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

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: