From a5278fc126a36055aa61c4fa3a5ee7331a1801ab Mon Sep 17 00:00:00 2001
From: jgv <jgv@opencascade.com>
Date: Tue, 2 Apr 2019 14:14:00 +0300
Subject: [PATCH] 0030597: BRepOffsetAPI_MakePipeShell raises
 Standard_RangeError

Constructor of GeomFill_SectionPlacement has been corrected: add correction of boundaries of curve to avoid mistake of LocateU in the case when the curve is BSpline.
---
 src/GeomFill/GeomFill_SectionPlacement.cxx | 15 +++++++++++++++
 tests/bugs/modalg_7/bug30597               | 19 +++++++++++++++++++
 2 files changed, 34 insertions(+)
 create mode 100644 tests/bugs/modalg_7/bug30597

diff --git a/src/GeomFill/GeomFill_SectionPlacement.cxx b/src/GeomFill/GeomFill_SectionPlacement.cxx
index e4223d827f..98e1a2306c 100644
--- a/src/GeomFill/GeomFill_SectionPlacement.cxx
+++ b/src/GeomFill/GeomFill_SectionPlacement.cxx
@@ -283,6 +283,21 @@ GeomFill_SectionPlacement(const Handle(GeomFill_LocationLaw)& L,
 	  Handle(TColgp_HArray1OfPnt) Pnts;
 	  Standard_Real first = myAdpSection.FirstParameter();
 	  Standard_Real last =  myAdpSection.LastParameter();
+          if (myAdpSection.IsPeriodic())
+          {
+            //Correct boundaries to avoid mistake of LocateU
+            Handle(Geom_Curve) aCurve = myAdpSection.Curve();
+            if (aCurve->IsInstance(STANDARD_TYPE(Geom_TrimmedCurve)))
+              aCurve = (Handle(Geom_TrimmedCurve)::DownCast(aCurve))->BasisCurve();
+            Standard_Real Ufirst = aCurve->FirstParameter();
+            Standard_Real aPeriod = aCurve->Period();
+            Standard_Real U1 = Ufirst + Floor((first - Ufirst)/aPeriod) * aPeriod;
+            Standard_Real U2 = U1 + aPeriod;
+            if (Abs(first - U1) <= Precision::PConfusion())
+              first = U1;
+            if (Abs(last - U2) <= Precision::PConfusion())
+              last = U2;
+          }
 	  Standard_Real t, delta;
 	  if (myAdpSection.GetType() == GeomAbs_BSplineCurve)
 	    {
diff --git a/tests/bugs/modalg_7/bug30597 b/tests/bugs/modalg_7/bug30597
new file mode 100644
index 0000000000..6f09f09b25
--- /dev/null
+++ b/tests/bugs/modalg_7/bug30597
@@ -0,0 +1,19 @@
+puts "================================================================"
+puts "OCC30597: BRepOffsetAPI_MakePipeShell raises Standard_RangeError"
+puts "================================================================"
+puts ""
+
+restore [locate_data_file bug30597_compound.brep] a
+explode a
+
+explode a_1 v
+explode a_2
+explode a_3
+
+mksweep a_1
+addsweep a_2_1 a_1_1
+addsweep a_3_1 a_1_2
+
+buildsweep result
+
+checkprops result -s 0.95884