KiCad PCB EDA Suite
shape_segment.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_SEGMENT_H
26 #define __SHAPE_SEGMENT_H
27 
28 #include <geometry/seg.h>
29 #include <geometry/shape.h>
30 #include <math/box2.h>
31 #include <math/vector2d.h>
32 
33 class SHAPE_SEGMENT : public SHAPE {
34 
35 public:
37  SHAPE( SH_SEGMENT ), m_width( 0 ) {};
38 
39  SHAPE_SEGMENT( const VECTOR2I& aA, const VECTOR2I& aB, int aWidth = 0 ):
40  SHAPE( SH_SEGMENT ), m_seg( aA, aB ), m_width( aWidth ) {};
41 
42  SHAPE_SEGMENT( const SEG& aSeg, int aWidth = 0 ):
43  SHAPE( SH_SEGMENT ), m_seg( aSeg ), m_width( aWidth ) {};
44 
46 
47  SHAPE* Clone() const override
48  {
49  return new SHAPE_SEGMENT( m_seg, m_width );
50  }
51 
52  const BOX2I BBox( int aClearance = 0 ) const override
53  {
54  return BOX2I( m_seg.A, m_seg.B - m_seg.A ).Inflate( aClearance + ( m_width + 1 ) / 2 );
55  }
56 
57  bool Collide( const SEG& aSeg, int aClearance = 0 ) const override
58  {
59  return m_seg.Distance( aSeg ) < ( m_width + 1 ) / 2 + aClearance;
60  }
61 
62  bool Collide( const VECTOR2I& aP, int aClearance = 0 ) const override
63  {
64  return m_seg.Distance( aP ) < ( m_width + 1 ) / 2 + aClearance;
65  }
66 
67  void SetSeg( const SEG& aSeg )
68  {
69  m_seg = aSeg;
70  }
71 
72  const SEG& GetSeg() const
73  {
74  return m_seg;
75  }
76 
77  void SetWidth( int aWidth )
78  {
79  m_width = aWidth;
80  }
81 
82  int GetWidth() const
83  {
84  return m_width;
85  }
86 
87  bool IsSolid() const override
88  {
89  return true;
90  }
91 
92  void Move( const VECTOR2I& aVector ) override
93  {
94  m_seg.A += aVector;
95  m_seg.B += aVector;
96  }
97 
98 private:
100  int m_width;
101 };
102 
103 #endif
BOX2< VECTOR2I > BOX2I
Definition: box2.h:521
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:207
bool Collide(const VECTOR2I &aP, int aClearance=0) const override
Function Collide()
Definition: shape_segment.h:62
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
Definition: shape_segment.h:57
void SetSeg(const SEG &aSeg)
Definition: shape_segment.h:67
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Definition: shape_segment.h:52
const SEG & GetSeg() const
Definition: shape_segment.h:72
void Move(const VECTOR2I &aVector) override
Definition: shape_segment.h:92
SHAPE.
Definition: shape.h:60
SHAPE_SEGMENT(const SEG &aSeg, int aWidth=0)
Definition: shape_segment.h:42
Definition: seg.h:39
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:301
SHAPE * Clone() const override
Function Clone()
Definition: shape_segment.h:47
VECTOR2I A
Definition: seg.h:47
int GetWidth() const
Definition: shape_segment.h:82
SHAPE_SEGMENT(const VECTOR2I &aA, const VECTOR2I &aB, int aWidth=0)
Definition: shape_segment.h:39
bool IsSolid() const override
Definition: shape_segment.h:87
void SetWidth(int aWidth)
Definition: shape_segment.h:77
axis-aligned rectangle
Definition: shape.h:46
VECTOR2I B
Definition: seg.h:48