RA-Consulting-GmbH / openscenario.api.test

Apache License 2.0
38 stars 11 forks source link

Loss of double value precision in XmlExportHelper::ToXmlStringFromDouble #202

Open shankarpatali-stla opened 11 months ago

shankarpatali-stla commented 11 months ago

Describe the bug While converting double values to string using XmlExportHelper::ToXmlStringFromDouble the precision is lost. This creates problems like position values being not correctly exported.

Hint: This might have been caused by std::to_string. It uses default precision of 6.

To Reproduce Steps to reproduce the behavior:

  1. Create a XOSC scenario where an object position defined with GeoPosition. GeoPosition has latitude and longitude vales of type double.
  2. Export the scenario using OpenScenarioXmlExporter.
  3. Check the position values or any double values in the exported scenario.
  4. Print the exported scenario like this: tinyxml2::XMLPrinter printer; xml_document->RootElement()->Accept(&printer); std::cout << printer.CStr() << std::endl;

Expected behavior Precision of double values are not lost

Screenshots None

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

arauschert commented 11 months ago

Original:

      <Position>
        <GeoPosition latitude="0.8416155582" longitude="0.2047521722"/>
      </Position>

Exported:

            <Position>
                <GeoPosition latitude="0.841616" longitude="0.204752"/>
            </Position>
ahege commented 10 months ago

Thank you for your ticket, and thank you for the example. Either, we could simply set up the precision to a higher constant value (e.g. 10). But this solution is not generic. In a more generic way we have to store the precision that comes with a document that was read in and keep the precision for every single double value wen exporting it.

We will investigate the bug as soon as we can. We are planning a bugfix release for October.