Horizon
shape_circle.h
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
30class SHAPE_CIRCLE : public SHAPE
31{
32public:
33 SHAPE_CIRCLE() :
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 }
98private:
99 int m_radius;
100 VECTOR2I m_center;
101};
102
103#endif
Definition: seg.h:37
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:199
Definition: shape_circle.h:31
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
Definition: shape_circle.h:62
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Definition: shape_circle.h:55
SHAPE * Clone() const override
Function Clone()
Definition: shape_circle.h:50
Class SHAPE.
Definition: shape.h:59
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:70