Menu

Why Integer coordinate is still a good idea

Remy LUCAS
2018-03-18
2018-03-24
  • Remy LUCAS

    Remy LUCAS - 2018-03-18

    Hi

    Here I saw several peoples who wants a floating version of clipper

    Angus J. uses integer instead floats to deals with robustness.

    In fact, integer values means fixed point arithmetic instead of floating point arithmetic.

    As explained in documentation, you just need to use a scale factor. For example, I use a 10.000 factor gives me a 0.1µm precision that is strong enough for NC milling or 3D printing.

    And I think that using integer (fixed point arithmetic) coordinate is still a good idea for another important reason.

    Floating point arithmetic is a bad idea when you deals with geometry. Because in floating point arithmetic, the precision is depending on the value, so each time you translate an object, there are rounding errors. So in floating point arithmetic, each time you translate an object you get deformation!

    Indeed, in fixed point arithmetic, you get the same precision regardless of object position.

    That is to say, fixed point arithmetic XY plane is a regular grid plane, but if you use floating point XY coordinates, your XY plane is a strange and insane “variable pitch” grid. So we should never use floating points to deals with geometric problems.

    Thanks

     
  • Ignorant

    Ignorant - 2018-03-23

    well...Angus does integerisation of coordinates after using floating point precions to evaluate intersections...
    But the integerisation of coordinates does help in cuttin down on the number of output polygons without affecting the areal output numerically.!

     
    • Timo Kähkönen

      Timo Kähkönen - 2018-03-23

      The downside is that this integerisation lowers precision. If floats would be used throughout the library, this integerisation is not needed. I mentioned this a while ago to Angus: one cause for minor self intersections can be this integerisation.

       
  • Timo Kähkönen

    Timo Kähkönen - 2018-03-23

    Also float->integer and integer->float cause rounding errors. It is safe to make comparisons using floating point coordinates inside Clipper because bigger float is bigger float the same way bigger integer is bigger integer.