← Back to team overview

kicad-developers team mailing list archive

Re: OK, *there are* issue with nano-pcbnew cleanup

 

On 06/22/2012 04:30 AM, Lorenzo Marcantonio wrote:
> Or, most probably, with rounding in the save/load code; didn't track it
> yet.
>
> I have this board I'm doing (15 nets left). Doing cleanup junks 8 links
> (bad pcbnew!). Doing 'connect to track' then cleanup works fine.
>
> After a save/reload the problem reappears!
>
> My theory: there is some mismatch in the save/load code when converting
> from nanometer to millimeters (didn't look on how it is done).
> A / 1000000000 operation is not exact in binary so maybe it rounds in
> the wrong way? The 2nm offset I found in the track laying maybe
> exacerbates the problem.
>
> Morale: take care when using nano-pcbnew :D keep an eye on the missing
> links counter...
>
> PS: please do not redistribute the board, at least for the moment
> because:
> 1) it's proprietary and
> 2) it isn't finished yet anyway!


Was that a request for help?

You call me a broken record and a tyrant within in a span of two days and then don't know
how to ask for help.  Put yourself in a box did you?


Jean-Pierre and Wayne were thinking that you would be a great contributor moving forward. 
That is not at all clear to me, I look to attitude and cooperative spirit when I decide
who I want to work with.

Marco is one outstanding example, and Wayne is the best.

You my friend, are not someone I would want to work with long term. 
But don't go away, instead wait five minutes, and I will.  You are not the reason either.


Please help test the attached patch on Linux.
The "double" was not good enough, "long double" is working better so far.

If it works, I will work on the Mingw solution tomorrow, but I gotta run now.

My testing strategy was to simply compile for nanometers, load you nanometer board, and
save it under another name, then use diff on the two files.



=== modified file 'pcbnew/legacy_plugin.cpp'
--- pcbnew/legacy_plugin.cpp	2012-06-19 19:25:41 +0000
+++ pcbnew/legacy_plugin.cpp	2012-06-22 22:21:18 +0000
@@ -2565,13 +2565,13 @@
 
 int LEGACY_PLUGIN::biuSprintf( char* buf, BIU aValue ) const
 {
-    double  engUnits = biuToDisk * aValue;
-    int     len;
+    long double engUnits = biuToDisk * aValue;
+    int         len;
 
-    if( engUnits != 0.0 && fabs( engUnits ) <= 0.0001 )
+    if( engUnits != 0.0 && fabsl( engUnits ) <= 0.0001 )
     {
         // printf( "f: " );
-        len = sprintf( buf, "%.10f", engUnits );
+        len = sprintf( buf, "%.10Lf", engUnits );
 
         while( --len > 0 && buf[len] == '0' )
             buf[len] = '\0';
@@ -2581,7 +2581,7 @@
     else
     {
         // printf( "g: " );
-        len = sprintf( buf, "%.10g", engUnits );
+        len = sprintf( buf, "%.10Lg", engUnits );
     }
     return len;
 }
@@ -2630,7 +2630,7 @@
 
     errno = 0;
 
-    double fval = strtod( aValue, &nptr );
+    long double fval = strtold( aValue, &nptr );
 
     if( errno )
     {
@@ -2651,20 +2651,9 @@
     if( nptrptr )
         *nptrptr = nptr;
 
-#if defined(DEBUG)
-
-    if( diskToBiu == 10000/25.4 )
-    {
-        // this is the special reverse trip mm -> deci-mils testing run,
-        // only available in DEBUG mode.
-        return BIU( KiROUND( fval * diskToBiu ) );
-    }
-
-#endif
-
-    // There should be no rounding issues here, since the values in the file initially
-    // came from integers via biuFmt(). In fact this product should be an integer, exactly.
-    return BIU( fval * diskToBiu );
+    fval *= diskToBiu;
+
+    return BIU( fval < 0 ? fval - 0.5 : fval + 0.5 );
 }
 
 
@@ -2706,7 +2695,7 @@
 
     // conversion factor for saving RAM BIUs to KICAD legacy file format.
 #if defined( USE_PCBNEW_NANOMETRES )
-    biuToDisk = 1/IU_PER_MM;        // BIUs are nanometers & file is mm
+    biuToDisk = 1.0L/IU_PER_MM;     // BIUs are nanometers & file is mm
 #else
     biuToDisk = 1.0;                // BIUs are deci-mils
 #endif

=== modified file 'pcbnew/legacy_plugin.h'
--- pcbnew/legacy_plugin.h	2012-06-10 00:39:40 +0000
+++ pcbnew/legacy_plugin.h	2012-06-22 22:20:28 +0000
@@ -130,8 +130,11 @@
     /// initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
     void    init( PROPERTIES* aProperties );
 
-    double  biuToDisk;      ///< convert from BIUs to disk engineering units with this scale factor
-    double  diskToBiu;      ///< convert from disk engineering units to BIUs with this scale factor
+    long double  biuToDisk;         ///< convert from BIUs to disk engineering units
+                                    ///< with this scale factor
+
+    long double  diskToBiu;         ///< convert from disk engineering units to BIUs
+                                    ///< with this scale factor
 
     /**
      * Function biuParse


Follow ups

References