KiCad PCB EDA Suite
RING_2D Class Reference

#include <ring_2d.h>

Inheritance diagram for RING_2D:
OBJECT_2D

Public Member Functions

 RING_2D (const SFVEC2F &aCenter, float aInnerRadius, float aOuterRadius, const BOARD_ITEM &aBoardItem)
 
bool Overlaps (const BBOX_2D &aBBox) const override
 Test if the box overlaps the object. More...
 
bool Intersects (const BBOX_2D &aBBox) const override
 a.Intersects(b) ⇔ !a.Disjoint(b) ⇔ !(a ∩ b = ∅) More...
 
bool Intersect (const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut) const override
 
INTERSECTION_RESULT IsBBoxInside (const BBOX_2D &aBBox) const override
 Test this object if it's completely outside, intersects, or is completely inside aBBox. More...
 
bool IsPointInside (const SFVEC2F &aPoint) const override
 
const SFVEC2FGetCenter () const
 
float GetInnerRadius () const
 
float GetOuterRadius () const
 
float GetInnerRadiusSquared () const
 
float GetOuterRadiusSquared () const
 
const BOARD_ITEMGetBoardItem () const
 
const BBOX_2DGetBBox () const
 
const SFVEC2FGetCentroid () const
 
OBJECT_2D_TYPE GetObjectType () const
 

Protected Attributes

BBOX_2D m_bbox
 
SFVEC2F m_centroid
 
OBJECT_2D_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 34 of file ring_2d.h.

Constructor & Destructor Documentation

◆ RING_2D()

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

Definition at line 35 of file ring_2d.cpp.

36  :
37  OBJECT_2D( OBJECT_2D_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  wxASSERT( m_bbox.IsInitialized() );
55 }
BBOX_2D m_bbox
Definition: object_2d.h:110
float m_outer_radius
Definition: ring_2d.h:56
SFVEC2F GetCenter() const
Definition: bbox_2d.cpp:119
float m_inner_radius
Definition: ring_2d.h:55
void Set(const SFVEC2F &aPbMin, const SFVEC2F &aPbMax)
Set bounding box with new parameters.
Definition: bbox_2d.cpp:61
SFVEC2F m_center
Definition: ring_2d.h:54
SFVEC2F m_centroid
Definition: object_2d.h:111
OBJECT_2D(OBJECT_2D_TYPE aObjType, const BOARD_ITEM &aBoardItem)
Definition: object_2d.cpp:36
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
void Reset()
Reset the bounding box to zero and uninitialize it.
Definition: bbox_2d.cpp:86
float m_outer_radius_squared
Definition: ring_2d.h:58
float m_inner_radius_squared
Definition: ring_2d.h:57
void ScaleNextUp()
Scale a bounding box to the next float representation making it larger.
Definition: bbox_2d.cpp:162
bool IsInitialized() const
Check if this bounding box is already initialized.
Definition: bbox_2d.cpp:79

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

Member Function Documentation

◆ GetBBox()

◆ GetBoardItem()

const BOARD_ITEM& OBJECT_2D::GetBoardItem ( ) const
inlineinherited

Definition at line 66 of file object_2d.h.

66 { return m_boardItem; }
const BOARD_ITEM & m_boardItem
Definition: object_2d.h:114

References OBJECT_2D::m_boardItem.

Referenced by RENDER_3D_RAYTRACE::createItemsFromContainer().

◆ GetCenter()

const SFVEC2F& RING_2D::GetCenter ( ) const
inline

Definition at line 46 of file ring_2d.h.

46 { return m_center; }
SFVEC2F m_center
Definition: ring_2d.h:54

References m_center.

Referenced by RENDER_3D_OPENGL::addObjectTriangles().

◆ GetCentroid()

const SFVEC2F& OBJECT_2D::GetCentroid ( ) const
inlineinherited

Definition at line 105 of file object_2d.h.

105 { return m_centroid; }
SFVEC2F m_centroid
Definition: object_2d.h:111

References OBJECT_2D::m_centroid.

Referenced by LAYER_ITEM::LAYER_ITEM(), sortByCentroidX(), sortByCentroidY(), and sortByCentroidZ().

◆ GetInnerRadius()

float RING_2D::GetInnerRadius ( ) const
inline

Definition at line 47 of file ring_2d.h.

47 { return m_inner_radius; }
float m_inner_radius
Definition: ring_2d.h:55

References m_inner_radius.

Referenced by RENDER_3D_OPENGL::addObjectTriangles().

◆ GetInnerRadiusSquared()

float RING_2D::GetInnerRadiusSquared ( ) const
inline

Definition at line 50 of file ring_2d.h.

50 { return m_inner_radius_squared; }
float m_inner_radius_squared
Definition: ring_2d.h:57

References m_inner_radius_squared.

◆ GetObjectType()

◆ GetOuterRadius()

float RING_2D::GetOuterRadius ( ) const
inline

Definition at line 48 of file ring_2d.h.

48 { return m_outer_radius; }
float m_outer_radius
Definition: ring_2d.h:56

References m_outer_radius.

Referenced by RENDER_3D_OPENGL::addObjectTriangles().

◆ GetOuterRadiusSquared()

float RING_2D::GetOuterRadiusSquared ( ) const
inline

Definition at line 51 of file ring_2d.h.

51 { return m_outer_radius_squared; }
float m_outer_radius_squared
Definition: ring_2d.h:58

References m_outer_radius_squared.

◆ Intersect()

bool RING_2D::Intersect ( const RAYSEG2D aSegRay,
float *  aOutT,
SFVEC2F aNormalOut 
) const
overridevirtual
Parameters
aOutTa value between 0.0 and 1.0 in relation to the time of the hit of the segment.

