Handle basic rounding error in schematic import
The fractional part of Altium schematic units is an integer number of
1/10000 mil segments, which is 2.54 nm. The internal unit of eeschema
is 10 nm, so each fractional unit in Altium is 0.254 base eeschema
units. To be consistent with
cf33cfcad1
we round to the nearest 10nm for each element
Fixes https://gitlab.com/kicad/code/kicad/issues/11742
This commit is contained in:
parent
0c47a09517
commit
6fef054c51
|
@ -43,7 +43,12 @@ ALTIUM_SCH_RECORD ReadRecord( const std::map<wxString, wxString>& aProps )
|
|||
|
||||
constexpr int Altium2KiCadUnit( const int val, const int frac )
|
||||
{
|
||||
return Mils2iu( val ) * 10 + Mils2iu( frac ) / 10000; // TODO: correct, rounding issues?
|
||||
constexpr double int_limit = ( std::numeric_limits<int>::max() - 10 ) / 2.54;
|
||||
|
||||
double dbase = 10 * Mils2iu( val );
|
||||
double dfrac = Mils2iu( frac ) / 10000.0;
|
||||
|
||||
return KiROUND( Clamp<double>( -int_limit, ( dbase + dfrac ) / 10.0, int_limit ) ) * 10;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ void kimathLogDebug( const char* aFormatString, ... );
|
|||
* result is: lower <= value <= upper
|
||||
*</p>
|
||||
*/
|
||||
template <typename T> inline const T& Clamp( const T& lower, const T& value, const T& upper )
|
||||
template <typename T> inline constexpr T Clamp( const T& lower, const T& value, const T& upper )
|
||||
{
|
||||
if( value < lower )
|
||||
return lower;
|
||||
|
|
Loading…
Reference in New Issue