KiCad PCB EDA Suite
edgeshrink.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) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
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 
34 #include <vector>
35 
36 // clip2tri is Licenced under:
37 
38 // The MIT License (MIT)
39 
40 // Copyright (c) 2014 Bitfighter developers
41 
42 // Permission is hereby granted, free of charge, to any person obtaining a copy
43 // of this software and associated documentation files (the "Software"), to deal
44 // in the Software without restriction, including without limitation the rights
45 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
46 // copies of the Software, and to permit persons to whom the Software is
47 // furnished to do so, subject to the following conditions:
48 
49 // The above copyright notice and this permission notice shall be included in all
50 // copies or substantial portions of the Software.
51 
52 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
53 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
54 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
55 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
56 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
57 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
58 // SOFTWARE.
59 
60 
61 // Shrink large polygons by reducing each coordinate by 1 in the
62 // general direction of the last point as we wind around
63 //
64 // This normally wouldn't work in every case, but our upscaled-by-1000 polygons
65 // have little chance to create new duplicate points with this method.
66 //
67 // For information on why this was needed, see:
68 //
69 // https://github.com/greenm01/poly2tri/issues/90
70 //
71 
72 #define S_INC 1
73 
74 void EdgeShrink( std::vector<SFVEC2I64> &aPath )
75 {
76  unsigned int prev = aPath.size() - 1;
77 
78  for( unsigned int i = 0; i < aPath.size(); i++ )
79  {
80  // Adjust coordinate by 1 depending on the direction
81  (aPath[i].x - aPath[prev].x) > 0 ? aPath[i].x -= S_INC :
82  aPath[i].x += S_INC;
83 
84  (aPath[i].y - aPath[prev].y) > 0 ? aPath[i].y -= S_INC :
85  aPath[i].y += S_INC;
86 
87  prev = i;
88  }
89 }
#define S_INC
Definition: edgeshrink.cpp:72
void EdgeShrink(std::vector< SFVEC2I64 > &aPath)
Definition: edgeshrink.cpp:74