Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
[modules/shaper.git] / src / GeomAPI / GeomAPI_Pnt.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAPI_Pnt.cpp
4 // Created:     23 Apr 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include<GeomAPI_Pnt.h>
8 #include<GeomAPI_XYZ.h>
9 #include<GeomAPI_Pnt2d.h>
10 #include<GeomAPI_Dir.h>
11
12 #include<gp_Pnt.hxx>
13
14 #define MY_PNT static_cast<gp_Pnt*>(myImpl)
15
16 GeomAPI_Pnt::GeomAPI_Pnt(const double theX, const double theY, const double theZ)
17     : GeomAPI_Interface(new gp_Pnt(theX, theY, theZ))
18 {
19 }
20
21 GeomAPI_Pnt::GeomAPI_Pnt(const std::shared_ptr<GeomAPI_XYZ>& theCoords)
22     : GeomAPI_Interface(new gp_Pnt(theCoords->x(), theCoords->y(), theCoords->z()))
23 {
24 }
25
26 double GeomAPI_Pnt::x() const
27 {
28   return MY_PNT->X();
29 }
30
31 double GeomAPI_Pnt::y() const
32 {
33   return MY_PNT->Y();
34 }
35
36 double GeomAPI_Pnt::z() const
37 {
38   return MY_PNT->Z();
39 }
40
41 void GeomAPI_Pnt::setX(const double theX)
42 {
43   return MY_PNT->SetX(theX);
44 }
45
46 void GeomAPI_Pnt::setY(const double theY)
47 {
48   return MY_PNT->SetY(theY);
49 }
50
51 void GeomAPI_Pnt::setZ(const double theZ)
52 {
53   return MY_PNT->SetZ(theZ);
54 }
55
56 const std::shared_ptr<GeomAPI_XYZ> GeomAPI_Pnt::xyz()
57 {
58   return std::shared_ptr<GeomAPI_XYZ>(new GeomAPI_XYZ(MY_PNT->X(), MY_PNT->Y(), MY_PNT->Z()));
59 }
60
61 double GeomAPI_Pnt::distance(const std::shared_ptr<GeomAPI_Pnt>& theOther) const
62 {
63   return MY_PNT->Distance(theOther->impl<gp_Pnt>());
64 }
65
66 std::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Pnt::to2D(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
67   const std::shared_ptr<GeomAPI_Dir>& theDirX, const std::shared_ptr<GeomAPI_Dir>& theDirY)
68 {
69   gp_Pnt anOriginPnt(theOrigin->x(), theOrigin->y(), theOrigin->z());
70   gp_Vec aVec(anOriginPnt, impl<gp_Pnt>());
71
72   double aX = aVec.X() * theDirX->x() + aVec.Y() * theDirX->y() + aVec.Z() * theDirX->z();
73   double aY = aVec.X() * theDirY->x() + aVec.Y() * theDirY->y() + aVec.Z() * theDirY->z();
74   return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, aY));
75 }