From eb815120dc6261975d8615b71c67c445e4ac1073 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Wed, 26 Nov 2014 13:08:47 +0000 Subject: [PATCH] Take unit information into account when applying precision. Thanks Stefan --- src/ifcgeom/IfcGeomObjects.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ifcgeom/IfcGeomObjects.cpp b/src/ifcgeom/IfcGeomObjects.cpp index c945a57f24..f1b3a55498 100644 --- a/src/ifcgeom/IfcGeomObjects.cpp +++ b/src/ifcgeom/IfcGeomObjects.cpp @@ -606,6 +606,9 @@ double UnitPrefixToValue( IfcSchema::IfcSIPrefix::IfcSIPrefix v ) { else return 1.0f; } +static std::string unit_name = "METER"; +static float unit_magnitude = 1.0f; + void IfcGeomObjects::InitPrecision() { IfcGeom::SetValue(IfcGeom::GV_PRECISION, 0.00001); @@ -631,7 +634,13 @@ void IfcGeomObjects::InitPrecision() { } } if (any_precision_encountered) { - IfcGeom::SetValue(IfcGeom::GV_PRECISION, lowest_precision_encountered); + lowest_precision_encountered *= unit_magnitude; + if (lowest_precision_encountered < 1.e-8) { + Logger::Message(Logger::LOG_WARNING, "Precision lower than 0.00000001 meter not enforced"); + IfcGeom::SetValue(IfcGeom::GV_PRECISION, 1.e-8); + } else { + IfcGeom::SetValue(IfcGeom::GV_PRECISION, lowest_precision_encountered); + } } } catch (const IfcParse::IfcException& ex) { std::stringstream ss; @@ -640,9 +649,6 @@ void IfcGeomObjects::InitPrecision() { } } -static std::string unit_name = "METER"; -static float unit_magnitude = 1.0f; - void IfcGeomObjects::InitUnits() { // Set default units, set length to meters, angles to undefined IfcGeom::SetValue(IfcGeom::GV_LENGTH_UNIT,1.0);