KiCad PCB EDA Suite
FILLED_CIRCLE_2D Class Reference

#include <filled_circle_2d.h>

Inheritance diagram for FILLED_CIRCLE_2D:
OBJECT_2D

Public Member Functions

 FILLED_CIRCLE_2D (const SFVEC2F &aCenter, float aRadius, const BOARD_ITEM &aBoardItem)
 
float GetRadius () const
 
const SFVEC2FGetCenter () const
 
float GetRadiusSquared () const
 
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 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_radius
 
float m_radius_squared
 

Detailed Description

Definition at line 34 of file filled_circle_2d.h.

Constructor & Destructor Documentation

◆ FILLED_CIRCLE_2D()

FILLED_CIRCLE_2D::FILLED_CIRCLE_2D ( const SFVEC2F aCenter,
float  aRadius,
const BOARD_ITEM aBoardItem 
)

Definition at line 35 of file filled_circle_2d.cpp.

36  :
38 {
39  wxASSERT( aRadius > 0.0f ); // If that happens, it should be handled before create this circle
40 
41  m_center = aCenter;
42  m_radius = aRadius;
43  m_radius_squared = aRadius * aRadius;
44 
45  m_bbox.Reset();
46  m_bbox.Set( m_center - SFVEC2F( aRadius, aRadius ),
47  m_center + SFVEC2F( aRadius, aRadius ) );
50 
51  wxASSERT( m_bbox.IsInitialized() );
52 }
BBOX_2D m_bbox
Definition: object_2d.h:110
SFVEC2F GetCenter() const
Definition: bbox_2d.cpp:119
void Set(const SFVEC2F &aPbMin, const SFVEC2F &aPbMax)
Set bounding box with new parameters.
Definition: bbox_2d.cpp:61
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
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 FILLED_CIRCLE, BBOX_2D::GetCenter(), BBOX_2D::IsInitialized(), OBJECT_2D::m_bbox, m_center, OBJECT_2D::m_centroid, m_radius, m_radius_squared, BBOX_2D::Reset(), 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& FILLED_CIRCLE_2D::GetCenter ( ) const
inline

Definition at line 40 of file filled_circle_2d.h.

40 { return m_center; }

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().

◆ GetObjectType()

◆ GetRadius()

float FILLED_CIRCLE_2D::GetRadius ( ) const
inline

Definition at line 39 of file filled_circle_2d.h.

39 { return m_radius; }

References m_radius.

Referenced by RENDER_3D_OPENGL::addObjectTriangles().

◆ GetRadiusSquared()

float FILLED_CIRCLE_2D::GetRadiusSquared ( ) const
inline

Definition at line 41 of file filled_circle_2d.h.

41 { return m_radius_squared; }

References m_radius_squared.

◆ Intersect()

bool FILLED_CIRCLE_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 68 of file filled_circle_2d.cpp.

69 {
70  // This code used directly from Steve Marschner's CS667 framework
71  // http://cs665pd.googlecode.com/svn/trunk/photon/sphere.cpp
72 
73  // Compute some factors used in computation
74  const float qx = aSegRay.m_Start.x - m_center.x;
75  const float qy = aSegRay.m_Start.y - m_center.y;
76 
77  const float qd = qx * aSegRay.m_Dir.x + qy * aSegRay.m_Dir.y;
78  const float qq = qx * qx + qy * qy;
79 
80  // solving the quadratic equation for t at the pts of intersection
81  // dd*t^2 + (2*qd)*t + (qq-r^2) = 0
82  const float discriminantsqr = ( qd * qd - ( qq - m_radius_squared ) );
83 
84  // If the discriminant is less than zero, there is no intersection
85  if( discriminantsqr < FLT_EPSILON )
86  return false;
87 
88  // Otherwise check and make sure that the intersections occur on the ray (t > 0) and
89  // return the closer one.
90  const float discriminant = sqrt( discriminantsqr );
91  const float t1 = ( -qd - discriminant );
92  const float t2 = ( -qd + discriminant );
93  float t;
94 
95  if( ( t1 > 0.0f ) && ( t1 < aSegRay.m_Length ) )
96  {
97  t = t1;
98  }
99  else
100  {
101  if( ( t2 > 0.0f ) && ( t2 < aSegRay.m_Length ) )
102  t = t2;
103  else
104  return false; // Neither intersection was in the ray's half line.
105  }
106 
107  wxASSERT( ( t > 0.0f ) && ( t <= aSegRay.m_Length ) );
108 
109  // Convert the intersection to a normalized 0.0 .. 1.0
110  if( aOutT )
111  *aOutT = t / aSegRay.m_Length;
112 
113  const SFVEC2F hitPoint = aSegRay.at( t );
114 
115  if( aNormalOut )
116  *aNormalOut = (hitPoint - m_center) / m_radius;
117 
118  return true;
119 }
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
SFVEC2F m_Start
Definition: ray.h:107

