From ac2494968c1b617a98646c1df4791b66e518997e Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Wed, 9 Sep 2020 14:20:15 +0200 Subject: [PATCH] Actualize trapezium profile per https://forums.buildingsmart.org/t/how-are-the-sides-of-ifctrapeziumprofiledefs-bounding-box-calculated-in-most-implementations/2945/8 --- src/ifcgeom/IfcGeomFaces.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/ifcgeom/IfcGeomFaces.cpp b/src/ifcgeom/IfcGeomFaces.cpp index 332b1321b0..356627ae31 100644 --- a/src/ifcgeom/IfcGeomFaces.cpp +++ b/src/ifcgeom/IfcGeomFaces.cpp @@ -584,10 +584,14 @@ bool IfcGeom::Kernel::convert(const IfcSchema::IfcRectangleHollowProfileDef* l, } bool IfcGeom::Kernel::convert(const IfcSchema::IfcTrapeziumProfileDef* l, TopoDS_Shape& face) { - const double x1 = l->BottomXDim() / 2.0f * getValue(GV_LENGTH_UNIT); + const double x1 = l->BottomXDim() / 2. * getValue(GV_LENGTH_UNIT); const double w = l->TopXDim() * getValue(GV_LENGTH_UNIT); const double dx = l->TopXOffset() * getValue(GV_LENGTH_UNIT); - const double y = l->YDim() / 2.0f * getValue(GV_LENGTH_UNIT); + const double y = l->YDim() / 2. * getValue(GV_LENGTH_UNIT); + + // See: https://forums.buildingsmart.org/t/how-are-the-sides-of-ifctrapeziumprofiledefs-bounding-box-calculated-in-most-implementations/2945/8 + // The trapezium x center should not be midway of BottomXDim but rather at the center of the overall bounding box. + const double x_offset = ((std::min(dx, 0.) + std::max(w + dx, x1 * 2.)) / 2.) - x1; if ( x1 < ALMOST_ZERO || w < ALMOST_ZERO || y < ALMOST_ZERO ) { Logger::Message(Logger::LOG_NOTICE,"Skipping zero sized profile:",l); @@ -603,7 +607,12 @@ bool IfcGeom::Kernel::convert(const IfcSchema::IfcTrapeziumProfileDef* l, TopoDS IfcGeom::Kernel::convert(l->Position(), trsf2d); } - double coords[8] = {-x1,-y, x1,-y, dx+w-x1,y, dx-x1,y}; + double coords[8] = { + -x1 - x_offset, -y, + +x1 - x_offset, -y, + -x1 + dx + w - x_offset, y, + -x1 + dx - x_offset,y + }; return profile_helper(4,coords,0,0,0,trsf2d,face); }