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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef __SHAPE_SIMPLE_H
21#define __SHAPE_SIMPLE_H
22
23#include <geometry/seg.h>
24#include <geometry/shape.h>
26#include <math/box2.h>
27#include <math/vector2d.h>
28
36
38{
39public:
45 {
46 m_points.SetClosed( true );
47 }
48
51 m_points( aPoly )
52 {
53 m_points.SetClosed( true );
54 }
55
56 SHAPE_SIMPLE( const SHAPE_SIMPLE& aOther ) :
58 {}
59
60 SHAPE* Clone() const override
61 {
62 return new SHAPE_SIMPLE( *this );
63 }
64
68 void Clear()
69 {
70 m_points.Clear();
71 }
72
73 const BOX2I BBox( int aClearance = 0 ) const override
74 {
75 return m_points.BBox( aClearance );
76 }
77
83 int PointCount() const
84 {
85 return m_points.PointCount();
86 }
87
97 const VECTOR2I& CPoint( int aIndex ) const
98 {
99 return m_points.CPoint( aIndex );
100 }
101
108 const VECTOR2D CDPoint( int aIndex ) const
109 {
110 const VECTOR2I& v = CPoint( aIndex );
111 return VECTOR2D( v.x, v.y );
112 }
113
120 {
121 return m_points;
122 }
123
130 void Append( int aX, int aY )
131 {
132 VECTOR2I v( aX, aY );
133 Append( v );
134 }
135
141 void Append( const VECTOR2I& aP )
142 {
143 m_points.Append( aP );
144 }
145
146 bool Collide( const SEG& aSeg, int aClearance = 0, int* aActual = nullptr,
147 VECTOR2I* aLocation = nullptr ) const override
148 {
149 return m_points.Collide( aSeg, aClearance, aActual, aLocation );
150 }
151
152 void Rotate( const EDA_ANGLE& aAngle, const VECTOR2I& aCenter = { 0, 0 } ) override
153 {
154 m_points.Rotate( aAngle, aCenter );
155 }
156
157 void Move( const VECTOR2I& aVector ) override
158 {
159 m_points.Move( aVector );
160 }
161
162 bool IsSolid() const override
163 {
164 return true;
165 }
166
167 virtual const VECTOR2I GetPoint( int aIndex ) const override { return m_points.CPoint(aIndex); }
168 virtual const SEG GetSegment( int aIndex ) const override { return m_points.CSegment(aIndex); }
169 virtual size_t GetPointCount() const override { return m_points.PointCount(); }
170 virtual size_t GetSegmentCount() const override { return m_points.SegmentCount(); }
171
172 bool IsClosed() const override
173 {
174 return true;
175 }
176
177 void TransformToPolygon( SHAPE_POLY_SET& aBuffer, int aError,
178 ERROR_LOC aErrorLoc ) const override;
179
180private:
181 // vertices
183};
184
185#endif // __SHAPE_SIMPLE_H
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
Definition seg.h:38
SHAPE_LINE_CHAIN_BASE(SHAPE_TYPE aType)
Definition shape.h:318
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Rotate all vertices by a given angle.
Represent a set of closed polygons.
void Clear()
Remove all points from the polygon.
const SHAPE_LINE_CHAIN & Vertices() const
Return the list of vertices defining this simple polygon.
virtual const SEG GetSegment(int aIndex) const override
virtual const VECTOR2I GetPoint(int aIndex) const override
void Append(int aX, int aY)
Append a new point at the end of the polygon.
SHAPE * Clone() const override
Return a dynamically allocated copy of the shape.
SHAPE_LINE_CHAIN m_points
bool IsSolid() const override
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter={ 0, 0 }) 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.
Definition shape.cpp:135
SHAPE_SIMPLE(const SHAPE_SIMPLE &aOther)
const VECTOR2I & CPoint(int aIndex) const
Return a const reference to a given point in the polygon.
int PointCount() const
Return the number of points (vertices) in this polygon.
void Move(const VECTOR2I &aVector) override
SHAPE_SIMPLE(const SHAPE_LINE_CHAIN &aPoly)
void Append(const VECTOR2I &aP)
Append a new point at the end of the polygon.
bool Collide(const SEG &aSeg, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if segment aSeg lies closer to us than aClearance.
bool IsClosed() const override
virtual size_t GetSegmentCount() const override
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
virtual size_t GetPointCount() const override
const VECTOR2D CDPoint(int aIndex) const
Return a given point as a vector with elements of type double.
SHAPE_SIMPLE()
Create an empty polygon.
SHAPE(SHAPE_TYPE aType)
Create an empty shape of type aType.
Definition shape.h:134
@ SH_SIMPLE
simple polygon
Definition shape.h:47
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707