1 // Copyright (C) 2018-2022 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <GeomAPI_Cylinder.h>
21 #include <GeomAPI_Pnt.h>
22 #include <GeomAPI_Dir.h>
24 #include <gp_Cylinder.hxx>
25 #include <Precision.hxx>
27 #define MY_CYL implPtr<gp_Cylinder>()
29 static gp_Cylinder* newCyl(const gp_Pnt& theLocation, const gp_Dir& theAxis, const double theRadius)
31 return new gp_Cylinder(gp_Ax3(theLocation, theAxis), theRadius);
34 //=================================================================================================
35 GeomAPI_Cylinder::GeomAPI_Cylinder(const std::shared_ptr<GeomAPI_Pnt>& theLocation,
36 const std::shared_ptr<GeomAPI_Dir>& theAxis,
37 const double theRadius)
38 : GeomAPI_Interface(newCyl(theLocation->impl<gp_Pnt>(), theAxis->impl<gp_Dir>(), theRadius)),
39 myHeight(Precision::Infinite())
43 //=================================================================================================
44 GeomAPI_Cylinder::GeomAPI_Cylinder(const std::shared_ptr<GeomAPI_Pnt>& theLocation,
45 const std::shared_ptr<GeomAPI_Dir>& theAxis,
46 const double theRadius,
47 const double theHeight)
48 : GeomAPI_Interface(newCyl(theLocation->impl<gp_Pnt>(), theAxis->impl<gp_Dir>(), theRadius)),
53 //=================================================================================================
54 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Cylinder::location() const
56 const gp_Pnt& aCenter = MY_CYL->Location();
57 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCenter.X(), aCenter.Y(), aCenter.Z()));
60 //=================================================================================================
61 std::shared_ptr<GeomAPI_Dir> GeomAPI_Cylinder::axis() const
63 const gp_Dir& anAxis = MY_CYL->Position().Direction();
64 return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(anAxis.X(), anAxis.Y(), anAxis.Z()));
67 //=================================================================================================
68 double GeomAPI_Cylinder::radius() const
70 return MY_CYL->Radius();
73 //=================================================================================================
74 double GeomAPI_Cylinder::height() const
79 //=================================================================================================
80 bool GeomAPI_Cylinder::isInfinite() const
82 return Precision::IsInfinite(myHeight);
85 //=================================================================================================
86 bool GeomAPI_Cylinder::isCoincident(const GeomCylinderPtr theCylinder, const double theTolerance)
91 gp_Cylinder* anOther = theCylinder->implPtr<gp_Cylinder>();
92 if (fabs(MY_CYL->Radius() - anOther->Radius()) < theTolerance) {
93 gp_Dir aDir1 = MY_CYL->Position().Direction();
94 gp_Dir aDir2 = anOther->Position().Direction();
95 if (aDir1.IsParallel(aDir2, Precision::Angular())) {
96 gp_Pnt aLoc1 = MY_CYL->Location();
97 gp_Pnt aLoc2 = anOther->Location();
98 gp_Vec aVec12(aLoc1, aLoc2);
99 if (aVec12.SquareMagnitude() < theTolerance * theTolerance ||
100 aVec12.IsParallel(aDir1, Precision::Angular())) {