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