KiCad PCB EDA Suite
shape_circle.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) 2013 CERN
5  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef __SHAPE_CIRCLE_H
26 #define __SHAPE_CIRCLE_H
27 
28 #include <geometry/shape.h>
29 #include <math/box2.h>
30 #include <math/vector2d.h>
31 
32 class SHAPE_CIRCLE : public SHAPE
33 {
34 public:
36  SHAPE( SH_CIRCLE ), m_radius( 0 )
37  {}
38 
39  SHAPE_CIRCLE( const VECTOR2I& aCenter, int aRadius ) :
40  SHAPE( SH_CIRCLE ), m_radius( aRadius ), m_center( aCenter )
41  {}
42 
43  SHAPE_CIRCLE( const SHAPE_CIRCLE& aOther ) :
44  SHAPE( SH_CIRCLE ),
45  m_radius( aOther.m_radius ),
46  m_center( aOther.m_center )
47  {};
48 
50  {}
51 
52  SHAPE* Clone() const override
53  {
54  return new SHAPE_CIRCLE( *this );
55  }
56 
57  SHAPE_CIRCLE& operator=( const SHAPE_CIRCLE& ) = default;
58 
59  const BOX2I BBox( int aClearance = 0 ) const override
60  {
61  const VECTOR2I rc( m_radius + aClearance, m_radius + aClearance );
62 
63  return BOX2I( m_center - rc, rc * 2 );
64  }
65 
66  bool Collide( const SEG& aSeg, int aClearance = 0 ) const override
67  {
68  int rc = aClearance + m_radius;
69 
70  return aSeg.Distance( m_center ) < rc;
71  }
72 
73  void SetRadius( int aRadius )
74  {
75  m_radius = aRadius;
76  }
77 
78  void SetCenter( const VECTOR2I& aCenter )
79  {
80  m_center = aCenter;
81  }
82 
83  int GetRadius() const
84  {
85  return m_radius;
86  }
87 
88  const VECTOR2I GetCenter() const
89  {
90  return m_center;
91  }
92 
93  void Move( const VECTOR2I& aVector ) override
94  {
95  m_center += aVector;
96  }
97 
98  bool IsSolid() const override
99  {
100  return true;
101  }
102 private:
103  int m_radius;
105 };
106 
107 #endif
void SetCenter(const VECTOR2I &aCenter)
Definition: shape_circle.h:78
BOX2< VECTOR2I > BOX2I
Definition: box2.h:521
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:207
int GetRadius() const
Definition: shape_circle.h:83
SHAPE_CIRCLE(const SHAPE_CIRCLE &aOther)
Definition: shape_circle.h:43
VECTOR2I m_center
Definition: shape_circle.h:104
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Definition: shape_circle.h:59
const VECTOR2I GetCenter() const
Definition: shape_circle.h:88
void Move(const VECTOR2I &aVector) override
Definition: shape_circle.h:93
bool IsSolid() const override
Definition: shape_circle.h:98
SHAPE_CIRCLE & operator=(const SHAPE_CIRCLE &)=default
SHAPE.
Definition: shape.h:60
SHAPE * Clone() const override
Function Clone()
Definition: shape_circle.h:52
line chain (polyline)
Definition: shape.h:48
SHAPE_CIRCLE(const VECTOR2I &aCenter, int aRadius)
Definition: shape_circle.h:39
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
Definition: shape_circle.h:66
Definition: seg.h:39
void SetRadius(int aRadius)
Definition: shape_circle.h:73