KiCad PCB EDA Suite
pns_solid.cpp
Go to the documentation of this file.
1 /*
2  * KiRouter - a push-and-(sometimes-)shove PCB router
3  *
4  * Copyright (C) 2013-2014 CERN
5  * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
6  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
7  *
8  * This program is free software: you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by the
10  * Free Software Foundation, either version 3 of the License, or (at your
11  * option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include <math/vector2d.h>
23 
24 #include <geometry/shape.h>
26 #include <geometry/shape_rect.h>
27 #include <geometry/shape_circle.h>
28 #include <geometry/shape_convex.h>
29 
30 #include "pns_solid.h"
31 #include "pns_utils.h"
32 
33 namespace PNS {
34 
35 const SHAPE_LINE_CHAIN SOLID::Hull( int aClearance, int aWalkaroundThickness ) const
36 {
37  int cl = aClearance + ( aWalkaroundThickness + 1 )/ 2;
38 
39  switch( m_shape->Type() )
40  {
41  case SH_RECT:
42  {
43  SHAPE_RECT* rect = static_cast<SHAPE_RECT*>( m_shape );
44  return OctagonalHull( rect->GetPosition(), rect->GetSize(), cl + 1, 0.2 * cl );
45  }
46 
47  case SH_CIRCLE:
48  {
49  SHAPE_CIRCLE* circle = static_cast<SHAPE_CIRCLE*>( m_shape );
50  int r = circle->GetRadius();
51  return OctagonalHull( circle->GetCenter() - VECTOR2I( r, r ), VECTOR2I( 2 * r, 2 * r ),
52  cl + 1, 0.52 * ( r + cl ) );
53  }
54 
55  case SH_SEGMENT:
56  {
57  SHAPE_SEGMENT* seg = static_cast<SHAPE_SEGMENT*>( m_shape );
58  return SegmentHull( *seg, aClearance, aWalkaroundThickness );
59  }
60 
61  case SH_CONVEX:
62  {
63  SHAPE_CONVEX* convex = static_cast<SHAPE_CONVEX*>( m_shape );
64 
65  return ConvexHull( *convex, cl );
66  }
67 
68  default:
69  break;
70  }
71 
72  return SHAPE_LINE_CHAIN();
73 }
74 
75 
77 {
78  ITEM* solid = new SOLID( *this );
79  return solid;
80 }
81 
82 }
Class ITEM.
Definition: pns_item.h:53
const VECTOR2I GetCenter() const
Definition: shape_circle.h:84
int GetRadius() const
Definition: shape_circle.h:79
const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0) const override
Definition: pns_solid.cpp:35
Class SHAPE_CONVEX.
Definition: shape_convex.h:42
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
const SHAPE_LINE_CHAIN SegmentHull(const SHAPE_SEGMENT &aSeg, int aClearance, int aWalkaroundThickness)
Definition: pns_utils.cpp:53
SHAPE * m_shape
Definition: pns_solid.h:106
ITEM * Clone() const override
Function Clone()
Definition: pns_solid.cpp:76
const VECTOR2I & GetPosition() const
Function GetPosition()
Definition: shape_rect.h:100
const SHAPE_LINE_CHAIN ConvexHull(const SHAPE_CONVEX &aConvex, int aClearance)
Function ConvexHull()
Definition: pns_utils.cpp:101
const SHAPE_LINE_CHAIN OctagonalHull(const VECTOR2I &aP0, const VECTOR2I &aSize, int aClearance, int aChamfer)
Various utility functions.
Definition: pns_utils.cpp:33
line chain (polyline)
Definition: shape.h:46
SHAPE_TYPE Type() const
Function Type()
Definition: shape.h:82
Class SHAPE_LINE_CHAIN.
Definition: shape.h:43
Push and Shove diff pair dimensions (gap) settings dialog.
circle
Definition: shape.h:47
const VECTOR2I GetSize() const
Function GetSize()
Definition: shape_rect.h:110
axis-aligned rectangle
Definition: shape.h:44