From 973f7d55bd2c99dd8378a0870b4629ab56eaeeed Mon Sep 17 00:00:00 2001
From: oan <oan@opencascade.com>
Date: Tue, 21 Jan 2020 13:21:38 +0300
Subject: [PATCH] 0031258: Mesh - OCCT 7.4.0 VIS get wrong render data

Check intervals for infinite value causing exception in GeomLib::NormEstim
---
 src/BRepMesh/BRepMesh_NURBSRangeSplitter.cxx |  6 ++++++
 tests/bugs/mesh/bug31258                     | 16 ++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 tests/bugs/mesh/bug31258

diff --git a/src/BRepMesh/BRepMesh_NURBSRangeSplitter.cxx b/src/BRepMesh/BRepMesh_NURBSRangeSplitter.cxx
index 332be97de3..429a18035f 100644
--- a/src/BRepMesh/BRepMesh_NURBSRangeSplitter.cxx
+++ b/src/BRepMesh/BRepMesh_NURBSRangeSplitter.cxx
@@ -269,11 +269,17 @@ namespace
     for (; aIntervalU <= theIntervals[0].Upper (); ++aIntervalU)
     {
       const Standard_Real aParamU = theIntervals[0].Value(aIntervalU);
+      if (Precision::IsInfinite (aParamU))
+        continue;
+
       Standard_Integer aIntervalV = theIntervals[1].Lower ();
       for (; aIntervalV <= theIntervals[1].Upper (); ++aIntervalV)
       {
         gp_Dir aNorm;
         const Standard_Real aParamV = theIntervals[1].Value(aIntervalV);
+        if (Precision::IsInfinite (aParamV))
+          continue;
+
         if (GeomLib::NormEstim (theSurf, gp_Pnt2d (aParamU, aParamV), Precision::Confusion (), aNorm) != 0)
         {
           return Standard_True;
diff --git a/tests/bugs/mesh/bug31258 b/tests/bugs/mesh/bug31258
new file mode 100644
index 0000000000..d5a716f80e
--- /dev/null
+++ b/tests/bugs/mesh/bug31258
@@ -0,0 +1,16 @@
+puts "======="
+puts "0031258: Mesh - OCCT 7.4.0 VIS get wrong render data"
+puts "======="
+puts ""
+
+restore [locate_data_file bug31258.brep] result
+tclean result
+
+vinit
+vsetdispmode 1
+vdisplay result
+vfit
+
+checktrinfo result -tri 166 -nod 102
+
+checkview -screenshot -3d -path ${imagedir}/${test_image}.png