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