Salome HOME
f935f67d1d127cc3b37ce1a67beadb13543c8c0f
[modules/shaper.git] / src / GeomAPI / GeomAPI_Pnt2d.cpp
1 // Copyright (C) 2014-2023  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include<GeomAPI_Pnt2d.h>
21 #include<GeomAPI_XY.h>
22 #include<GeomAPI_XYZ.h>
23 #include<GeomAPI_Pnt.h>
24 #include<GeomAPI_Dir.h>
25
26 #include<gp_Pnt2d.hxx>
27
28 #include <Precision.hxx>
29
30 #define MY_PNT2D implPtr<gp_Pnt2d>()
31
32 GeomAPI_Pnt2d::GeomAPI_Pnt2d(const double theX, const double theY)
33     : GeomAPI_Interface(new gp_Pnt2d(theX, theY))
34 {
35 }
36
37 GeomAPI_Pnt2d::GeomAPI_Pnt2d(const std::shared_ptr<GeomAPI_XY>& theCoords)
38     : GeomAPI_Interface(new gp_Pnt2d(theCoords->x(), theCoords->y()))
39 {
40 }
41
42 double GeomAPI_Pnt2d::x() const
43 {
44   return MY_PNT2D->X();
45 }
46
47 double GeomAPI_Pnt2d::y() const
48 {
49   return MY_PNT2D->Y();
50 }
51
52 void GeomAPI_Pnt2d::setX(const double theX)
53 {
54   return MY_PNT2D->SetX(theX);
55 }
56
57 void GeomAPI_Pnt2d::setY(const double theY)
58 {
59   return MY_PNT2D->SetY(theY);
60 }
61
62 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Pnt2d::to3D(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
63                                                    const std::shared_ptr<GeomAPI_Dir>& theDirX,
64                                                    const std::shared_ptr<GeomAPI_Dir>& theDirY)
65 {
66   std::shared_ptr<GeomAPI_XYZ> aSum = theOrigin->xyz()->added(theDirX->xyz()->multiplied(x()))
67       ->added(theDirY->xyz()->multiplied(y()));
68
69   return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
70 }
71
72 const std::shared_ptr<GeomAPI_XY> GeomAPI_Pnt2d::xy()
73 {
74   return std::shared_ptr<GeomAPI_XY>(new GeomAPI_XY(MY_PNT2D->X(), MY_PNT2D->Y()));
75 }
76
77 double GeomAPI_Pnt2d::distance(const std::shared_ptr<GeomAPI_Pnt2d>& theOther) const
78 {
79   return MY_PNT2D->Distance(theOther->impl<gp_Pnt2d>());
80 }
81
82 bool GeomAPI_Pnt2d::isEqual(const std::shared_ptr<GeomAPI_Pnt2d>& theOther) const
83 {
84   return distance(theOther) < Precision::Confusion();
85 }