kicad/gerbview
Dick Hollenbeck c24863c078 // Dick Hollenbeck's KiROUND R&D
// This provides better project control over rounding to int from double
// than wxRound() did.  This scheme provides better logging in Debug builds
// and it provides for compile time calculation of constants.


#include <stdio.h>
#include <assert.h>
#include <limits.h>

//-----<KiROUND KIT>------------------------------------------------------------

/**
 * KiROUND
 * rounds a floating point number to an int using
 * "round halfway cases away from zero".
 * In Debug build an assert fires if will not fit into an int.
 */

#if defined( DEBUG )

// DEBUG: a macro to capture line and file, then calls this inline

static inline int KiRound( double v, int line, const char* filename )
{
    v = v < 0 ? v - 0.5 : v + 0.5;
    if( v > INT_MAX + 0.5 )
    {
        printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v );
    }
    else if( v < INT_MIN - 0.5 )
    {
        printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v );
    }
    return int( v );
}

#define KiROUND( v )    KiRound( v, __LINE__, __FILE__ )

#else

// RELEASE: a macro so compile can pre-compute constants.

#define KiROUND( v )  int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )

#endif


//-----</KiROUND KIT>-----------------------------------------------------------

// Only a macro is compile time calculated, an inline function causes a static constructor
// in a situation like this.
// Therefore the Release build is best done with a MACRO not an inline function.
int Computed = KiROUND( 14.3 * 8 );


int main( int argc, char** argv )
{
    for( double d = double(INT_MAX)-1;  d < double(INT_MAX)+8;  d += 2.0 )
    {
        int i = KiROUND( d );

        printf( "t: %d  %.16g\n", i, d );
    }

    return 0;
}
2012-04-19 01:55:45 -05:00
..
dialogs Make Gerbview working with USE_PCBNEW_NANOMETRES option ON 2012-04-18 09:07:13 +02:00
gerber_test_files Gerbview: add gerber test file. 2010-12-06 13:18:56 +01:00
CMakeLists.txt Hit test method rationalization and other minor improvements. 2012-03-15 10:31:16 -04:00
Info.plist Fix some minor OS X issues 2011-08-30 09:35:40 +02:00
block.cpp Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
class_DCodeSelectionbox.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
class_DCodeSelectionbox.h More encapsulation work and other minor improvements. 2011-12-16 08:32:23 -05:00
class_GERBER.cpp Make Gerbview working with USE_PCBNEW_NANOMETRES option ON 2012-04-18 09:07:13 +02:00
class_GERBER.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
class_am_param.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
class_am_param.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
class_aperture_macro.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
class_aperture_macro.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
class_excellon.h Gerbview: Added: read Excellon files created by Pcbnew. The full Excellon command set is not supported, but drill files created by Pcbnew are supported. 2011-03-16 21:51:20 +01:00
class_gerber_draw_item.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
class_gerber_draw_item.h see CHANGELOG.txt 2012-02-19 22:33:54 -06:00
class_gerbview_layer_widget.cpp Layers manager: add in popup menu option to hide all coppers layers but active layer. 2012-02-17 20:43:43 +01:00
class_gerbview_layer_widget.h Layers manager: add in popup menu option to hide all coppers layers but active layer. 2012-02-17 20:43:43 +01:00
controle.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
dcode.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
dcode.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
draw_gerber_screen.cpp Pcbnew nanometer internal unit fixes. 2012-04-15 21:25:26 -04:00
events_called_functions.cpp Minor code improvements and coding policy fixes. 2012-03-26 19:47:08 -04:00
excellon_read_drill_file.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
export_to_pcbnew.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
files.cpp Kicad project manager: add .cmp, .drl .pos and .rpt files management. 2012-02-16 21:03:33 +01:00
gerbview.cpp Make Gerbview working with USE_PCBNEW_NANOMETRES option ON 2012-04-18 09:07:13 +02:00
gerbview.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
gerbview.icns Update OS X icns icons 2010-05-13 21:03:12 +02:00
gerbview.rc Remove old xpm icons files 2012-04-07 13:09:57 +02:00
gerbview_config.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
gerbview_doc.icns Update OS X icns icons 2010-05-13 21:03:12 +02:00
gerbview_frame.cpp Make Gerbview working with USE_PCBNEW_NANOMETRES option ON 2012-04-18 09:07:13 +02:00
gerbview_frame.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
gerbview_id.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
hotkeys.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
hotkeys.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
initpcb.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
locate.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
menubar.cpp Move AddMenuItem inline functions outside wxstruct.h in a new file (menu_helpers.h) 2012-04-09 11:16:47 +02:00
onleftclick.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
onrightclick.cpp Move AddMenuItem inline functions outside wxstruct.h in a new file (menu_helpers.h) 2012-04-09 11:16:47 +02:00
options.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
pcbplot.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
pcbplot.h Minor dialog fixes and code cleaning. 2011-10-17 16:01:27 -04:00
readgerb.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
rs274_read_XY_and_IJ_coordinates.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
rs274d.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
rs274x.cpp // Dick Hollenbeck's KiROUND R&D 2012-04-19 01:55:45 -05:00
select_layers_to_pcb.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
select_layers_to_pcb.h switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00
toolbars_gerber.cpp switch to <> for includes from "" per conversation with Jean-Pierre and Wayne, adjust search paths 2012-01-22 22:33:36 -06:00