KiCad PCB EDA Suite
CFILLEDCIRCLE2D Class Reference

#include <cfilledcircle2d.h>

Inheritance diagram for CFILLEDCIRCLE2D:
COBJECT2D

Public Member Functions

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

Detailed Description

Definition at line 35 of file cfilledcircle2d.h.

Constructor & Destructor Documentation

◆ CFILLEDCIRCLE2D()

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

Definition at line 34 of file cfilledcircle2d.cpp.

37 {
38  wxASSERT( aRadius > 0.0f ); // If that happens, it should be handled before create this circle
39 
40  m_center = aCenter;
41  m_radius = aRadius;
42  m_radius_squared = aRadius * aRadius;
43 
44  m_bbox.Reset();
45  m_bbox.Set( m_center - SFVEC2F( aRadius, aRadius ),
46  m_center + SFVEC2F( aRadius, aRadius ) );
49 
50  wxASSERT( m_bbox.IsInitialized() );
51 }
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
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

References FILLED_CIRCLE, CBBOX2D::GetCenter(), CBBOX2D::IsInitialized(), COBJECT2D::m_bbox, m_center, COBJECT2D::m_centroid, m_radius, m_radius_squared, CBBOX2D::Reset(), 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::reload().

◆ GetCenter()

const SFVEC2F& CFILLEDCIRCLE2D::GetCenter ( ) const
inline

Definition at line 39 of file cfilledcircle2d.h.

39 { return m_center; }

References m_center.

Referenced by C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer().

◆ GetCentroid()

const SFVEC2F& COBJECT2D::GetCentroid ( ) const
inlineinherited

◆ GetObjectType()

◆ GetRadius()

float CFILLEDCIRCLE2D::GetRadius ( ) const
inline

Definition at line 38 of file cfilledcircle2d.h.

38 { return m_radius; }

References m_radius.

Referenced by C3D_RENDER_OGL_LEGACY::add_object_to_triangle_layer().

◆ GetRadiusSquared()

float CFILLEDCIRCLE2D::GetRadiusSquared ( ) const
inline

Definition at line 40 of file cfilledcircle2d.h.

40 { return m_radius_squared; }

References m_radius_squared.

◆ Intersect()

bool CFILLEDCIRCLE2D::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 67 of file cfilledcircle2d.cpp.

70 {
71  wxASSERT( aOutT );
72  wxASSERT( aNormalOut );
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 - m_radius_squared));
87 
88  // If the discriminant is less than zero, there is no intersection
89  if( discriminantsqr < FLT_EPSILON )
90  return false;
91 
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);
96  const float t1 = (-qd - discriminant);
97  const float t2 = (-qd + discriminant);
98  float t;
99 
100 
101  if( (t1 > 0.0f) && (t1 < aSegRay.m_Length) )
102  t = t1;
103  else
104  {
105  if( (t2 > 0.0f) && (t2 < aSegRay.m_Length) )
106  t = t2;
107  else
108  return false; // Neither intersection was in the ray's half line.
109  }
110 
111  wxASSERT( (t > 0.0f) && (t <= aSegRay.m_Length) );
112 
113  // Convert the intersection to a normalized 0.0 .. 1.0
114  *aOutT = t / aSegRay.m_Length;
115 
116  const SFVEC2F hitPoint = aSegRay.at( t );
117 
118  *aNormalOut = (hitPoint - m_center) / m_radius;
119 
120  return true;
121 }
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

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

◆ Intersects()

bool CFILLEDCIRCLE2D::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 61 of file cfilledcircle2d.cpp.

62 {
63  return aBBox.Intersects( m_center, m_radius_squared );
64 }
bool Intersects(const CBBOX2D &aBBox) const
Function Intersects test if a bounding box intersects this box.
Definition: cbbox2d.cpp:213

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

◆ IsBBoxInside()

INTERSECTION_RESULT CFILLEDCIRCLE2D::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 124 of file cfilledcircle2d.cpp.

125 {
126  if( !m_bbox.Intersects( aBBox ) )
128 
129  SFVEC2F v[4];
130 
131  v[0] = aBBox.Min() - m_center;
132  v[1] = aBBox.Max() - m_center;
133  v[2] = SFVEC2F( aBBox.Min().x, aBBox.Max().y ) - m_center;
134  v[3] = SFVEC2F( aBBox.Max().x, aBBox.Min().y ) - m_center;
135 
136  float s[4];
137 
138  s[0] = v[0].x * v[0].x + v[0].y * v[0].y;
139  s[1] = v[1].x * v[1].x + v[1].y * v[1].y;
140  s[2] = v[2].x * v[2].x + v[2].y * v[2].y;
141  s[3] = v[3].x * v[3].x + v[3].y * v[3].y;
142 
143  bool isInside[4];
144 
145  isInside[0] = s[0] <= m_radius_squared;
146  isInside[1] = s[1] <= m_radius_squared;
147  isInside[2] = s[2] <= m_radius_squared;
148  isInside[3] = s[3] <= m_radius_squared;
149 
150  // Check if all points are inside the circle
151  if( isInside[0] &&
152  isInside[1] &&
153  isInside[2] &&
154  isInside[3] )
156 
157  // Check if any point is inside the circle
158  if( isInside[0] ||
159  isInside[1] ||
160  isInside[2] ||
161  isInside[3] )
163 
165 }
const SFVEC2F & Min() const
Function Min return the minimun vertex pointer.
Definition: cbbox2d.h:176
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
bool Intersects(const CBBOX2D &aBBox) const
Function Intersects test if a bounding box intersects this box.
Definition: cbbox2d.cpp:213
const SFVEC2F & Max() const
Function Max return the maximum vertex pointer.
Definition: cbbox2d.h:183
CBBOX2D m_bbox
Definition: cobject2d.h:65

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

◆ IsPointInside()

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

Implements COBJECT2D.

Definition at line 168 of file cfilledcircle2d.cpp.

169 {
170  const SFVEC2F v = m_center - aPoint;
171 
172  if( (v.x * v.x + v.y * v.y) <= m_radius_squared )
173  return true;
174 
175  return false;
176 }
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45

References m_center, and m_radius_squared.

◆ Overlaps()

bool CFILLEDCIRCLE2D::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 54 of file cfilledcircle2d.cpp.

55 {
56  // NOT IMPLEMENTED
57  return false;
58 }

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

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

float CFILLEDCIRCLE2D::m_radius
private

Definition at line 44 of file cfilledcircle2d.h.

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

◆ m_radius_squared

float CFILLEDCIRCLE2D::m_radius_squared
private

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