KiCad PCB EDA Suite
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 Kicad Developers, see change_log.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 class SHAPE_SIMPLE : public SHAPE
43 {
44 public:
50  SHAPE( SH_SIMPLE )
51  {
52  m_points.SetClosed( true );
53  }
54 
55  SHAPE_SIMPLE( const SHAPE_LINE_CHAIN& aPoly ) :
56  SHAPE( SH_SIMPLE ),
57  m_points( aPoly )
58  {
59  m_points.SetClosed( true );
60  }
61 
62  SHAPE_SIMPLE( const SHAPE_SIMPLE& aOther ) :
63  SHAPE( SH_SIMPLE ), m_points( aOther.m_points )
64  {}
65 
66  SHAPE* Clone() const override
67  {
68  return new SHAPE_SIMPLE( *this );
69  }
70 
75  void Clear()
76  {
77  m_points.Clear();
78  }
79 
81  const BOX2I BBox( int aClearance = 0 ) const override
82  {
83  return m_points.BBox( aClearance );
84  }
85 
92  int PointCount() const
93  {
94  return m_points.PointCount();
95  }
96 
106  const VECTOR2I& CPoint( int aIndex ) const
107  {
108  return m_points.CPoint( aIndex );
109  }
110 
119  const VECTOR2D CDPoint( int aIndex ) const
120  {
121  const VECTOR2I& v = CPoint( aIndex );
122  return VECTOR2D( v.x, v.y );
123  }
124 
132  const SHAPE_LINE_CHAIN& Vertices() const
133  {
134  return m_points;
135  }
136 
144  void Append( int aX, int aY )
145  {
146  VECTOR2I v( aX, aY );
147  Append( v );
148  }
149 
156  void Append( const VECTOR2I& aP )
157  {
158  m_points.Append( aP );
159  }
160 
162  bool Collide( const SEG& aSeg, int aClearance = 0, int* aActual = nullptr ) const override
163  {
164  return m_points.Collide( aSeg, aClearance, aActual );
165  }
166 
167  void Rotate( double aAngle, const VECTOR2I& aCenter = { 0, 0 } ) override
168  {
169  m_points.Rotate( aAngle, aCenter );
170  }
171 
172  void Move( const VECTOR2I& aVector ) override
173  {
174  m_points.Move( aVector );
175  }
176 
177  bool IsSolid() const override
178  {
179  return true;
180  }
181 
182 private:
183  // vertices
185 };
186 
187 #endif // __SHAPE_SIMPLE_H
SHAPE_SIMPLE.
Definition: shape_simple.h:42
bool Collide(const SEG &aSeg, int aClearance=0, int *aActual=nullptr) const override
Function Collide()
Definition: shape_simple.h:162
const VECTOR2I & CPoint(int aIndex) const
Function Point()
Definition: shape_simple.h:106
void Move(const VECTOR2I &aVector) override
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Definition: shape_simple.h:81
int PointCount() const
Function PointCount()
void Append(const VECTOR2I &aP)
Function Append()
Definition: shape_simple.h:156
SHAPE * Clone() const override
Function Clone()
Definition: shape_simple.h:66
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
const VECTOR2I & CPoint(int aIndex) const
Function Point()
void SetClosed(bool aClosed)
Function SetClosed()
const VECTOR2D CDPoint(int aIndex) const
Function CDPoint()
Definition: shape_simple.h:119
const BOX2I BBox(int aClearance=0) const override
Function BBox()
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
SHAPE_SIMPLE(const SHAPE_SIMPLE &aOther)
Definition: shape_simple.h:62
void Rotate(double aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Function Rotate.
Definition: shape_simple.h:167
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_simple.h:132
SHAPE_SIMPLE()
Constructor Creates an empty polygon.
Definition: shape_simple.h:49
SHAPE.
Definition: shape.h:74
bool IsSolid() const override
Definition: shape_simple.h:177
void Clear()
Function Clear() Removes all points from the polygon.
Definition: shape_simple.h:75
void Rotate(double aAngle, const VECTOR2I &aCenter=VECTOR2I(0, 0)) override
Function Rotate rotates all vertices by a given angle.
Definition: seg.h:39
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:184
bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr) const override
Function Collide()
SHAPE_LINE_CHAIN.
int PointCount() const
Function PointCount()
Definition: shape_simple.h:92
void Clear()
Function Clear() Removes all points from the line chain.
SHAPE_SIMPLE(const SHAPE_LINE_CHAIN &aPoly)
Definition: shape_simple.h:55
circle
Definition: shape.h:45
void Append(int aX, int aY)
Function Append()
Definition: shape_simple.h:144
void Move(const VECTOR2I &aVector) override
Definition: shape_simple.h:172