From 4d8026762c42e24b18018f481dca1cf26dfdea95 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 20 Jan 2018 00:02:08 +0100 Subject: [PATCH] avoid division by zero when discretizing a shape --- src/Mod/Part/App/TopoShape.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index ae14f9f133..d9c9230b02 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -3177,8 +3177,10 @@ void TopoShape::getPoints(std::vector &Points, // parameter ranges Standard_Real uFirst = surface.FirstUParameter(); Standard_Real uLast = surface.LastUParameter(); + Standard_Real uMid = (uFirst+uLast)/2; Standard_Real vFirst = surface.FirstVParameter(); Standard_Real vLast = surface.LastVParameter(); + Standard_Real vMid = (vFirst+vLast)/2; // get geometrical length and width of the surface // @@ -3187,11 +3189,11 @@ void TopoShape::getPoints(std::vector &Points, for (int i = 1; i <= pointsPerEdge; i++) { double u1 = static_cast(i-1)/static_cast(pointsPerEdge); double s1 = (1.0-u1)*uFirst + u1*uLast; - p1 = surface.Value(s1,0.0); + p1 = surface.Value(s1,vMid); double u2 = static_cast(i)/static_cast(pointsPerEdge); double s2 = (1.0-u2)*uFirst + u2*uLast; - p2 = surface.Value(s2,0.0); + p2 = surface.Value(s2,vMid); fLengthU += p1.Distance(p2); } @@ -3199,17 +3201,19 @@ void TopoShape::getPoints(std::vector &Points, for (int i = 1; i <= pointsPerEdge; i++) { double v1 = static_cast(i-1)/static_cast(pointsPerEdge); double t1 = (1.0-v1)*vFirst + v1*vLast; - p1 = surface.Value(0.0,t1); + p1 = surface.Value(uMid,t1); double v2 = static_cast(i)/static_cast(pointsPerEdge); double t2 = (1.0-v2)*vFirst + v2*vLast; - p2 = surface.Value(0.0,t2); + p2 = surface.Value(uMid,t2); fLengthV += p1.Distance(p2); } int uPointsPerEdge = static_cast(fLengthU / lateralDistance); int vPointsPerEdge = static_cast(fLengthV / lateralDistance); + uPointsPerEdge = std::max(uPointsPerEdge, 1); + vPointsPerEdge = std::max(vPointsPerEdge, 1); for (int i = 0; i <= uPointsPerEdge; i++) { double u = static_cast(i)/static_cast(uPointsPerEdge);