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