From c08aa3216d4734be572b7d6d36b1561ee961e558 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Sat, 10 Dec 2016 14:11:01 +0100 Subject: [PATCH] Fix #163 Disallow narrow IfcPolygonalBoundedHalfSpace --- src/ifcgeom/IfcGeom.h | 1 + src/ifcgeom/IfcGeomFunctions.cpp | 4 ++-- src/ifcgeom/IfcGeomShapes.cpp | 11 +++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ifcgeom/IfcGeom.h b/src/ifcgeom/IfcGeom.h index b2abcdcb5c..c485d6e347 100644 --- a/src/ifcgeom/IfcGeom.h +++ b/src/ifcgeom/IfcGeom.h @@ -43,6 +43,7 @@ inline static bool ALMOST_THE_SAME(const T& a, const T& b, double tolerance=ALMO #include #include #include +#include #include "../ifcparse/IfcParse.h" #include "../ifcparse/IfcUtil.h" diff --git a/src/ifcgeom/IfcGeomFunctions.cpp b/src/ifcgeom/IfcGeomFunctions.cpp index 58db91d02e..2e6e501771 100644 --- a/src/ifcgeom/IfcGeomFunctions.cpp +++ b/src/ifcgeom/IfcGeomFunctions.cpp @@ -948,7 +948,7 @@ bool IfcGeom::Kernel::flatten_shape_list(const IfcGeom::IfcRepresentationShapeIt } void IfcGeom::Kernel::remove_duplicate_points_from_loop(TColgp_SequenceOfPnt& polygon, bool closed, double tol) { - if (tol <= 0.) tol = getValue(GV_POINT_EQUALITY_TOLERANCE); + if (tol <= 0.) tol = getValue(GV_PRECISION); tol *= tol; for (;;) { @@ -972,7 +972,7 @@ void IfcGeom::Kernel::remove_duplicate_points_from_loop(TColgp_SequenceOfPnt& po } void IfcGeom::Kernel::remove_collinear_points_from_loop(TColgp_SequenceOfPnt& polygon, bool closed, double tol) { - if (tol <= 0.) tol = getValue(GV_POINT_EQUALITY_TOLERANCE); + if (tol <= 0.) tol = getValue(GV_PRECISION); const int start = closed ? 1 : 2; const int end = polygon.Length() - (closed ? 0 : 1); std::vector to_remove(polygon.Length(), false); diff --git a/src/ifcgeom/IfcGeomShapes.cpp b/src/ifcgeom/IfcGeomShapes.cpp index d4abfa3ff9..650da7d07e 100644 --- a/src/ifcgeom/IfcGeomShapes.cpp +++ b/src/ifcgeom/IfcGeomShapes.cpp @@ -433,8 +433,15 @@ bool IfcGeom::Kernel::convert(const IfcSchema::IfcPolygonalBoundedHalfSpace* l, TColgp_SequenceOfPnt points; if (wire_to_sequence_of_point(wire, points)) { - remove_duplicate_points_from_loop(points, wire.Closed() != 0); // Note: wire always closed, as per if statement above - remove_collinear_points_from_loop(points, wire.Closed() != 0); + // Boolean subtractions not very robust for narrow operands, + // increase minimal point spacing to eliminate such shapes. + const double t = getValue(GV_PRECISION) * 10.; + remove_duplicate_points_from_loop(points, wire.Closed() != 0, t); // Note: wire always closed, as per if statement above + remove_collinear_points_from_loop(points, wire.Closed() != 0, t); + if (points.Size() < 3) { + Logger::Message(Logger::LOG_ERROR, "Not enough points retained from:", l->PolygonalBoundary()->entity); + return false; + } sequence_of_point_to_wire(points, wire, wire.Closed() != 0); }