KiCad PCB EDA Suite
shape_convex.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_CONVEX_H
25 #define __SHAPE_CONVEX_H
26 
27 #include <vector>
28 
29 #include <geometry/shape.h>
30 #include <geometry/seg.h>
32 
42 class SHAPE_CONVEX : public SHAPE
43 {
44 public:
50  SHAPE( SH_CONVEX )
51  {
52  m_points.SetClosed( true );
53  }
54 
55  SHAPE_CONVEX( const SHAPE_CONVEX& aOther ) :
56  SHAPE( SH_CONVEX ), m_points( aOther.m_points )
57  {}
58 
59  SHAPE* Clone() const override
60  {
61  return new SHAPE_CONVEX( *this );
62  }
63 
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 
85  int PointCount() const
86  {
87  return m_points.PointCount();
88  }
89 
99  VECTOR2I& Point( int aIndex )
100  {
101  return m_points.Point( aIndex );
102  }
103 
113  const VECTOR2I& CPoint( int aIndex ) const
114  {
115  return m_points.CPoint( aIndex );
116  }
117 
126  const VECTOR2D CDPoint( int aIndex ) const
127  {
128  const VECTOR2I& v = CPoint( aIndex );
129  return VECTOR2D( v.x, v.y );
130  }
131 
139  const SHAPE_LINE_CHAIN& Vertices() const
140  {
141  return m_points;
142  }
143 
151  void Append( int aX, int aY )
152  {
153  VECTOR2I v( aX, aY );
154  Append( v );
155  }
156 
163  void Append( const VECTOR2I& aP )
164  {
165  m_points.Append( aP );
166  }
167 
169  bool Collide( const SEG& aSeg, int aClearance = 0 ) const override
170  {
171  return m_points.Collide( aSeg, aClearance );
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 private:
185  // vertices
187 };
188 
189 #endif // __SHAPE_CONVEX_H
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Definition: shape_convex.h:74
void Clear()
Function Clear() Removes all points from the polygon.
Definition: shape_convex.h:68
int PointCount() const
Function PointCount()
void Move(const VECTOR2I &aVector) override
Class SHAPE_CONVEX.
Definition: shape_convex.h:42
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
Definition: shape_convex.h:113
bool Collide(const VECTOR2I &aP, int aClearance=0) const override
Function Collide()
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
SHAPE * Clone() const override
Function Clone()
Definition: shape_convex.h:59
void Move(const VECTOR2I &aVector) override
Definition: shape_convex.h:174
void SetClosed(bool aClosed)
Function SetClosed()
void Append(int aX, int aY)
Function Append()
Definition: shape_convex.h:151
const BOX2I BBox(int aClearance=0) const override
Function BBox()
VECTOR2< double > VECTOR2D
Definition: vector2d.h:588
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_convex.h:139
int PointCount() const
Function PointCount()
Definition: shape_convex.h:85
SHAPE_CONVEX()
Constructor Creates an empty polygon.
Definition: shape_convex.h:49
Class SHAPE.
Definition: shape.h:57
SHAPE_CONVEX(const SHAPE_CONVEX &aOther)
Definition: shape_convex.h:55
bool IsSolid() const override
Definition: shape_convex.h:179
VECTOR2I & Point(int aIndex)
Function Point()
Definition: shape_convex.h:99
Definition: seg.h:36
SHAPE_LINE_CHAIN m_points
Definition: shape_convex.h:186
Class SHAPE_LINE_CHAIN.
void Clear()
Function Clear() Removes all points from the line chain.
VECTOR2I & Point(int aIndex)
Function Point()
const VECTOR2D CDPoint(int aIndex) const
Function CDPoint()
Definition: shape_convex.h:126
circle
Definition: shape.h:47
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
void Append(const VECTOR2I &aP)
Function Append()
Definition: shape_convex.h:163
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
Definition: shape_convex.h:169