KiCad PCB EDA Suite
Loading...
Searching...
No Matches
SHAPE_RECT Class Reference

#include <shape_rect.h>

Inheritance diagram for SHAPE_RECT:
SHAPE SHAPE_BASE

Public Member Functions

 SHAPE_RECT ()
 Create an empty (0-sized) rectangle.
 
 SHAPE_RECT (const BOX2I &aBox)
 Create a rectangle defined by a BOX2.
 
 SHAPE_RECT (int aX0, int aY0, int aW, int aH)
 Create a rectangle defined by top-left corner (aX0, aY0), width aW and height aH.
 
 SHAPE_RECT (const VECTOR2I &aP0, int aW, int aH)
 Create a rectangle defined by top-left corner aP0, width aW and height aH.
 
 SHAPE_RECT (const VECTOR2I &aP0, const VECTOR2I &aP1)
 Create by two corners.
 
 SHAPE_RECT (const SHAPE_RECT &aOther)
 
SHAPE * Clone () const override
 Return a dynamically allocated copy of the shape.
 
const BOX2I BBox (int aClearance=0) const override
 Compute a bounding box of the shape, with a margin of aClearance a collision.
 
SHAPE_RECT GetInflated (int aOffset) const
 Return a rectangle that is larger by aOffset in all directions, but still centered on the original rectangle.
 
int Diagonal () const
 Return length of the diagonal of the rectangle.
 
int MajorDimension () const
 
int MinorDimension () const
 
bool Collide (const SHAPE *aShape, int aClearance, VECTOR2I *aActual) const override
 Check if the boundary of shape (this) lies closer to the shape aShape than aClearance, indicating a collision.
 
