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 "shape.h"
29 
30 class SHAPE_CIRCLE : public SHAPE
31 {
32 public:
34  SHAPE( SH_CIRCLE ), m_radius( 0 )
35  {}
36 
37  SHAPE_CIRCLE( const VECTOR2I& aCenter, int aRadius ) :
38  SHAPE( SH_CIRCLE ), m_radius( aRadius ), m_center( aCenter )
39  {}
40 
41  SHAPE_CIRCLE( const SHAPE_CIRCLE& aOther ) :
42  SHAPE( SH_CIRCLE ),
43  m_radius( aOther.m_radius ),
44  m_center( aOther.m_center )
45  {};
46 
48  {}
49 
50  SHAPE* Clone() const override
51  {
52  return new SHAPE_CIRCLE( *this );
53  }
54 
55  const BOX2I BBox( int aClearance = 0 ) const override
56  {
57  const VECTOR2I rc( m_radius + aClearance, m_radius + aClearance );
58 
59  return BOX2I( m_center - rc, rc * 2 );
60  }
61 
62  bool Collide( const SEG& aSeg, int aClearance = 0 ) const override
63  {
64  int rc = aClearance + m_radius;
65 
66  return aSeg.Distance( m_center ) < rc;
67  }
68 
69  void SetRadius( int aRadius )
70  {
71  m_radius = aRadius;
72  }
73 
74  void SetCenter( const VECTOR2I& aCenter )
75  {
76  m_center = aCenter;
77  }
78 
79  int GetRadius() const
80  {
81  return m_radius;
82  }
83 
84  const VECTOR2I GetCenter() const
85  {
86  return m_center;
87  }
88 
89  void Move( const VECTOR2I& aVector ) override
90  {
91  m_center += aVector;
92  }
93 
94  bool IsSolid() const override
95  {
96  return true;
97  }
98 private:
99  int m_radius;
101 };
102 
103 #endif
void SetCenter(const VECTOR2I &aCenter)
Definition: shape_circle.h:74
BOX2< VECTOR2I > BOX2I
Definition: box2.h:468
const VECTOR2I GetCenter() const
Definition: shape_circle.h:84
SHAPE_CIRCLE(const SHAPE_CIRCLE &aOther)
Definition: shape_circle.h:41
VECTOR2I m_center
Definition: shape_circle.h:100
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Definition: shape_circle.h:55
int GetRadius() const
Definition: shape_circle.h:79
void Move(const VECTOR2I &aVector) override
Definition: shape_circle.h:89
bool IsSolid() const override
Definition: shape_circle.h:94
Class SHAPE.
Definition: shape.h:57
SHAPE * Clone() const override
Function Clone()
Definition: shape_circle.h:50
line chain (polyline)
Definition: shape.h:46
SHAPE_CIRCLE(const VECTOR2I &aCenter, int aRadius)
Definition: shape_circle.h:37
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
Definition: shape_circle.h:62
Definition: seg.h:37
void SetRadius(int aRadius)
Definition: shape_circle.h:69
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:185