From 61d73ebfd62c0c64bfbdba55b1e95ccc585a9b69 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Tue, 6 Jan 2015 14:09:28 +0000 Subject: [PATCH] Improvements for precision handling --- src/ifcgeom/IfcGeomObjects.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/ifcgeom/IfcGeomObjects.cpp b/src/ifcgeom/IfcGeomObjects.cpp index b8f60e2d5c..9e0b367652 100644 --- a/src/ifcgeom/IfcGeomObjects.cpp +++ b/src/ifcgeom/IfcGeomObjects.cpp @@ -592,6 +592,9 @@ double UnitPrefixToValue( Ifc2x3::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); @@ -617,7 +620,16 @@ void IfcGeomObjects::InitPrecision() { } } if (any_precision_encountered) { - IfcGeom::SetValue(IfcGeom::GV_PRECISION, lowest_precision_encountered); + // Some arbitrary factor that has proven to work better for the models in the set of test files. + lowest_precision_encountered *= 10.; + + lowest_precision_encountered *= unit_magnitude; + if (lowest_precision_encountered < 1.e-7) { + Logger::Message(Logger::LOG_WARNING, "Precision lower than 0.0000001 meter not enforced"); + IfcGeom::SetValue(IfcGeom::GV_PRECISION, 1.e-7); + } else { + IfcGeom::SetValue(IfcGeom::GV_PRECISION, lowest_precision_encountered); + } } } catch (const IfcParse::IfcException& ex) { std::stringstream ss; @@ -626,9 +638,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);