X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FGeomAPI%2FGeomAPI_Ellipse.cpp;h=fcfbbb3363f5f663f1265a8a57e27d8101e56924;hb=50a8df0c6a66da8067b16155e5ae39f8f26a7ebc;hp=2d47a5a6f7a9612d68505f303b05821b8a69bdb3;hpb=a299eecbf62594492e777394588e4cf2e6ba11c3;p=modules%2Fshaper.git diff --git a/src/GeomAPI/GeomAPI_Ellipse.cpp b/src/GeomAPI/GeomAPI_Ellipse.cpp index 2d47a5a6f..fcfbbb336 100644 --- a/src/GeomAPI/GeomAPI_Ellipse.cpp +++ b/src/GeomAPI/GeomAPI_Ellipse.cpp @@ -1,4 +1,21 @@ -// Copyright (C) 2014-20xx 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// 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 +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// // File: GeomAPI_Ellipse.cpp // Created: 25 April 2017 @@ -6,8 +23,12 @@ #include "GeomAPI_Ellipse.h" #include "GeomAPI_Ax2.h" +#include "GeomAPI_Curve.h" #include "GeomAPI_Pnt.h" +#include +#include +#include #include #define MY_ELIPS implPtr() @@ -18,6 +39,16 @@ GeomAPI_Ellipse::GeomAPI_Ellipse(const std::shared_ptr& theAx2, { } +GeomAPI_Ellipse::GeomAPI_Ellipse(GeomCurvePtr theCurve) +{ + GeomCurvePtr anUntrimmedCurve = theCurve->basisCurve(); + Handle(Geom_Curve) aCurve = anUntrimmedCurve->impl(); + 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_Ellipse::center() const { const gp_Pnt& aCenter = MY_ELIPS->Location(); @@ -36,6 +67,13 @@ GeomPointPtr GeomAPI_Ellipse::secondFocus() const return std::shared_ptr(new GeomAPI_Pnt(aSecond.X(), aSecond.Y(), aSecond.Z())); } +std::shared_ptr GeomAPI_Ellipse::normal() const +{ + const gp_Ax1& anAxis = MY_ELIPS->Axis(); + const gp_Dir& aDir = anAxis.Direction(); + return std::shared_ptr(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z())); +} + double GeomAPI_Ellipse::minorRadius() const { return MY_ELIPS->MinorRadius(); @@ -45,3 +83,32 @@ double GeomAPI_Ellipse::majorRadius() const { return MY_ELIPS->MajorRadius(); } + +const std::shared_ptr GeomAPI_Ellipse::project( + const std::shared_ptr& thePoint) const +{ + std::shared_ptr aResult; + if (!MY_ELIPS) + return aResult; + + Handle(Geom_Ellipse) aEllipse = new Geom_Ellipse(*MY_ELIPS); + + const gp_Pnt& aPoint = thePoint->impl(); + + 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 thePoint, + const double theTolerance, + double& theParameter) const +{ + Handle(Geom_Ellipse) aCurve = new Geom_Ellipse(*MY_ELIPS); + return GeomLib_Tool::Parameter(aCurve, thePoint->impl(), + theTolerance, theParameter) == Standard_True; +}