Skip to content

Class RyuDouble returns inappropriate values #35

@christianAppl

Description

@christianAppl

First of all:
This is a nice and simple solution and I really like it!

Issue:
Using this fine library I tried to draw a path that contained a point with the Y-coordinate 9.62E-4.
In the created SVG the Y-coordinate for said point was set to 9.62 instead, which lead to a unrecognizable Glyph in the result.

Observations:
Following this, I tried to find the cause of the issue and ended up playing arround with the class "RyuDouble" at the end.
As far as I understood it, Ryu is a method to create a String representing a floating point number (with increased speed and performance, when compared to other methods) and as far as I could see your intention was, to not only implement that method, but to also limit the maximum number of fractional digits to 4.

I tried to pinpoint my issue, by comparing the results of "RyuDouble.doubleToString(double value, int decimals)" to those of a simple DecimalFormat (which is simply dropping fractional digits beyond 4):

public static String doubleToString(double value, int decimals) {
   DecimalFormat decimalFormat = new DecimalFormat("#.#");
   decimalFormat.setMaximumFractionDigits(decimals);

   DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols();
   decimalFormatSymbols.setDecimalSeparator('.');
   decimalFormat.setDecimalFormatSymbols(decimalFormatSymbols);

   return decimalFormat.format(value);
}

My results were as follows:

>>> LIMIT ALL VALUES TO 4 FRACTION DIGITS 
VALUE: '0'
   RYU_DOUBLE: '0.0'
   DECIMAL_FORMAT: '0'

VALUE: '0.000000000001'
   RYU_DOUBLE: '1.'
   DECIMAL_FORMAT: '0'

VALUE: '-1'
   RYU_DOUBLE: '-1.0'
   DECIMAL_FORMAT: '-1'

VALUE: '-0.0001'
   RYU_DOUBLE: '-1.0E-'
   DECIMAL_FORMAT: '-0.0001'

VALUE: '0.0001'
   RYU_DOUBLE: '1.0E-'
   DECIMAL_FORMAT: '0.0001'

VALUE: '0.01'
   RYU_DOUBLE: '0.01'
   DECIMAL_FORMAT: '0.01'

VALUE: '1000'
   RYU_DOUBLE: '1000.0'
   DECIMAL_FORMAT: '1000'

VALUE: '10000'
   RYU_DOUBLE: '10000.0'
   DECIMAL_FORMAT: '10000'

VALUE: '1000000000'
   RYU_DOUBLE: '1.0E9'
   DECIMAL_FORMAT: '1000000000'

Issues with "RyuDouble":

  1. Some of the results yielded by "RyuDouble.doubleToString" are clearly incorrect or incomplete. (i.e. results for values '0.0001' and '0.000000000001')

  2. I am not entirely sure, whether SVG does support the scientific notation at all!? Hence I did enforce a "raw number format" in my approach.

  3. Even though I could find a recommendation to only use 2 fractional digits in SVG paths, I don't know whether I like the intended loss of precision (4 fractional digits). Is it really necessary to do this? I tried replacing "doubleToString" in "SVGGraphics2D" with my primitive approach - not limiting the maximum number of fractional digits - and the resulting SVG displayed just fine. (If it is necessary, I would rather round values?)

Assumption:
I did not read the paper concerning the Ryu method, therefore I can not claim this to be correct: But I would assume, that the combination of the Ryu method and the limitting of the fractional digits may cause the issue here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions