From f8974b7209e09ed10992565389ce97eafa5582a8 Mon Sep 17 00:00:00 2001 From: aramis_acg Date: Wed, 17 Oct 2012 00:32:59 +0000 Subject: [PATCH] - Ifc: explicitly clamp some computations to [0,1] even if this is already their (arithmetically) defined range to improve numerical robustness. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1309 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/IFCGeometry.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/code/IFCGeometry.cpp b/code/IFCGeometry.cpp index ea54a9525..61442bdba 100644 --- a/code/IFCGeometry.cpp +++ b/code/IFCGeometry.cpp @@ -1437,6 +1437,8 @@ bool TryAddOpenings_Quadrulate(const std::vector& openings, { std::vector& out = curmesh.verts; + const IfcVector2 one_vec = IfcVector2(static_cast(1.0),static_cast(1.0)); + // Try to derive a solid base plane within the current surface for use as // working coordinate system. const IfcMatrix3& m = DerivePlaneCoordinateSpace(curmesh); @@ -1478,6 +1480,10 @@ bool TryAddOpenings_Quadrulate(const std::vector& openings, BOOST_FOREACH(IfcVector2& vv, contour_flat) { vv.x = (vv.x - vmin.x) / vmax.x; vv.y = (vv.y - vmin.y) / vmax.y; + + // sanity rounding + vv = std::max(vv,IfcVector2()); + vv = std::min(vv,one_vec); } // project all openings into the coordinate system defined by the p+sv*tu plane @@ -1521,7 +1527,7 @@ bool TryAddOpenings_Quadrulate(const std::vector& openings, vv.y = (vv.y - vmin.y) / vmax.y; vv = std::max(vv,IfcVector2()); - vv = std::min(vv,IfcVector2(static_cast(1.0),static_cast(1.0))); + vv = std::min(vv,one_vec); vpmin = std::min(vpmin,vv); vpmax = std::max(vpmax,vv); @@ -1567,7 +1573,11 @@ bool TryAddOpenings_Quadrulate(const std::vector& openings, contour.clear(); BOOST_FOREACH(const ClipperLib::IntPoint& point, poly[0].outer) { - contour.push_back( IfcVector2( from_int64(point.X), from_int64(point.Y))); + IfcVector2 vv = IfcVector2( from_int64(point.X), from_int64(point.Y)); + vv = std::max(vv,IfcVector2()); + vv = std::min(vv,one_vec); + + contour.push_back( vv ); } bb.first = std::min(bb.first, ibb.first);