KiCad PCB EDA Suite
convert_to_biu.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) 2012-2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2019 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 CONVERT_TO_BIU_H_
26 #define CONVERT_TO_BIU_H_
27 
38 #if defined(PCBNEW) || defined(CVPCB) || defined(GERBVIEW)
40  #if defined(GERBVIEW)
41  constexpr double IU_PER_MM = 1e5; // Gerbview IU is 10 nanometers.
42  #else
43  constexpr double IU_PER_MM = 1e6; // Pcbnew IU is 1 nanometer.
44  #endif
45 
46 constexpr double IU_PER_MILS = IU_PER_MM * 0.0254;
47 
49 inline int Mils2iu( int mils )
50 {
51  double x = mils * IU_PER_MILS;
52  return int( x < 0 ? x - 0.5 : x + 0.5 );
53 }
54 
55 constexpr inline double Iu2Mils( int iu )
56 {
57  double mils = iu / IU_PER_MILS;
58 
59  return static_cast< int >( mils < 0 ? mils - 0.5 : mils + 0.5 );
60 }
61 #elif defined (PL_EDITOR)
62 constexpr double IU_PER_MM = 1e3; // internal units in micron (should be enough)
63 constexpr double IU_PER_MILS = (IU_PER_MM * 0.0254);
64 
66 inline int Mils2iu( int mils )
67 {
68  double x = mils * IU_PER_MILS;
69  return int( x < 0 ? x - 0.5 : x + 0.5 );
70 }
71 
72 #elif defined (EESCHEMA) // Eeschema
73 constexpr double IU_PER_MM = 1e4; // Schematic internal units 1=100nm
74 constexpr double IU_PER_MILS = IU_PER_MM * 0.0254;
75 
76 constexpr inline int Mils2iu( int mils )
77 {
78  double x = mils * IU_PER_MILS;
79  return int( x < 0 ? x - 0.5 : x + 0.5 );
80 }
81 
82 constexpr inline int Iu2Mils( int iu )
83 {
84  double mils = iu / IU_PER_MILS;
85 
86  return static_cast< int >( mils < 0 ? mils - 0.5 : mils + 0.5 );
87 }
88 #else
89 // Here, we do not know the value of internal units: do not define
90 // conversion functions (They do not have meaning)
91 #define UNKNOWN_IU
92 #endif
93 
94 #ifndef UNKNOWN_IU
95 // Other definitions used in a few files
96 constexpr double MM_PER_IU = ( 1 / IU_PER_MM );
97 
99 constexpr inline int Millimeter2iu( double mm )
100 {
101  return (int) ( mm < 0 ? mm * IU_PER_MM - 0.5 : mm * IU_PER_MM + 0.5 );
102 }
103 
105 constexpr inline double Iu2Millimeter( int iu )
106 {
107  return iu / IU_PER_MM;
108 }
109 
111 // constexpr inline double Iu2Mils( int iu )
112 // {
113 // return iu / IU_PER_MILS;
114 // }
115 
116 // The max error is the distance between the middle of a segment, and the circle
117 // for circle/arc to segment approximation.
118 // Warning: too small values can create very long calculation time in zone filling
119 // 0.05 to 0.005 mm are reasonable values
120 
121 constexpr int ARC_LOW_DEF = Millimeter2iu( 0.02 );
122 constexpr int ARC_HIGH_DEF = Millimeter2iu( 0.005 );
123 
124 #endif
125 
126 #endif // CONVERT_TO_BIU_H_
#define IU_PER_MILS
Definition: plotter.cpp:137