1 // Copyright (C) 2014-2017 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_Pnt.h>
22 #include<GeomAPI_XYZ.h>
23 #include<GeomAPI_Pnt2d.h>
24 #include<GeomAPI_Dir.h>
25 #include<GeomAPI_Pln.h>
31 #define MY_PNT implPtr<gp_Pnt>()
33 GeomAPI_Pnt::GeomAPI_Pnt(const double theX, const double theY, const double theZ)
34 : GeomAPI_Interface(new gp_Pnt(theX, theY, theZ))
38 GeomAPI_Pnt::GeomAPI_Pnt(const std::shared_ptr<GeomAPI_XYZ>& theCoords)
39 : GeomAPI_Interface(new gp_Pnt(theCoords->x(), theCoords->y(), theCoords->z()))
43 double GeomAPI_Pnt::x() const
48 double GeomAPI_Pnt::y() const
53 double GeomAPI_Pnt::z() const
58 void GeomAPI_Pnt::setX(const double theX)
60 return MY_PNT->SetX(theX);
63 void GeomAPI_Pnt::setY(const double theY)
65 return MY_PNT->SetY(theY);
68 void GeomAPI_Pnt::setZ(const double theZ)
70 return MY_PNT->SetZ(theZ);
73 const std::shared_ptr<GeomAPI_XYZ> GeomAPI_Pnt::xyz()
75 return std::shared_ptr<GeomAPI_XYZ>(new GeomAPI_XYZ(MY_PNT->X(), MY_PNT->Y(), MY_PNT->Z()));
78 double GeomAPI_Pnt::distance(const std::shared_ptr<GeomAPI_Pnt>& theOther) const
80 return MY_PNT->Distance(theOther->impl<gp_Pnt>());
83 bool GeomAPI_Pnt::isEqual(const std::shared_ptr<GeomAPI_Pnt>& theOther) const
85 return distance(theOther) < Precision::Confusion();
88 bool GeomAPI_Pnt::isLess(const std::shared_ptr<GeomAPI_Pnt>& theOther) const
90 if (MY_PNT->X() + Precision::Confusion() < theOther->x())
92 else if (MY_PNT->X() < theOther->x() + Precision::Confusion()) {
93 if (MY_PNT->Y() + Precision::Confusion() < theOther->y())
95 else if (MY_PNT->Y() < theOther->y() + Precision::Confusion() &&
96 MY_PNT->Z() + Precision::Confusion() < theOther->z())
102 std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Pnt::to2D(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
103 const std::shared_ptr<GeomAPI_Dir>& theDirX, const std::shared_ptr<GeomAPI_Dir>& theDirY)
105 gp_Pnt anOriginPnt(theOrigin->x(), theOrigin->y(), theOrigin->z());
106 gp_Vec aVec(anOriginPnt, impl<gp_Pnt>());
108 double aX = aVec.X() * theDirX->x() + aVec.Y() * theDirX->y() + aVec.Z() * theDirX->z();
109 double aY = aVec.X() * theDirY->x() + aVec.Y() * theDirY->y() + aVec.Z() * theDirY->z();
110 return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
114 void GeomAPI_Pnt::translate(const std::shared_ptr<GeomAPI_Dir>& theDir, double theDist)
116 gp_Vec aVec(theDir->impl<gp_Dir>());
118 aVec.Multiply(theDist);
119 MY_PNT->Translate(aVec);
122 std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Pnt::to2D(const std::shared_ptr<GeomAPI_Pln>& thePln) const
124 double aA, aB, aC, aD;
125 thePln->coefficients(aA, aB, aC, aD);
126 gp_Pln aPln(aA, aB, aC, aD);
128 gp_Pnt2d aRes = ProjLib::Project(aPln, *MY_PNT);
129 return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aRes.X(), aRes.Y()));