KiCad PCB EDA Suite
Loading...
Searching...
No Matches
shape_simple.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015-2022 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef __SHAPE_SIMPLE_H
25#define __SHAPE_SIMPLE_H
26
27#include <geometry/seg.h>
28#include <geometry/shape.h>
30#include <math/box2.h>
31#include <math/vector2d.h>
32
42{
43public:
49 {
50 m_points.SetClosed( true );
51 }
52
55 m_points( aPoly )
56 {
57 m_points.SetClosed( true );
58 }
59
60 SHAPE_SIMPLE( const SHAPE_SIMPLE& aOther ) :
62 {}
63
64 SHAPE* Clone() const override
65 {
66 return new SHAPE_SIMPLE( *this );
67 }
68
72 void Clear()
73 {
75 }
76
78 const BOX2I BBox( int aClearance = 0 ) const override
79 {
80 return m_points.BBox( aClearance );
81 }
82
88 int PointCount() const
89 {
90 return m_points.PointCount();
91 }
92
102 const VECTOR2I& CPoint( int aIndex ) const
103 {
104 return m_points.CPoint( aIndex );
105 }
106
113 const VECTOR2D CDPoint( int aIndex ) const
114 {
115 const VECTOR2I& v = CPoint( aIndex );
116 return VECTOR2D( v.x, v.y );
117 }
118
125 {
126 return m_points;
127 }
128
135 void Append( int aX, int aY )
136 {
137 VECTOR2I v( aX, aY );
138 Append( v );
139 }
140
146 void Append( const VECTOR2I& aP )
147 {
148 m_points.Append( aP );
149 }
150
152 bool Collide( const SEG& aSeg, int aClearance = 0, int* aActual = nullptr,
153 VECTOR2I* aLocation = nullptr ) const override
154 {
155 return m_points.Collide( aSeg, aClearance, aActual, aLocation );
156 }
157
158 void Rotate( const EDA_ANGLE& aAngle, const VECTOR2I& aCenter = { 0, 0 } ) override
159 {
160 m_points.Rotate( aAngle, aCenter );
161 }
162
163 void Move( const VECTOR2I& aVector ) override
164 {
165 m_points.Move( aVector );
166 }
167
168 bool IsSolid() const override
169 {
170 return true;
171 }
172
173 virtual const VECTOR2I GetPoint( int aIndex ) const override { return m_points.CPoint(aIndex); }
174 virtual const SEG GetSegment( int aIndex ) const override { return m_points.CSegment(aIndex); }
175 virtual size_t GetPointCount() const override { return m_points.PointCount(); }
176 virtual size_t GetSegmentCount() const override { return m_points.SegmentCount(); }
177
178 bool IsClosed() const override
179 {
180 return true;
181 }
182
183 void TransformToPolygon( SHAPE_POLY_SET& aBuffer, int aError,
184 ERROR_LOC aErrorLoc ) const override;
185
186private:
187 // vertices
189};
190
191#endif // __SHAPE_SIMPLE_H
Definition: seg.h:42
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void Move(const VECTOR2I &aVector) override
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
int PointCount() const
Return the number of points (vertices) in this line chain.
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if point aP lies closer to us than aClearance.
void Clear()
Remove all points from the line chain.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Rotate all vertices by a given angle.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
int SegmentCount() const
Return the number of segments in this line chain.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
Represent a set of closed polygons.
Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.
Definition: shape_simple.h:42
void Clear()
Remove all points from the polygon.
Definition: shape_simple.h:72
const SHAPE_LINE_CHAIN & Vertices() const
Return the list of vertices defining this simple polygon.
Definition: shape_simple.h:124
virtual const SEG GetSegment(int aIndex) const override
Definition: shape_simple.h:174
virtual const VECTOR2I GetPoint(int aIndex) const override
Definition: shape_simple.h:173
void Append(int aX, int aY)
Append a new point at the end of the polygon.
Definition: shape_simple.h:135
SHAPE * Clone() const override
Return a dynamically allocated copy of the shape.
Definition: shape_simple.h:64
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:188
bool IsSolid() const override
Definition: shape_simple.h:168
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Definition: shape_simple.h:158
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.
Definition: shape.cpp:138
SHAPE_SIMPLE(const SHAPE_SIMPLE &aOther)
Definition: shape_simple.h:60
const VECTOR2I & CPoint(int aIndex) const
Return a const reference to a given point in the polygon.
Definition: shape_simple.h:102
int PointCount() const
Return the number of points (vertices) in this polygon.
Definition: shape_simple.h:88
void Move(const VECTOR2I &aVector) override
Definition: shape_simple.h:163
SHAPE_SIMPLE(const SHAPE_LINE_CHAIN &aPoly)
Definition: shape_simple.h:53
void Append(const VECTOR2I &aP)
Append a new point at the end of the polygon.
Definition: shape_simple.h:146
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 point aP than aClearance,...
Definition: shape_simple.h:152
bool IsClosed() const override
Definition: shape_simple.h:178
virtual size_t GetSegmentCount() const override
Definition: shape_simple.h:176
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
Definition: shape_simple.h:78
virtual size_t GetPointCount() const override
Definition: shape_simple.h:175
const VECTOR2D CDPoint(int aIndex) const
Return a given point as a vector with elements of type double.
Definition: shape_simple.h:113
SHAPE_SIMPLE()
Create an empty polygon.
Definition: shape_simple.h:47
An abstract shape on 2D plane.
Definition: shape.h:126
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
@ SH_SIMPLE
simple polygon
Definition: shape.h:51
VECTOR2< double > VECTOR2D
Definition: vector2d.h:587