1 // Copyright (C) 2018-2019 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_Cone.h>
21 #include <GeomAPI_Pnt.h>
22 #include <GeomAPI_Dir.h>
24 #include <gp_Cone.hxx>
25 #include <Precision.hxx>
27 #define MY_CONE implPtr<gp_Cone>()
29 static gp_Cone* newCone(const gp_Pnt& theApex, const gp_Dir& theAxis,
30 const double theSemiAngle, const double theRadius = 0.0)
32 return new gp_Cone(gp_Ax3(theApex, theAxis), theSemiAngle, theRadius);
35 //=================================================================================================
36 GeomAPI_Cone::GeomAPI_Cone(const std::shared_ptr<GeomAPI_Pnt>& theApex,
37 const std::shared_ptr<GeomAPI_Dir>& theAxis,
38 const double theSemiAngle)
39 : GeomAPI_Interface(newCone(theApex->impl<gp_Pnt>(), theAxis->impl<gp_Dir>(), theSemiAngle)),
40 myRadius1(Precision::Infinite()),
41 myRadius2(Precision::Infinite())
45 //=================================================================================================
46 GeomAPI_Cone::GeomAPI_Cone(const std::shared_ptr<GeomAPI_Pnt>& theLocation,
47 const std::shared_ptr<GeomAPI_Dir>& theAxis,
48 const double theSemiAngle,
49 const double theRadius)
51 newCone(theLocation->impl<gp_Pnt>(), theAxis->impl<gp_Dir>(), theSemiAngle, theRadius)),
53 myRadius2(Precision::Infinite())
57 //=================================================================================================
58 GeomAPI_Cone::GeomAPI_Cone(const std::shared_ptr<GeomAPI_Pnt>& theLocation,
59 const std::shared_ptr<GeomAPI_Dir>& theAxis,
60 const double theSemiAngle,
61 const double theRadius1,
62 const double theRadius2)
63 : myRadius1(theRadius1),
66 gp_Pnt aLoc = theLocation->impl<gp_Pnt>();
67 gp_Dir aDir = theAxis->impl<gp_Dir>();
68 if (theRadius1 > theRadius2) {
69 aLoc.ChangeCoord() += aDir.XYZ() * (theRadius1 - theRadius2) / Tan(theSemiAngle);
71 myRadius1 = theRadius2;
72 myRadius2 = theRadius1;
75 setImpl(newCone(aLoc, aDir, theSemiAngle, myRadius1));
78 //=================================================================================================
79 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Cone::apex() const
81 const gp_Pnt& anApex = MY_CONE->Apex();
82 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(anApex.X(), anApex.Y(), anApex.Z()));
85 //=================================================================================================
86 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Cone::location() const
88 const gp_Pnt& aLoc = MY_CONE->Location();
89 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
92 //=================================================================================================
93 std::shared_ptr<GeomAPI_Dir> GeomAPI_Cone::axis() const
95 const gp_Dir& anAxis = MY_CONE->Position().Direction();
96 return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(anAxis.X(), anAxis.Y(), anAxis.Z()));
99 //=================================================================================================
100 double GeomAPI_Cone::semiAngle() const
102 return MY_CONE->SemiAngle();
105 //=================================================================================================
106 double GeomAPI_Cone::radius1() const
111 //=================================================================================================
112 double GeomAPI_Cone::radius2() const
117 //=================================================================================================
118 double GeomAPI_Cone::height() const
120 if (Precision::IsInfinite(myRadius1) || Precision::IsInfinite(myRadius2))
121 return Precision::Infinite();
123 return Abs((myRadius2 - myRadius1) / Tan(semiAngle()));
126 //=================================================================================================
127 bool GeomAPI_Cone::isSemiInfinite() const
129 return (!Precision::IsInfinite(myRadius1) && Precision::IsInfinite(myRadius2)) ||
130 (Precision::IsInfinite(myRadius1) && !Precision::IsInfinite(myRadius2));
133 //=================================================================================================
134 bool GeomAPI_Cone::isInfinite() const
136 return Precision::IsInfinite(myRadius1) && Precision::IsInfinite(myRadius2);