-// Copyright (C) 2017 CEA/DEN, EDF R&D
+// Copyright (C) 2017-2020 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// File: GeomAPI_Ellipse.cpp
#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 <GeomLib_Tool.hxx>
#include <gp_Elips.hxx>
#define MY_ELIPS implPtr<gp_Elips>()
{
}
+GeomAPI_Ellipse::GeomAPI_Ellipse(GeomCurvePtr theCurve)
+{
+ GeomCurvePtr anUntrimmedCurve = theCurve->basisCurve();
+ Handle(Geom_Curve) aCurve = anUntrimmedCurve->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();
return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSecond.X(), aSecond.Y(), aSecond.Z()));
}
+std::shared_ptr<GeomAPI_Dir> GeomAPI_Ellipse::normal() const
+{
+ const gp_Ax1& anAxis = MY_ELIPS->Axis();
+ const gp_Dir& aDir = anAxis.Direction();
+ return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
+}
+
double GeomAPI_Ellipse::minorRadius() const
{
return MY_ELIPS->MinorRadius();
{
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;
+}
+
+const bool GeomAPI_Ellipse::parameter(const std::shared_ptr<GeomAPI_Pnt> thePoint,
+ const double theTolerance,
+ double& theParameter) const
+{
+ Handle(Geom_Ellipse) aCurve = new Geom_Ellipse(*MY_ELIPS);
+ return GeomLib_Tool::Parameter(aCurve, thePoint->impl<gp_Pnt>(),
+ theTolerance, theParameter) == Standard_True;
+}