From b969ebe7cf040e497e7cf840efe52c96fce6d386 Mon Sep 17 00:00:00 2001
From: aka <aka@opencascade.com>
Date: Thu, 27 Oct 2016 16:58:38 +0300
Subject: [PATCH] 0027769: BRepOffsetAPI_MakePipeShell produces a face based on
 degenerated toroidal surface

method BuildKPart was modified in order to create sphere instead of torus in case of major radius <= tolerance
Minor corrections in test case bugs/modalg_6/bug27769
---
 src/GeomFill/GeomFill_Sweep.cxx | 14 +++++++++++---
 tests/bugs/modalg_6/bug27769    | 27 +++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 3 deletions(-)
 create mode 100644 tests/bugs/modalg_6/bug27769

diff --git a/src/GeomFill/GeomFill_Sweep.cxx b/src/GeomFill/GeomFill_Sweep.cxx
index d89fb9095b..f82769730c 100644
--- a/src/GeomFill/GeomFill_Sweep.cxx
+++ b/src/GeomFill/GeomFill_Sweep.cxx
@@ -836,13 +836,21 @@ static Standard_Boolean IsSweepParallelSpine (const Handle(GeomFill_LocationLaw)
 	if (error <= Tol) {
 	  SError = error;
 	  error += Radius + Abs(RotRadius - C.Radius())/2;
-	  if (error <= Tol) {
+          if (error <= Tol || Radius <= Tol) {
 	    // (2.1.a) Sphere
-	    Standard_Real f = UFirst , l =  ULast;
+	    Standard_Real f = UFirst , l =  ULast, aRadius = 0.0;
 	    SError = error;
 	    Centre.BaryCenter(1.0, C.Location(), 1.0); 
 	    gp_Ax3 AxisOfSphere(Centre, DN, DS);
-            gp_Sphere theSphere( AxisOfSphere, (RotRadius + C.Radius())/2 );
+            if (Radius <= Tol)
+            {
+              aRadius = C.Radius();
+            }
+            else
+            {
+              aRadius = (RotRadius + C.Radius()) / 2;
+            }
+            gp_Sphere theSphere( AxisOfSphere, aRadius );
 	    S = new Geom_SphericalSurface(theSphere);
 	    // Pour les spheres on ne peut pas controler le parametre
             // V (donc U car  myExchUV = Standard_True)
diff --git a/tests/bugs/modalg_6/bug27769 b/tests/bugs/modalg_6/bug27769
new file mode 100644
index 0000000000..ae1b6432ff
--- /dev/null
+++ b/tests/bugs/modalg_6/bug27769
@@ -0,0 +1,27 @@
+puts "========"
+puts "OCC27769"
+puts "========"
+puts ""
+#################################################
+# BRepOffsetAPI_MakePipeShell produces a face 
+# based on degenerated toroidal surfaces
+#################################################
+
+restore [locate_data_file bug27769_W5_slot.brep] w
+restore [locate_data_file bug27769_A4_slot.brep] e
+
+wire p e
+mksweep p
+addsweep w
+buildsweep r
+explode r f
+mksurface s1 r_1
+set info [dump s1]
+
+set check [regexp "SphericalSurface" $info]
+
+if { ${check} == 1 } {
+   puts "OK: The basic surface is spherical surface."
+} else {
+   puts "Faulty: The basic surface is not spherical surface."
+}
\ No newline at end of file