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
74 const BOX2I BBox( int aClearance = 0 ) const override
75 {
76 return m_points.BBox( aClearance );
77 }
78
84 int PointCount() const
85 {
86 return m_points.PointCount();
87 }
88
98 const VECTOR2I& CPoint( int aIndex ) const
99 {
100 return m_points.CPoint( aIndex );
101 }
102
109 const VECTOR2D CDPoint( int aIndex ) const
110 {
111 const VECTOR2I& v = CPoint( aIndex );
112 return VECTOR2D( v.x, v.y );
113 }
114
121 {
122 return m_points;
123 }
124
131 void Append( int aX, int aY )
132 {
133 VECTOR2I v( aX, aY );
134 Append( v );
135 }
136
142 void Append( const VECTOR2I& aP )
143 {
144 m_points.Append( aP );
145 }
146
148 bool Collide( const SEG& aSeg, int aClearance = 0, int* aActual = nullptr,
149 VECTOR2I* aLocation = nullptr ) const override
150 {
151 return m_points.Collide( aSeg, aClearance, aActual, aLocation );
152 }
153
154 void Rotate( const EDA_ANGLE& aAngle, const VECTOR2I& aCenter = { 0, 0 } ) override
155 {
156 m_points.Rotate( aAngle, aCenter );
157 }
158
159 void Move( const VECTOR2I& aVector ) override
160 {
161 m_points.Move( aVector );
162 }
163
164 bool IsSolid() const override
165 {
166 return true;
167 }
168
169 virtual const VECTOR2I GetPoint( int aIndex ) const override { return m_points.CPoint(aIndex); }
170 virtual const SEG GetSegment( int aIndex ) const override { return m_points.CSegment(aIndex); }
171 virtual size_t GetPointCount() const override { return m_points.PointCount(); }
172 virtual size_t GetSegmentCount() const override { return m_points.SegmentCount(); }
173
174 bool IsClosed() const override
175 {
176 return true;
177 }
178
179 void TransformToPolygon( SHAPE_POLY_SET& aBuffer, int aError,
180 ERROR_LOC aErrorLoc ) const override;
181
182private:
183 // vertices
185};
186
187#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:918
Definition seg.h:38
SHAPE_LINE_CHAIN_BASE(SHAPE_TYPE aType)
Definition shape.h:306
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 the boundary of shape (this) lies closer to the point aP 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:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682