Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / GeomAPI / GeomAPI_Pnt2d.cpp
1 // File:        GeomAPI_Pnt2d.cpp
2 // Created:     29 May 2014
3 // Author:      Artem ZHIDKOV
4
5 #include<GeomAPI_Pnt2d.h>
6 #include<GeomAPI_XY.h>
7 #include<GeomAPI_XYZ.h>
8 #include<GeomAPI_Pnt.h>
9 #include<GeomAPI_Dir.h>
10
11 #include<gp_Pnt2d.hxx>
12
13 #include <Precision.hxx>
14
15 #define MY_PNT2D static_cast<gp_Pnt2d*>(myImpl)
16
17 GeomAPI_Pnt2d::GeomAPI_Pnt2d(const double theX, const double theY)
18     : GeomAPI_Interface(new gp_Pnt2d(theX, theY))
19 {
20 }
21
22 GeomAPI_Pnt2d::GeomAPI_Pnt2d(const boost::shared_ptr<GeomAPI_XY>& theCoords)
23     : GeomAPI_Interface(new gp_Pnt2d(theCoords->x(), theCoords->y()))
24 {
25 }
26
27 double GeomAPI_Pnt2d::x() const
28 {
29   return MY_PNT2D->X();
30 }
31
32 double GeomAPI_Pnt2d::y() const
33 {
34   return MY_PNT2D->Y();
35 }
36
37 void GeomAPI_Pnt2d::setX(const double theX)
38 {
39   return MY_PNT2D->SetX(theX);
40 }
41
42 void GeomAPI_Pnt2d::setY(const double theY)
43 {
44   return MY_PNT2D->SetY(theY);
45 }
46
47 boost::shared_ptr<GeomAPI_Pnt> GeomAPI_Pnt2d::to3D(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin,
48                                                    const boost::shared_ptr<GeomAPI_Dir>& theDirX,
49                                                    const boost::shared_ptr<GeomAPI_Dir>& theDirY)
50 {
51   boost::shared_ptr<GeomAPI_XYZ> aSum = theOrigin->xyz()->added(theDirX->xyz()->multiplied(x()))
52       ->added(theDirY->xyz()->multiplied(y()));
53
54   return boost::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
55 }
56
57 const boost::shared_ptr<GeomAPI_XY> GeomAPI_Pnt2d::xy()
58 {
59   return boost::shared_ptr<GeomAPI_XY>(new GeomAPI_XY(MY_PNT2D->X(), MY_PNT2D->Y()));
60 }
61
62 double GeomAPI_Pnt2d::distance(const boost::shared_ptr<GeomAPI_Pnt2d>& theOther) const
63 {
64   return MY_PNT2D->Distance(theOther->impl<gp_Pnt2d>());
65 }
66
67 bool GeomAPI_Pnt2d::isEqual(const boost::shared_ptr<GeomAPI_Pnt2d>& theOther) const
68 {
69   return distance(theOther) < Precision::Confusion();
70 }