Implements OBJECT_2D.

Definition at line 72 of file ring_2d.cpp.

73 {
74  // This code used directly from Steve Marschner's CS667 framework
75  // http://cs665pd.googlecode.com/svn/trunk/photon/sphere.cpp
76 
77  // Compute some factors used in computation
78  const float qx = ( aSegRay.m_Start.x - m_center.x );
79  const float qy = ( aSegRay.m_Start.y - m_center.y );
80 
81  const float qd = qx * aSegRay.m_Dir.x + qy * aSegRay.m_Dir.y;
82  const float qq = qx * qx + qy * qy;
83 
84  // solving the quadratic equation for t at the pts of intersection
85  // dd*t^2 + (2*qd)*t + (qq-r^2) = 0
86  const float discriminantsqr = qd * qd - qq;
87  const float discriminantsqr_outer = discriminantsqr + m_outer_radius_squared;
88 
89  // If the discriminant is less than zero, there is no intersection
90  if( discriminantsqr_outer < FLT_EPSILON )
91  return false;
92 
93  // Otherwise check and make sure that the intersections occur on the ray (t
94  // > 0) and return the closer one
95  const float discriminant = sqrt( discriminantsqr_outer );
96  float t = ( -qd - discriminant );
97 
98  if( ( t > FLT_EPSILON ) && ( t < aSegRay.m_Length ) )
99  {
100  if( aNormalOut )
101  {
102  SFVEC2F hitPoint = aSegRay.at( t );
103  *aNormalOut = (hitPoint - m_center) / m_outer_radius;
104  }
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  if( aNormalOut )
121  {
122  const SFVEC2F hitPoint = aSegRay.at( t2_inner );
123 
124  *aNormalOut = ( m_center - hitPoint ) / m_inner_radius;
125  }
126  }
127  else
128  {
129  return false;
130  }
131  }
132  else
133  {
134  return false;
135  }
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: ring_2d.h:56
float m_inner_radius
Definition: ring_2d.h:55
SFVEC2F m_center
Definition: ring_2d.h:54
SFVEC2F m_Dir
Definition: ray.h:110
SFVEC2F at(float t) const
Definition: ray.h:137
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
float m_Length
Definition: ray.h:112
float m_outer_radius_squared
Definition: ring_2d.h:58
SFVEC2F m_Start
Definition: ray.h:107
float m_inner_radius_squared
Definition: ring_2d.h:57

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 RING_2D::Intersects ( const BBOX_2D aBBox) const
overridevirtual

a.Intersects(b) ⇔ !a.Disjoint(b) ⇔ !(a ∩ b = ∅)

Implements OBJECT_2D.

Definition at line 65 of file ring_2d.cpp.

66 {
67  // !TODO: check the inside for a great improvement
69 }
SFVEC2F m_center
Definition: ring_2d.h:54
float m_outer_radius_squared
Definition: ring_2d.h:58
bool Intersects(const BBOX_2D &aBBox) const
Test if a bounding box intersects this box.
Definition: bbox_2d.cpp:211

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

◆ IsBBoxInside()

INTERSECTION_RESULT RING_2D::IsBBoxInside ( const BBOX_2D aBBox) const
overridevirtual

Test this object if it's completely outside, intersects, or is completely inside aBBox.

Returns
INTERSECTION_RESULT

Implements OBJECT_2D.

Definition at line 148 of file ring_2d.cpp.

References MISSES.

◆ IsPointInside()

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

Implements OBJECT_2D.

Definition at line 154 of file ring_2d.cpp.

155 {
156  const SFVEC2F v = m_center - aPoint;
157 
158  const float dot = glm::dot( v, v );
159 
160  if( ( dot <= m_outer_radius_squared ) && ( dot >= m_inner_radius_squared ) )
161  return true;
162 
163  return false;
164 }
SFVEC2F m_center
Definition: ring_2d.h:54
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
float m_outer_radius_squared
Definition: ring_2d.h:58
float m_inner_radius_squared
Definition: ring_2d.h:57

References m_center, m_inner_radius_squared, and m_outer_radius_squared.

◆ Overlaps()

bool RING_2D::Overlaps ( const BBOX_2D aBBox) const
overridevirtual

Test if the box overlaps the object.

Conformance Implements the Overlaps function from the OGC Simple Feature Specification at 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 dimensions 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
aBBoxis the bounding box to test.
Returns
true if the BBox intersects the object or is inside it.

Implements OBJECT_2D.

Definition at line 58 of file ring_2d.cpp.

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

Member Data Documentation

◆ m_bbox

◆ m_boardItem

const BOARD_ITEM& OBJECT_2D::m_boardItem
protectedinherited

Definition at line 114 of file object_2d.h.

Referenced by OBJECT_2D::GetBoardItem().

◆ m_center

SFVEC2F RING_2D::m_center
private

Definition at line 54 of file ring_2d.h.

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

◆ m_centroid

◆ m_inner_radius

float RING_2D::m_inner_radius
private

Definition at line 55 of file ring_2d.h.

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

◆ m_inner_radius_squared

float RING_2D::m_inner_radius_squared
private

Definition at line 57 of file ring_2d.h.

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

◆ m_obj_type

OBJECT_2D_TYPE OBJECT_2D::m_obj_type
protectedinherited

Definition at line 112 of file object_2d.h.

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

◆ m_outer_radius

float RING_2D::m_outer_radius
private

Definition at line 56 of file ring_2d.h.

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

◆ m_outer_radius_squared

float RING_2D::m_outer_radius_squared
private

Definition at line 58 of file ring_2d.h.

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


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