KiCad PCB EDA Suite
bezier_curves.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) 2009-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2017 KiCad Developers, see CHANGELOG.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 
25 #ifndef BEZIER_CURVES_H
26 #define BEZIER_CURVES_H
27 
28 #include <vector>
29 #include <wx/gdicmn.h>
30 
35 {
36 public:
37  BEZIER_POLY( int x1, int y1, int x2, int y2, int x3, int y3 )
38  {
39  m_ctrlPts.emplace_back( x1, y1 );
40  m_ctrlPts.emplace_back( x2, y2 );
41  m_ctrlPts.emplace_back( x3, y3 );
42  m_output = nullptr;
43  }
44 
45  BEZIER_POLY( int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4 )
46  {
47  m_ctrlPts.emplace_back( x1, y1 );
48  m_ctrlPts.emplace_back( x2, y2 );
49  m_ctrlPts.emplace_back( x3, y3 );
50  m_ctrlPts.emplace_back( x4, y4 );
51  m_output = nullptr;
52  }
53 
54  BEZIER_POLY( const std::vector<wxPoint>& aControlPoints )
55  : m_ctrlPts( aControlPoints )
56  {
57  m_output = nullptr;
58  }
59 
64  void GetPoly( std::vector<wxPoint>& aOutput );
65 
66 private:
68  std::vector<wxPoint> m_ctrlPts;
69 
71  std::vector<wxPoint>* m_output;
72 
73  void addSegment( const wxPoint& aSegment )
74  {
75  if( m_output->back() != aSegment )
76  m_output->push_back( aSegment );
77  }
78 
79  void recursiveBezier( int x1, int y1, int x2, int y2, int x3, int y3, unsigned int level );
80  void recursiveBezier( int x1, int y1, int x2, int y2,
81  int x3, int y3, int x4, int y4, unsigned int level );
82 
83 
84  // Conversion parameters
85  constexpr static double angle_tolerance = 0.0;
86  constexpr static double cusp_limit = 0.0;
87  constexpr static int recursion_limit = 12;
88  constexpr static double approximation_scale = 0.5; // 1
89  constexpr static double distance_tolerance_square = ( 0.5 / approximation_scale ) * ( 0.5 / approximation_scale );
90 
91  constexpr static double curve_collinearity_epsilon = 1e-30;
92  constexpr static double curve_angle_tolerance_epsilon = 0.0001;
93 };
94 
95 #endif // BEZIER_CURVES_H
BEZIER_POLY(const std::vector< wxPoint > &aControlPoints)
Definition: bezier_curves.h:54
static constexpr double distance_tolerance_square
Definition: bezier_curves.h:89
static constexpr double approximation_scale
Definition: bezier_curves.h:88
BEZIER_POLY(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
Definition: bezier_curves.h:45
static constexpr double angle_tolerance
Definition: bezier_curves.h:85
void GetPoly(std::vector< wxPoint > &aOutput)
Converts Bezier curve to a polygon.
void recursiveBezier(int x1, int y1, int x2, int y2, int x3, int y3, unsigned int level)
std::vector< wxPoint > m_ctrlPts
Control points
Definition: bezier_curves.h:68
void addSegment(const wxPoint &aSegment)
Definition: bezier_curves.h:73
static constexpr double curve_collinearity_epsilon
Definition: bezier_curves.h:91
BEZIER_POLY(int x1, int y1, int x2, int y2, int x3, int y3)
Definition: bezier_curves.h:37
static constexpr double cusp_limit
Definition: bezier_curves.h:86
std::vector< wxPoint > * m_output
Pointer to the output vector
Definition: bezier_curves.h:71
static constexpr double curve_angle_tolerance_epsilon
Definition: bezier_curves.h:92
Bezier curves to polygon converter.
Definition: bezier_curves.h:34
static constexpr int recursion_limit
Definition: bezier_curves.h:87