References RAYSEG2D::at(), m_center, RAYSEG2D::m_Dir, RAYSEG2D::m_Length, m_radius, m_radius_squared, and RAYSEG2D::m_Start.

◆ Intersects()

bool FILLED_CIRCLE_2D::Intersects ( const BBOX_2D aBBox) const
overridevirtual

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

Implements OBJECT_2D.

Definition at line 62 of file filled_circle_2d.cpp.

63 {
64  return aBBox.Intersects( m_center, m_radius_squared );
65 }
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_radius_squared.

◆ IsBBoxInside()

INTERSECTION_RESULT FILLED_CIRCLE_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 122 of file filled_circle_2d.cpp.

123 {
124  if( !m_bbox.Intersects( aBBox ) )
126 
127  SFVEC2F v[4];
128 
129  v[0] = aBBox.Min() - m_center;
130  v[1] = aBBox.Max() - m_center;
131  v[2] = SFVEC2F( aBBox.Min().x, aBBox.Max().y ) - m_center;
132  v[3] = SFVEC2F( aBBox.Max().x, aBBox.Min().y ) - m_center;
133 
134  float s[4];
135 
136  s[0] = v[0].x * v[0].x + v[0].y * v[0].y;
137  s[1] = v[1].x * v[1].x + v[1].y * v[1].y;
138  s[2] = v[2].x * v[2].x + v[2].y * v[2].y;
139  s[3] = v[3].x * v[3].x + v[3].y * v[3].y;
140 
141  bool isInside[4];
142 
143  isInside[0] = s[0] <= m_radius_squared;
144  isInside[1] = s[1] <= m_radius_squared;
145  isInside[2] = s[2] <= m_radius_squared;
146  isInside[3] = s[3] <= m_radius_squared;
147 
148  // Check if all points are inside the circle
149  if( isInside[0] && isInside[1] && isInside[2] && isInside[3] )
151 
152  // Check if any point is inside the circle
153  if( isInside[0] || isInside[1] || isInside[2] || isInside[3] )
155 
157 }
BBOX_2D m_bbox
Definition: object_2d.h:110
const SFVEC2F & Max() const
Definition: bbox_2d.h:172
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
const SFVEC2F & Min() const
Definition: bbox_2d.h:167
bool Intersects(const BBOX_2D &aBBox) const
Test if a bounding box intersects this box.
Definition: bbox_2d.cpp:211

References FULL_INSIDE, INTERSECTS, BBOX_2D::Intersects(), OBJECT_2D::m_bbox, m_center, m_radius_squared, BBOX_2D::Max(), BBOX_2D::Min(), and MISSES.

◆ IsPointInside()

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

Implements OBJECT_2D.

Definition at line 160 of file filled_circle_2d.cpp.

161 {
162  const SFVEC2F v = m_center - aPoint;
163 
164  if( ( v.x * v.x + v.y * v.y ) <= m_radius_squared )
165  return true;
166 
167  return false;
168 }
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42

References m_center, and m_radius_squared.

◆ Overlaps()

bool FILLED_CIRCLE_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 55 of file filled_circle_2d.cpp.

56 {
57  // NOT IMPLEMENTED, why?
58  return false;
59 }

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 FILLED_CIRCLE_2D::m_center
private

◆ m_centroid

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

float FILLED_CIRCLE_2D::m_radius
private

Definition at line 51 of file filled_circle_2d.h.

Referenced by FILLED_CIRCLE_2D(), GetRadius(), and Intersect().

◆ m_radius_squared

float FILLED_CIRCLE_2D::m_radius_squared
private

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