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

(cherry picked from commit 6fef054c51)
This commit is contained in:
Seth Hillbrand 2022-07-07 10:53:06 -07:00
parent 7dc6abd533
commit 95fcf53353
2 changed files with 7 additions and 2 deletions

View File

@ -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;
}

View File

@ -49,7 +49,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;