From 0fe1715f01b4e03071b6e2bc7c840566042d763b Mon Sep 17 00:00:00 2001
From: azv <azv@opencascade.com>
Date: Wed, 14 Jan 2015 17:26:30 +0300
Subject: [PATCH] 0025582: SIGSEGV in thrusections of circle segments

1. Implemented using of trimmed circular curve
2. Added test case
---
 src/BRepFill/BRepFill_Generator.cxx | 28 +++++++++++++++-------------
 tests/bugs/modalg_5/bug25582        | 19 +++++++++++++++++++
 2 files changed, 34 insertions(+), 13 deletions(-)
 create mode 100644 tests/bugs/modalg_5/bug25582

diff --git a/src/BRepFill/BRepFill_Generator.cxx b/src/BRepFill/BRepFill_Generator.cxx
index 3f7a83869f..f12a486dc7 100644
--- a/src/BRepFill/BRepFill_Generator.cxx
+++ b/src/BRepFill/BRepFill_Generator.cxx
@@ -398,14 +398,16 @@ void CreateKPart(const TopoDS_Edge& Edge1,const TopoDS_Edge& Edge2,
   BW1.MakeWire(newW1);
   BW2.MakeWire(newW2);
 
+  GeomAdaptor_Curve aC1Adaptor(C1);
+  GeomAdaptor_Curve aC2Adaptor(C2);
 
   // calculate the surface
   Handle(Geom_Surface) surface;
   Standard_Real V, Rad;
   if (IType==1) {
     // cylindrical surface
-    gp_Circ c1 = (Handle(Geom_Circle)::DownCast(C1))->Circ();
-    gp_Circ c2 = (Handle(Geom_Circle)::DownCast(C2))->Circ();
+    gp_Circ c1 = aC1Adaptor.Circle();
+    gp_Circ c2 = aC2Adaptor.Circle();
     gp_Ax3 Ac1 = c1.Position();
     V = gp_Vec( c1.Location(),c2.Location()).Dot(gp_Vec(Ac1.Direction()));
     if ( V < 0.) {
@@ -419,7 +421,7 @@ void CreateKPart(const TopoDS_Edge& Edge1,const TopoDS_Edge& Edge2,
   }
   else if (IType==2) {
     // conical surface
-    gp_Circ k1 = (Handle(Geom_Circle)::DownCast(C1))->Circ();
+    gp_Circ k1 = aC1Adaptor.Circle();
     gp_Ax3 Ak1 = k1.Position();
     if (degen2) {
       V = gp_Vec( k1.Location(),BRep_Tool::Pnt(v2f))
@@ -427,7 +429,7 @@ void CreateKPart(const TopoDS_Edge& Edge1,const TopoDS_Edge& Edge2,
       Rad = - k1.Radius();
     }
     else {
-      gp_Circ k2 = (Handle(Geom_Circle)::DownCast(C2))->Circ();
+      gp_Circ k2 = aC2Adaptor.Circle();
       V = gp_Vec( k1.Location(),k2.Location()).Dot(gp_Vec(Ak1.Direction()));
       Rad = k2.Radius() - k1.Radius();
     }
@@ -445,7 +447,7 @@ void CreateKPart(const TopoDS_Edge& Edge1,const TopoDS_Edge& Edge2,
   }
   else if (IType==-2) {
     // conical surface with the top at the beginning (degen1 is true)
-    gp_Circ k2 = (Handle(Geom_Circle)::DownCast(C2))->Circ();
+    gp_Circ k2 = aC2Adaptor.Circle();
     gp_Ax3 Ak2 = k2.Position();
     Ak2.SetLocation(BRep_Tool::Pnt(v1f));
     V = gp_Vec(BRep_Tool::Pnt(v1f),k2.Location())
@@ -469,15 +471,15 @@ void CreateKPart(const TopoDS_Edge& Edge1,const TopoDS_Edge& Edge2,
     // surface plane
     gp_Lin L1, L2, aLine;
     if (!degen1)
-      {
-	L1 = (Handle(Geom_Line)::DownCast(C1))->Lin();
-	aLine = L1;
-      }
+    {
+      L1 = aC1Adaptor.Line();
+      aLine = L1;
+    }
     if (!degen2)
-      {
-	L2 = (Handle(Geom_Line)::DownCast(C2))->Lin();
-	aLine = L2;
-      }
+    {
+      L2 = aC2Adaptor.Line();
+      aLine = L2;
+    }
 
     gp_Pnt P1 = (degen1)? BRep_Tool::Pnt(v1f) : L1.Location();
     gp_Pnt P2 = (degen2)? BRep_Tool::Pnt(v2f) : L2.Location();
diff --git a/tests/bugs/modalg_5/bug25582 b/tests/bugs/modalg_5/bug25582
new file mode 100644
index 0000000000..9ac7d8b914
--- /dev/null
+++ b/tests/bugs/modalg_5/bug25582
@@ -0,0 +1,19 @@
+puts "============"
+puts "OCC25582"
+puts "============"
+puts ""
+#########################################################################
+# SIGSEGV in thrusections on coaxial circlular segments
+#########################################################################
+
+restore [locate_data_file bug25582_filletloft-draw-Loft-00-section.brep] Loft-00-section
+restore [locate_data_file bug25582_filletloft-draw-Loft-01-section.brep] Loft-01-section
+
+thrusections result 0 0 Loft-00-section Loft-01-section
+
+if ![isdraw result] {
+  puts "Error : thrusections failed"
+}
+
+set square 1.5708
+set 2dviewer 0