KiCad PCB EDA Suite
shape.cpp
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) 2015 CERN
5 * @author Tomasz Wlostowski <[email protected]>
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
26#include <geometry/shape.h>
27#include <geometry/shape_arc.h>
30#include <geometry/shape_rect.h>
33
34bool SHAPE::Parse( std::stringstream& aStream )
35{
36 assert( false );
37 return false;
38}
39
40
41const std::string SHAPE::Format() const
42{
43 assert( false );
44 return std::string( "" );
45}
46
47
48int SHAPE::GetClearance( const SHAPE* aOther ) const
49{
50 int actual_clearance = std::numeric_limits<int>::max();
51 std::vector<const SHAPE*> a_shapes;
52 std::vector<const SHAPE*> b_shapes;
53
54 GetIndexableSubshapes( a_shapes );
55 aOther->GetIndexableSubshapes( b_shapes );
56
57 if( GetIndexableSubshapeCount() == 0 )
58 a_shapes.push_back( this );
59
60 if( aOther->GetIndexableSubshapeCount() == 0 )
61 b_shapes.push_back( aOther );
62
63 for( const SHAPE* a : a_shapes )
64 {
65 for( const SHAPE* b : b_shapes )
66 {
67 int temp_dist = 0;
68 a->Collide( b, std::numeric_limits<int>::max() / 2, &temp_dist );
69
70 if( temp_dist < actual_clearance )
71 actual_clearance = temp_dist;
72 }
73 }
74
75 return actual_clearance;
76}
virtual size_t GetIndexableSubshapeCount() const
Definition: shape.h:110
virtual void GetIndexableSubshapes(std::vector< const SHAPE * > &aSubshapes) const
Definition: shape.h:112
An abstract shape on 2D plane.
Definition: shape.h:123
int GetClearance(const SHAPE *aOther) const
Return the actual minimum distance between two shapes.
Definition: shape.cpp:48
virtual const std::string Format() const
Definition: shape.cpp:41
virtual bool Parse(std::stringstream &aStream)
Definition: shape.cpp:34