1 // Copyright (C) 2018-20xx 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <GeomAPI_Cone.h>
22 #include <GeomAPI_Pnt.h>
23 #include <GeomAPI_Dir.h>
25 #include <gp_Cone.hxx>
26 #include <Precision.hxx>
28 #define MY_CONE implPtr<gp_Cone>()
30 static gp_Cone* newCone(const gp_Pnt& theApex, const gp_Dir& theAxis,
31 const double theSemiAngle, const double theRadius = 0.0)
33 return new gp_Cone(gp_Ax3(theApex, theAxis), theSemiAngle, theRadius);
36 //=================================================================================================
37 GeomAPI_Cone::GeomAPI_Cone(const std::shared_ptr<GeomAPI_Pnt>& theApex,
38 const std::shared_ptr<GeomAPI_Dir>& theAxis,
39 const double theSemiAngle)
40 : GeomAPI_Interface(newCone(theApex->impl<gp_Pnt>(), theAxis->impl<gp_Dir>(), theSemiAngle)),
41 myRadius1(Precision::Infinite()),
42 myRadius2(Precision::Infinite())
46 //=================================================================================================
47 GeomAPI_Cone::GeomAPI_Cone(const std::shared_ptr<GeomAPI_Pnt>& theLocation,
48 const std::shared_ptr<GeomAPI_Dir>& theAxis,
49 const double theSemiAngle,
50 const double theRadius)
52 newCone(theLocation->impl<gp_Pnt>(), theAxis->impl<gp_Dir>(), theSemiAngle, theRadius)),
54 myRadius2(Precision::Infinite())
58 //=================================================================================================
59 GeomAPI_Cone::GeomAPI_Cone(const std::shared_ptr<GeomAPI_Pnt>& theLocation,
60 const std::shared_ptr<GeomAPI_Dir>& theAxis,
61 const double theSemiAngle,
62 const double theRadius1,
63 const double theRadius2)
64 : myRadius1(theRadius1),
67 gp_Pnt aLoc = theLocation->impl<gp_Pnt>();
68 gp_Dir aDir = theAxis->impl<gp_Dir>();
69 if (theRadius1 > theRadius2) {
70 aLoc.ChangeCoord() += aDir.XYZ() * (theRadius1 - theRadius2) / Tan(theSemiAngle);
72 myRadius1 = theRadius2;
73 myRadius2 = theRadius1;
76 setImpl(newCone(aLoc, aDir, theSemiAngle, myRadius1));
79 //=================================================================================================
80 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Cone::apex() const
82 const gp_Pnt& anApex = MY_CONE->Apex();
83 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(anApex.X(), anApex.Y(), anApex.Z()));
86 //=================================================================================================
87 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Cone::location() const
89 const gp_Pnt& aLoc = MY_CONE->Location();
90 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
93 //=================================================================================================
94 std::shared_ptr<GeomAPI_Dir> GeomAPI_Cone::axis() const
96 const gp_Dir& anAxis = MY_CONE->Position().Direction();
97 return std::shared_ptr<GeomAPI_Dir>(new GeomAPI_Dir(anAxis.X(), anAxis.Y(), anAxis.Z()));
100 //=================================================================================================
101 double GeomAPI_Cone::semiAngle() const
103 return MY_CONE->SemiAngle();
106 //=================================================================================================
107 double GeomAPI_Cone::radius1() const
112 //=================================================================================================
113 double GeomAPI_Cone::radius2() const
118 //=================================================================================================
119 double GeomAPI_Cone::height() const
121 if (Precision::IsInfinite(myRadius1) || Precision::IsInfinite(myRadius2))
122 return Precision::Infinite();
124 return Abs((myRadius2 - myRadius1) / Tan(semiAngle()));
127 //=================================================================================================
128 bool GeomAPI_Cone::isSemiInfinite() const
130 return (!Precision::IsInfinite(myRadius1) && Precision::IsInfinite(myRadius2)) ||
131 (Precision::IsInfinite(myRadius1) && !Precision::IsInfinite(myRadius2));
134 //=================================================================================================
135 bool GeomAPI_Cone::isInfinite() const
137 return Precision::IsInfinite(myRadius1) && Precision::IsInfinite(myRadius2);