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 
44 {
45 public:
52  {
53  m_points.SetClosed( true );
54  }
55 
56  SHAPE_SIMPLE( const SHAPE_LINE_CHAIN& aPoly ) :
58  m_points( aPoly )
59  {
60  m_points.SetClosed( true );
61  }
62 
63  SHAPE_SIMPLE( const SHAPE_SIMPLE& aOther ) :
65  {}
66 
67  SHAPE* Clone() const override
68  {
69  return new SHAPE_SIMPLE( *this );
70  }
71 
76  void Clear()
77  {
78  m_points.Clear();
79  }
80 
82  const BOX2I BBox( int aClearance = 0 ) const override
83  {
84  return m_points.BBox( aClearance );
85  }
86 
93  int PointCount() const
94  {
95  return m_points.PointCount();
96  }
97 
107  const VECTOR2I& CPoint( int aIndex ) const
108  {
109  return m_points.CPoint( aIndex );
110  }
111 
120  const VECTOR2D CDPoint( int aIndex ) const
121  {
122  const VECTOR2I& v = CPoint( aIndex );
123  return VECTOR2D( v.x, v.y );
124  }
125 
133  const SHAPE_LINE_CHAIN& Vertices() const
134  {
135  return m_points;
136  }
137 
145  void Append( int aX, int aY )
146  {
147  VECTOR2I v( aX, aY );
148  Append( v );
149  }
150 
157  void Append( const VECTOR2I& aP )
158  {
159  m_points.Append( aP );
160  }
161 
163  bool Collide( const SEG& aSeg, int aClearance = 0, int* aActual = nullptr,
164  VECTOR2I* aLocation = nullptr ) const override
165  {
166  return m_points.Collide( aSeg, aClearance, aActual, aLocation );
167  }
168 
169  void Rotate( double aAngle, const VECTOR2I& aCenter = { 0, 0 } ) override
170  {
171  m_points.Rotate( aAngle, aCenter );
172  }
173 
174  void Move( const VECTOR2I& aVector ) override
175  {
176  m_points.Move( aVector );
177  }
178 
179  bool IsSolid() const override
180  {
181  return true;
182  }
183 
184  virtual const VECTOR2I GetPoint( int aIndex ) const override { return m_points.CPoint(aIndex); }
185  virtual const SEG GetSegment( int aIndex ) const override { return m_points.CSegment(aIndex); }
186  virtual size_t GetPointCount() const override { return m_points.PointCount(); }
187  virtual size_t GetSegmentCount() const override { return m_points.SegmentCount(); }
188 
189  bool IsClosed() const override
190  {
191  return true;
192  }
193 
194 private:
195  // vertices
197 };
198 
199 #endif // __SHAPE_SIMPLE_H
virtual const SEG GetSegment(int aIndex) const override
Definition: shape_simple.h:185
bool IsClosed() const override
Definition: shape_simple.h:189
bool Collide(const SEG &aSeg, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Function Collide()
Definition: shape_simple.h:163
SHAPE_SIMPLE.
Definition: shape_simple.h:43
const VECTOR2I & CPoint(int aIndex) const
Function Point()
Definition: shape_simple.h:107
virtual const VECTOR2I GetPoint(int aIndex) const override
Definition: shape_simple.h:184
void Move(const VECTOR2I &aVector) override
virtual size_t GetPointCount() const override
Definition: shape_simple.h:186
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Definition: shape_simple.h:82
int PointCount() const
Function PointCount()
void Append(const VECTOR2I &aP)
Function Append()
Definition: shape_simple.h:157
SHAPE * Clone() const override
Function Clone()
Definition: shape_simple.h:67
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Function Collide()
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:120
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:63
void Rotate(double aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Function Rotate.
Definition: shape_simple.h:169
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_simple.h:133
SHAPE_SIMPLE()
Constructor Creates an empty polygon.
Definition: shape_simple.h:50
SHAPE.
Definition: shape.h:122
int SegmentCount() const
Function SegmentCount()
bool IsSolid() const override
Definition: shape_simple.h:179
void Clear()
Function Clear() Removes all points from the polygon.
Definition: shape_simple.h:76
void Rotate(double aAngle, const VECTOR2I &aCenter=VECTOR2I(0, 0)) override
Function Rotate rotates all vertices by a given angle.
Definition: seg.h:39
virtual size_t GetSegmentCount() const override
Definition: shape_simple.h:187
SHAPE_LINE_CHAIN m_points
Definition: shape_simple.h:196
const SEG CSegment(int aIndex) const
Function CSegment()
SHAPE_LINE_CHAIN.
int PointCount() const
Function PointCount()
Definition: shape_simple.h:93
void Clear()
Function Clear() Removes all points from the line chain.
SHAPE_SIMPLE(const SHAPE_LINE_CHAIN &aPoly)
Definition: shape_simple.h:56
circle
Definition: shape.h:47
void Append(int aX, int aY)
Function Append()
Definition: shape_simple.h:145
void Move(const VECTOR2I &aVector) override
Definition: shape_simple.h:174