Salome HOME
Fix for the issue #2753 : error when dump/load script
[modules/shaper.git] / src / GeomAPI / GeomAPI_Wire.cpp
index 32df6d6bbc55e39207ade979d5e3e2810ec063e2..05062a145cc25abc95b00133c5c7e91a7f52c145 100644 (file)
@@ -81,6 +81,8 @@ bool GeomAPI_Wire::isPolygon(std::list<GeomPointPtr>& thePoints) const
 //==================================================================================================
 bool GeomAPI_Wire::isRectangle(std::list<GeomPointPtr>& thePoints) const
 {
+  thePoints.clear();
+
   const TopoDS_Wire& aWire = TopoDS::Wire(impl<TopoDS_Shape>());
   const Handle(Standard_Type)& aLineType = STANDARD_TYPE(Geom_Line);
 
@@ -104,6 +106,9 @@ bool GeomAPI_Wire::isRectangle(std::list<GeomPointPtr>& thePoints) const
     gp_Pnt aStart = aC3D->Value(aT1);
     gp_Pnt aEnd = aC3D->Value(aT2);
 
+    if (aStart.Distance(aEnd) <= Precision::Confusion())
+      return false;
+
     // check the edge is orthogonal to the previous
     gp_XYZ aCurDir = (aEnd.XYZ() - aStart.XYZ()).Normalized();
     if (aPrevDir.Dot(aCurDir) < Precision::Confusion())
@@ -113,3 +118,20 @@ bool GeomAPI_Wire::isRectangle(std::list<GeomPointPtr>& thePoints) const
   }
   return true;
 }
+
+//==================================================================================================
+GeomPointPtr GeomAPI_Wire::middlePoint() const
+{
+  // find middle edge in the wire
+  std::list<GeomShapePtr> aSubs = subShapes(EDGE);
+  size_t aNbSubs = aSubs.size();
+  if (aNbSubs == 0)
+    return GeomPointPtr();
+
+  aNbSubs /= 2;
+  for (; aNbSubs > 0; --aNbSubs)
+    aSubs.pop_front();
+
+  // compute middle point on the middle edge
+  return aSubs.front()->middlePoint();
+}