X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAPI%2FGeomAPI_Circ2d.cpp;h=5204f25e5ca5def7ac0d599552ca98c73737a5fd;hb=b6cb9a5e9ecc1c5dae69d686fa73a8afec92d04f;hp=27854d2a943194acfa1dc3536051feb6b42ce235;hpb=258a626d26271b93bae55eb0803de020e2b6f315;p=modules%2Fshaper.git diff --git a/src/GeomAPI/GeomAPI_Circ2d.cpp b/src/GeomAPI/GeomAPI_Circ2d.cpp index 27854d2a9..5204f25e5 100644 --- a/src/GeomAPI/GeomAPI_Circ2d.cpp +++ b/src/GeomAPI/GeomAPI_Circ2d.cpp @@ -1,32 +1,44 @@ -// File: GeomAPI_Circ2d.cpp -// Created: 29 May 2014 -// Author: Artem ZHIDKOV +// Copyright (C) 2014-2019 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 +// #include #include #include -#include #include #include -#include +#include #include -#include #include -#include +#define MY_CIRC2D implPtr() -#define MY_CIRC2D static_cast(myImpl) -static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY, - const gp_Dir2d theDir, const double theRadius) +static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY, const gp_Dir2d theDir, + const double theRadius) { gp_Pnt2d aCenter(theCenterX, theCenterY); return new gp_Circ2d(gp_Ax2d(aCenter, theDir), theRadius); } static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY, - const double thePointX, const double thePointY) + const double thePointX, const double thePointY) { gp_Pnt2d aCenter(theCenterX, theCenterY); gp_Pnt2d aPoint(thePointX, thePointY); @@ -34,54 +46,88 @@ static gp_Circ2d* newCirc2d(const double theCenterX, const double theCenterY, double aRadius = aCenter.Distance(aPoint); if (aCenter.IsEqual(aPoint, Precision::Confusion())) - return NULL; + return NULL; + + gp_Dir2d aDir(thePointX - theCenterX, thePointY - theCenterY); - gp_Dir2d aDir(theCenterX - thePointX, theCenterY - thePointY); - return newCirc2d(theCenterX, theCenterY, aDir, aRadius); } -GeomAPI_Circ2d::GeomAPI_Circ2d(const boost::shared_ptr& theCenter, - const boost::shared_ptr& theCirclePoint) - : GeomAPI_Interface(newCirc2d(theCenter->x(), theCenter->y(), - theCirclePoint->x(), theCirclePoint->y())) -{} - -GeomAPI_Circ2d::GeomAPI_Circ2d(const boost::shared_ptr& theCenter, - const boost::shared_ptr& theDir, - double theRadius) - : GeomAPI_Interface(newCirc2d(theCenter->x(), theCenter->y(), - theDir->impl(), theRadius)) + + +GeomAPI_Circ2d::GeomAPI_Circ2d(const std::shared_ptr& theCenter, + const std::shared_ptr& theCirclePoint) + : GeomAPI_Interface( + newCirc2d(theCenter->x(), theCenter->y(), theCirclePoint->x(), theCirclePoint->y())) { +} +GeomAPI_Circ2d::GeomAPI_Circ2d(const std::shared_ptr& theCenter, + const std::shared_ptr& theDir, double theRadius) + : GeomAPI_Interface( + newCirc2d(theCenter->x(), theCenter->y(), theDir->impl(), theRadius)) +{ } -const boost::shared_ptr GeomAPI_Circ2d::project(const boost::shared_ptr& thePoint) const +const std::shared_ptr GeomAPI_Circ2d::project( + const std::shared_ptr& thePoint) const { - boost::shared_ptr aResult; + std::shared_ptr aResult; if (!MY_CIRC2D) return aResult; - Handle(Geom2d_Circle) aCircle = new Geom2d_Circle(MY_CIRC2D->Axis(), MY_CIRC2D->Radius());//(aCirc); - + const gp_Pnt2d& aCenter = MY_CIRC2D->Location(); const gp_Pnt2d& aPoint = thePoint->impl(); - Geom2dAPI_ProjectPointOnCurve aProj(aPoint, aCircle); - Standard_Integer aNbPoint = aProj.NbPoints(); - double aX, anY; - if (aNbPoint > 0) { - double aMinDistance = 0, aDistance; - for (Standard_Integer j = 1; j <= aNbPoint; j++) { - gp_Pnt2d aNewPoint = aProj.Point(j); - aDistance = aNewPoint.Distance(aPoint); - if (!aMinDistance || aDistance < aMinDistance) { - aX = aNewPoint.X(); - anY = aNewPoint.Y(); - aMinDistance = aDistance; - aResult = boost::shared_ptr(new GeomAPI_Pnt2d(aX, anY)); - } - } + double aDist = aCenter.Distance(aPoint); + if (aDist < Precision::Confusion()) + return aResult; + + if (Abs(aDist - MY_CIRC2D->Radius()) < Precision::Confusion()) { + // Point on the circle + aResult = std::shared_ptr( + new GeomAPI_Pnt2d(thePoint->x(), thePoint->y())); + } else { + gp_Dir2d aDir(aPoint.XY() - aCenter.XY()); + gp_XY aNewPoint = aCenter.XY() + aDir.XY() * MY_CIRC2D->Radius(); + aResult = std::shared_ptr( + new GeomAPI_Pnt2d(aNewPoint.X(), aNewPoint.Y())); } + return aResult; } +const std::shared_ptr GeomAPI_Circ2d::center() const +{ + if (!MY_CIRC2D) + return std::shared_ptr(); + const gp_Pnt2d& aCenter = MY_CIRC2D->Location(); + return std::shared_ptr(new GeomAPI_Pnt2d(aCenter.X(), aCenter.Y())); +} + +double GeomAPI_Circ2d::radius() const +{ + if (!MY_CIRC2D) + return 0.0; + return MY_CIRC2D->Radius(); +} + +//================================================================================================= +const bool GeomAPI_Circ2d::parameter(const std::shared_ptr thePoint, + const double theTolerance, + double& theParameter) const +{ + Handle(Geom2d_Circle) aCurve = new Geom2d_Circle(*MY_CIRC2D); + return GeomLib_Tool::Parameter(aCurve, thePoint->impl(), + theTolerance, theParameter) == Standard_True; +} + +//================================================================================================= +void GeomAPI_Circ2d::D0(const double theU, std::shared_ptr& thePoint) +{ + Handle(Geom2d_Circle) aCurve = new Geom2d_Circle(*MY_CIRC2D); + gp_Pnt2d aPnt; + aCurve->D0(theU, aPnt); + thePoint.reset(new GeomAPI_Pnt2d(aPnt.X(), aPnt.Y())); +} +