]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/GeomAPI/GeomAPI_Ellipse.cpp
Salome HOME
Task 2.12. New entities: ellipses and arcs of ellipses (issue #3003)
[modules/shaper.git] / src / GeomAPI / GeomAPI_Ellipse.cpp
index c9384724ac380a8ea90abedfbdb278e172b37652..243be630e507b5ae4ff99c22285dd24a06983e79 100644 (file)
 
 #include "GeomAPI_Ellipse.h"
 #include "GeomAPI_Ax2.h"
+#include "GeomAPI_Curve.h"
 #include "GeomAPI_Pnt.h"
 
+#include <Geom_Ellipse.hxx>
+#include <GeomAPI_ProjectPointOnCurve.hxx>
 #include <gp_Elips.hxx>
 
 #define MY_ELIPS implPtr<gp_Elips>()
@@ -35,6 +38,15 @@ GeomAPI_Ellipse::GeomAPI_Ellipse(const std::shared_ptr<GeomAPI_Ax2>& theAx2,
 {
 }
 
+GeomAPI_Ellipse::GeomAPI_Ellipse(GeomCurvePtr theCurve)
+{
+  Handle(Geom_Curve) aCurve = theCurve->impl<Handle(Geom_Curve)>();
+  Handle(Geom_Ellipse) anEllipse = Handle(Geom_Ellipse)::DownCast(aCurve);
+  if (anEllipse.IsNull())
+    throw Standard_ConstructionError("GeomAPI_Ellipse: Curve is not an ellipse");
+  setImpl(new gp_Elips(anEllipse->Elips()));
+}
+
 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Ellipse::center() const
 {
   const gp_Pnt& aCenter = MY_ELIPS->Location();
@@ -69,3 +81,23 @@ double GeomAPI_Ellipse::majorRadius() const
 {
   return MY_ELIPS->MajorRadius();
 }
+
+const std::shared_ptr<GeomAPI_Pnt> GeomAPI_Ellipse::project(
+    const std::shared_ptr<GeomAPI_Pnt>& thePoint) const
+{
+  std::shared_ptr<GeomAPI_Pnt> aResult;
+  if (!MY_ELIPS)
+    return aResult;
+
+  Handle(Geom_Ellipse) aEllipse = new Geom_Ellipse(*MY_ELIPS);
+
+  const gp_Pnt& aPoint = thePoint->impl<gp_Pnt>();
+
+  GeomAPI_ProjectPointOnCurve aProj(aPoint, aEllipse);
+  Standard_Integer aNbPoint = aProj.NbPoints();
+  if (aNbPoint > 0) {
+    gp_Pnt aNearest = aProj.NearestPoint();
+    aResult = GeomPointPtr(new GeomAPI_Pnt(aNearest.X(), aNearest.Y(), aNearest.Z()));
+  }
+  return aResult;
+}