bool Collide (const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
 Check if the boundary of shape (this) lies closer to the shape aShape than aClearance, indicating a collision.
 
bool Collide (const SEG &aSeg, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
 Check if the boundary of shape (this) lies closer to the segment aSeg than aClearance, indicating a collision.
 
const VECTOR2I & GetPosition () const
 
const VECTOR2I GetSize () const
 
int GetWidth () const override
 
int GetHeight () const
 
int GetRadius () const
 
void SetRadius (int aRadius)
 
void Move (const VECTOR2I &aVector) override
 
void Rotate (const EDA_ANGLE &aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
 This function has limited utility for SHAPE_RECT as non-cartesian rotations will distort the rectangle.
 
bool IsSolid () const override
 
const SHAPE_LINE_CHAIN Outline () const
 
virtual const std::string Format (bool aCplusPlus=true) const override
 
void TransformToPolygon (SHAPE_POLY_SET &aBuffer, int aError, ERROR_LOC aErrorLoc) const override
 Fills a SHAPE_POLY_SET with a polygon representation of this shape.
 
void Normalize ()
 Ensure that the height and width are positive.
 
int GetClearance (const SHAPE *aOther) const
 Return the actual minimum distance between two shapes.
 
bool IsNull () const
 Return true if the shape is a null shape.
 
virtual bool Collide (const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
 Check if the boundary of shape (this) lies closer to the point aP than aClearance, indicating a collision.
 
virtual VECTOR2I Centre () const
 Compute a center-of-mass of the shape.
 
virtual int Distance (const VECTOR2I &aP) const
 Returns the minimum distance from a given point to this shape.
 
virtual SEG::ecoord SquaredDistance (const VECTOR2I &aP, bool aOutlineOnly=false) const
 
bool NearestPoints (const SHAPE *aOther, VECTOR2I &aPtThis, VECTOR2I &aPtOther) const
 Return the two points that mark the closest distance between this shape and aOther.
 
virtual bool PointInside (const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const
 Check if point aP lies inside a closed shape.
 
virtual VECTOR2I GetStart () const
 
virtual VECTOR2I GetEnd () const
 
virtual void SetWidth (int aWidth)
 
virtual bool Parse (std::stringstream &aStream)
 
FACET * NewFacet ()
 
SGNODE * CalcShape (SGNODE *aParent, SGNODE *aColor, WRL1_ORDER aVertexOrder, float aCreaseLimit=0.74317, bool isVRML2=false)
 
SHAPE_TYPE Type () const
 Return the type of the shape.
 
wxString TypeName () const
 
virtual bool HasIndexableSubshapes () const
 
virtual size_t GetIndexableSubshapeCount () const
 
virtual void GetIndexableSubshapes (std::vector< const SHAPE * > &aSubshapes) const
 

Static Public Attributes

static const int MIN_PRECISION_IU = 4
 This is the minimum precision for all the points in a shape.
 

Protected Types

typedef VECTOR2I::extended_type ecoord
 

Protected Attributes

SHAPE_TYPE m_type
 type of our shape
 

Private Attributes

VECTOR2I m_p0
 Top-left corner.
 
int m_w
 Width.
 
int m_h
 Height.
 
int m_radius
 Corner radius.
 
std::list< FACET * > facets
 

Detailed Description

Definition at line 34 of file shape_rect.h.

Member Typedef Documentation

◆ ecoord

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 311 of file shape.h.

Constructor & Destructor Documentation

◆ SHAPE_RECT() [1/6]

SHAPE_RECT::SHAPE_RECT ( )
inline

Create an empty (0-sized) rectangle.

Definition at line 40 of file shape_rect.h.

References m_h, m_radius, m_w, SH_RECT, and SHAPE::SHAPE().

Referenced by Clone(), GetInflated(), and SHAPE_RECT().

◆ SHAPE_RECT() [2/6]

SHAPE_RECT::SHAPE_RECT ( const BOX2I & aBox)
inline

Create a rectangle defined by a BOX2.

Definition at line 50 of file shape_rect.h.

References GetHeight(), GetPosition(), GetWidth(), m_h, m_p0, m_radius, m_w, SH_RECT, and SHAPE::SHAPE().

◆ SHAPE_RECT() [3/6]

SHAPE_RECT::SHAPE_RECT ( int aX0,
int aY0,
int aW,
int aH )
inline

Create a rectangle defined by top-left corner (aX0, aY0), width aW and height aH.

Definition at line 61 of file shape_rect.h.

References m_h, m_p0, m_radius, m_w, SH_RECT, and SHAPE::SHAPE().

◆ SHAPE_RECT() [4/6]

SHAPE_RECT::SHAPE_RECT ( const VECTOR2I & aP0,
int aW,
int aH )
inline

Create a rectangle defined by top-left corner aP0, width aW and height aH.

Definition at line 72 of file shape_rect.h.

References m_h, m_p0, m_radius, m_w, SH_RECT, and SHAPE::SHAPE().

◆ SHAPE_RECT() [5/6]

SHAPE_RECT::SHAPE_RECT ( const VECTOR2I & aP0,
const VECTOR2I & aP1 )
inline

Create by two corners.

Definition at line 83 of file shape_rect.h.

References m_h, m_p0, m_radius, m_w, SH_RECT, and SHAPE::SHAPE().

◆ SHAPE_RECT() [6/6]

SHAPE_RECT::SHAPE_RECT ( const SHAPE_RECT & aOther)
inline

Definition at line 91 of file shape_rect.h.

References m_h, m_p0, m_radius, m_w, SH_RECT, SHAPE::SHAPE(), and SHAPE_RECT().

Member Function Documentation

◆ BBox()

const BOX2I SHAPE_RECT::BBox ( int aClearance = 0) const
inlineoverridevirtual

Compute a bounding box of the shape, with a margin of aClearance a collision.

Parameters
aClearancehow much the bounding box is expanded wrs to the minimum enclosing rectangle for the shape.
Returns
the bounding box.

Implements SHAPE.

Definition at line 105 of file shape_rect.h.

References m_h, m_p0, and m_w.

Referenced by Collide(), and Collide().

◆ CalcShape()

◆ Centre()

◆ Clone()

SHAPE * SHAPE_RECT::Clone ( ) const
inlineoverridevirtual

Return a dynamically allocated copy of the shape.

Return values
copyof the shape

Reimplemented from SHAPE.

Definition at line 99 of file shape_rect.h.

References SHAPE::SHAPE(), and SHAPE_RECT().

◆ Collide() [1/4]

virtual bool SHAPE::Collide ( const VECTOR2I & aP,
int aClearance = 0,
int * aActual = nullptr,
VECTOR2I * aLocation = nullptr ) const
inlinevirtualinherited

Check if the boundary of shape (this) lies closer to the point aP than aClearance, indicating a collision.

Parameters
[in]aPis the position to check for a collision.
aClearanceis the allowable tolerance of the collision comparison.
[out]aActualan optional pointer to an int to store the actual distance in the event of a collision.
[out]aLocationan option pointer to a point to store a nearby location in the event of a collision.
Returns
true, if there is a collision.

Reimplemented in SHAPE_ARC, SHAPE_LINE_CHAIN, SHAPE_LINE_CHAIN_BASE, SHAPE_POLY_SET, and SHAPE_SEGMENT.

Definition at line 181 of file shape.h.

References Collide().

Referenced by BOOST_AUTO_TEST_CASE(), DRC_RTREE::CheckColliding(), DRC_RTREE::CheckColliding(), FOOTPRINT::CheckShortingPads(), CN_ZONE_LAYER::Collide(), Collide(), SHAPE_ARC::Collide(), SHAPE_COMPOUND::Collide(), SHAPE_COMPOUND::Collide(), SHAPE_ELLIPSE::Collide(), SHAPE_POLY_SET::Collide(), SHAPE_RECT::Collide(), SHAPE_RECT::Collide(), SHAPE_SEGMENT::Collide(), SHAPE_SEGMENT::Collide(), collide(), PNS::ITEM::collideSimple(), PNS::TOPOLOGY::findLinesFromVia(), SCH_LINE::HitTest(), EDA_SHAPE::hitTest(), PCB_SELECTION_TOOL::hitTestDistance(), PNS::SHOVE::onCollidingVia(), PNS::SHOVE::onReverseCollidingVia(), PNS::HIT_VISITOR::operator()(), PNS::VIA::PushoutForce(), DRC_RTREE::QueryColliding(), DRC_RTREE::QueryColliding(), DRC_TEST_PROVIDER_SILK_CLEARANCE::Run(), KIGEOM::ShapeHitTest(), PNS::OPTIMIZER::smartPadsSingle(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::testAgainstEdge(), DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::testItemAgainstItem(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testSingleLayerItemAgainstItem(), and DIALOG_TRACK_VIA_PROPERTIES::TransferDataFromWindow().

◆ Collide() [2/4]

bool SHAPE_RECT::Collide ( const SEG & aSeg,
int aClearance = 0,
int * aActual = nullptr,
VECTOR2I * aLocation = nullptr ) const
overridevirtual

Check if the boundary of shape (this) lies closer to the segment aSeg than aClearance, indicating a collision.

Parameters
[in]aSegis the segment to compare.
aClearanceis the allowable tolerance of the collision comparison.
[out]aActualan optional pointer to an int to be updated with the actual distance int the event of a collision.
[out]aLocationan option pointer to a point to store a nearby location in the event of a collision.
Returns
true, if there is a collision.

Implements SHAPE.

Definition at line 27 of file shape_rect.cpp.

References SEG::A, SEG::B, BBox(), SHAPE_LINE_CHAIN::Collide(), BOX2< Vec >::Contains(), VECTOR2< int32_t >::ECOORD_MAX, m_h, m_p0, m_radius, m_w, SEG::NearestPoint(), Outline(), SEG::Square(), and SEG::SquaredDistance().

◆ Collide() [3/4]

bool SHAPE_RECT::Collide ( const SHAPE * aShape,
int aClearance,
VECTOR2I * aActual ) const
inlineoverridevirtual

Check if the boundary of shape (this) lies closer to the shape aShape than aClearance, indicating a collision.

Parameters
aShapeshape to check collision against
aClearanceminimum clearance
[out]aActualis the actual collision point
Returns
true, if there is a collision.

Reimplemented from SHAPE.

Definition at line 147 of file shape_rect.h.

References SHAPE::Collide(), and SHAPE::SHAPE().

Referenced by Collide(), Collide(), SCH_SELECTION_TOOL::GuessSelectionCandidates(), and SCH_JUNCTION::HitTest().

◆ Collide() [4/4]

bool SHAPE_RECT::Collide ( const SHAPE * aShape,
int aClearance = 0,
int * aActual = nullptr,
VECTOR2I * aLocation = nullptr ) const
inlineoverridevirtual

Check if the boundary of shape (this) lies closer to the shape aShape than aClearance, indicating a collision.

Parameters
aShapeshape to check collision against
aClearanceminimum clearance
[out]aActualan optional pointer to an int to store the actual distance in the event of a collision.
[out]aLocationan option pointer to a point to store a nearby location in the event of a collision.
Returns
true, if there is a collision.

Reimplemented from SHAPE.

Definition at line 152 of file shape_rect.h.

References SHAPE::Collide(), and SHAPE::SHAPE().

◆ Diagonal()

int SHAPE_RECT::Diagonal ( ) const
inline

Return length of the diagonal of the rectangle.

Returns
diagonal length

Definition at line 132 of file shape_rect.h.

References VECTOR2< T >::EuclideanNorm(), m_h, and m_w.

◆ Distance()

int SHAPE::Distance ( const VECTOR2I & aP) const
virtualinherited

Returns the minimum distance from a given point to this shape.

Always returns zero if the point is inside a closed shape and aOutlineOnly is false.

Parameters
aPis the point to test
Returns
the distance from the shape to aP

Reimplemented in SHAPE_COMPOUND, and SHAPE_LINE_CHAIN.

Definition at line 105 of file shape.cpp.

References SquaredDistance().

◆ Format()

const std::string SHAPE_RECT::Format ( bool aCplusPlus = true) const
overridevirtual

Reimplemented from SHAPE.

Definition at line 108 of file shape_rect.cpp.

References m_h, m_p0, m_radius, and m_w.

◆ GetClearance()

int SHAPE::GetClearance ( const SHAPE * aOther) const
inherited

Return the actual minimum distance between two shapes.

Return values
distancein IU

POLY_SETs contain a bunch of polygons that are triangulated. But there are way more triangles than necessary for collision detection. Triangles check three vertices each but for the outline, we only need one. These are also fractured, so we don't need to worry about holes

Definition at line 51 of file shape.cpp.

References SHAPE_POLY_SET::COutline(), SHAPE_BASE::GetIndexableSubshapeCount(), SHAPE_BASE::GetIndexableSubshapes(), SHAPE_POLY_SET::OutlineCount(), SH_POLY_SET, SHAPE(), and SHAPE_BASE::Type().

Referenced by BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ GetEnd()

virtual VECTOR2I SHAPE::GetEnd ( ) const
inlinevirtualinherited

Reimplemented in SHAPE_ARC, and SHAPE_SEGMENT.

Definition at line 297 of file shape.h.

◆ GetHeight()

int SHAPE_RECT::GetHeight ( ) const
inline
Returns
the height of the rectangle.

Definition at line 188 of file shape_rect.h.

References m_h.

Referenced by KIGFX::PCB_PAINTER::draw(), KIGEOM::GetPoint(), OUTSET_ROUTINE::ProcessItem(), and SHAPE_RECT().

◆ GetIndexableSubshapeCount()

virtual size_t SHAPE_BASE::GetIndexableSubshapeCount ( ) const
inlinevirtualinherited

Reimplemented in SHAPE_COMPOUND, and SHAPE_POLY_SET.

Definition at line 111 of file shape.h.

Referenced by SHAPE::GetClearance().

◆ GetIndexableSubshapes()

virtual void SHAPE_BASE::GetIndexableSubshapes ( std::vector< const SHAPE * > & aSubshapes) const
inlinevirtualinherited

Reimplemented in SHAPE_COMPOUND, and SHAPE_POLY_SET.

Definition at line 113 of file shape.h.

Referenced by SHAPE_COMPOUND::AddShape(), and SHAPE::GetClearance().

◆ GetInflated()

SHAPE_RECT SHAPE_RECT::GetInflated ( int aOffset) const
inline

Return a rectangle that is larger by aOffset in all directions, but still centered on the original rectangle.

Definition at line 116 of file shape_rect.h.

References m_h, m_p0, m_radius, m_w, and SHAPE_RECT().

Referenced by ROUNDRECT::OutsetFrom().

◆ GetPosition()

◆ GetRadius()

int SHAPE_RECT::GetRadius ( ) const
inline
Returns
the corner radius of the rectangle.

Definition at line 196 of file shape_rect.h.

References m_radius.

Referenced by BOOST_AUTO_TEST_CASE(), Collide(), Collide(), Collide(), Collide(), and Collide().

◆ GetSize()

◆ GetStart()

virtual VECTOR2I SHAPE::GetStart ( ) const
inlinevirtualinherited

Reimplemented in SHAPE_ARC, and SHAPE_SEGMENT.

Definition at line 296 of file shape.h.

Referenced by CADSTAR_PCB_ARCHIVE_LOADER::loadCoppers().

◆ GetWidth()

int SHAPE_RECT::GetWidth ( ) const
inlineoverridevirtual
Returns
the width of the rectangle.

Reimplemented from SHAPE.

Definition at line 180 of file shape_rect.h.

References m_w.

Referenced by KIGFX::PCB_PAINTER::draw(), KIGEOM::GetPoint(), OUTSET_ROUTINE::ProcessItem(), and SHAPE_RECT().

◆ HasIndexableSubshapes()

virtual bool SHAPE_BASE::HasIndexableSubshapes ( ) const
inlinevirtualinherited

Reimplemented in SHAPE_COMPOUND, and SHAPE_POLY_SET.

Definition at line 106 of file shape.h.

◆ IsNull()

bool SHAPE::IsNull ( ) const
inlineinherited

Return true if the shape is a null shape.

Return values
trueif null :-)

Definition at line 164 of file shape.h.

References SHAPE_BASE::m_type, and SH_NULL.

◆ IsSolid()

bool SHAPE_RECT::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 229 of file shape_rect.h.

◆ MajorDimension()

int SHAPE_RECT::MajorDimension ( ) const
inline

Definition at line 137 of file shape_rect.h.

References m_h, and m_w.

◆ MinorDimension()

int SHAPE_RECT::MinorDimension ( ) const
inline

Definition at line 142 of file shape_rect.h.

References m_h, and m_w.

◆ Move()

void SHAPE_RECT::Move ( const VECTOR2I & aVector)
inlineoverridevirtual

Implements SHAPE.

Definition at line 206 of file shape_rect.h.

References m_p0.

◆ NearestPoints()

bool SHAPE::NearestPoints ( const SHAPE * aOther,
VECTOR2I & aPtThis,
VECTOR2I & aPtOther ) const
inherited

◆ NewFacet()

FACET * SHAPE::NewFacet ( )
inherited

◆ Normalize()

void SHAPE_RECT::Normalize ( )

Ensure that the height and width are positive.

Definition at line 160 of file shape_rect.cpp.

References m_h, m_p0, and m_w.

◆ Outline()

◆ Parse()

bool SHAPE::Parse ( std::stringstream & aStream)
virtualinherited

Reimplemented in SHAPE_LINE_CHAIN, and SHAPE_POLY_SET.

Definition at line 36 of file shape.cpp.

◆ PointInside()

bool SHAPE::PointInside ( const VECTOR2I & aPt,
int aAccuracy = 0,
bool aUseBBoxCache = false ) const
virtualinherited

Check if point aP lies inside a closed shape.

Always returns false if this shape is not closed.

Parameters
aPtpoint to check.
aAccuracyis the allowable tolerance of the cheack.
aUseBBoxCachegives better performance if the bounding box caches have been generated.
Returns
true if the point is inside the shape (edge is not treated as being inside).

Reimplemented in SHAPE_ELLIPSE, SHAPE_LINE_CHAIN, SHAPE_LINE_CHAIN_BASE, and SHAPE_POLY_SET.

Definition at line 123 of file shape.cpp.

References SHAPE_POLY_SET::COutline(), ERROR_INSIDE, SHAPE_POLY_SET::OutlineCount(), SHAPE_LINE_CHAIN::PointInside(), and TransformToPolygon().

◆ Rotate()

void SHAPE_RECT::Rotate ( const EDA_ANGLE & aAngle,
const VECTOR2I & aCenter = { 0, 0 } )
inlineoverridevirtual

This function has limited utility for SHAPE_RECT as non-cartesian rotations will distort the rectangle.

If you might need to handle non-90° rotations then the SHAPE_RECT should first be converted to a SHAPE_SIMPLE which can then be free-rotated.

Implements SHAPE.

Definition at line 216 of file shape_rect.h.

◆ SetRadius()

void SHAPE_RECT::SetRadius ( int aRadius)
inline

◆ SetWidth()

virtual void SHAPE::SetWidth ( int aWidth)
inlinevirtualinherited

Reimplemented in SHAPE_ARC, SHAPE_LINE_CHAIN, and SHAPE_SEGMENT.

Definition at line 300 of file shape.h.

◆ SquaredDistance()

SEG::ecoord SHAPE::SquaredDistance ( const VECTOR2I & aP,
bool aOutlineOnly = false ) const
virtualinherited

◆ TransformToPolygon()

void SHAPE_RECT::TransformToPolygon ( SHAPE_POLY_SET & aBuffer,
int aError,
ERROR_LOC aErrorLoc ) const
overridevirtual

Fills a SHAPE_POLY_SET with a polygon representation of this shape.

Parameters
[out]aBufferwill be filled with the polygonal representation of this shape.
aErrorcontrols the maximum allowed deviation when converting rounded shapes to segments
aErrorLoccontrols where the error is placed when approximating rounded shapes

Implements SHAPE.

Definition at line 128 of file shape_rect.cpp.

References SHAPE_LINE_CHAIN::Append(), m_h, m_p0, m_radius, m_w, SHAPE_POLY_SET::NewOutline(), SHAPE_POLY_SET::Outline(), SHAPE_LINE_CHAIN::SetClosed(), and ROUNDRECT::TransformToPolygon().

Referenced by Outline().

◆ Type()

◆ TypeName()

wxString SHAPE_BASE::TypeName ( ) const
inlineinherited

Definition at line 101 of file shape.h.

References m_type, and SHAPE_TYPE_asString().

Referenced by Collide(), Collide(), Collide(), Collide(), Collide(), Collide(), Collide(), and Collide().

Member Data Documentation

◆ facets

std::list< FACET* > SHAPE::facets
privateinherited

Definition at line 140 of file wrlfacet.h.

Referenced by CalcShape(), and NewFacet().

◆ m_h

◆ m_p0

VECTOR2I SHAPE_RECT::m_p0
private

◆ m_radius

int SHAPE_RECT::m_radius
private

◆ m_type

SHAPE_TYPE SHAPE_BASE::m_type
protectedinherited

type of our shape

Definition at line 117 of file shape.h.

Referenced by SHAPE::Format(), SHAPE::IsNull(), SHAPE_BASE(), Type(), and TypeName().

◆ m_w

◆ MIN_PRECISION_IU

const int SHAPE::MIN_PRECISION_IU = 4
staticinherited

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