Salome HOME
Update copyrights
[modules/shaper.git] / src / GeomAPI / GeomAPI_Box.cpp
1 // Copyright (C) 2018-2019  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_Box.h>
21 #include <GeomAPI_Ax3.h>
22
23 #include <Precision.hxx>
24
25 struct Box
26 {
27   std::shared_ptr<GeomAPI_Ax3> myCoordSystem;
28   double myWidth;
29   double myDepth;
30   double myHeight;
31
32   Box(const std::shared_ptr<GeomAPI_Ax3>& theCoordSystem,
33       const double theWidth,
34       const double theDepth,
35       const double theHeight)
36     : myCoordSystem(theCoordSystem),
37       myWidth(theWidth),
38       myDepth(theDepth),
39       myHeight(theHeight)
40   {}
41 };
42
43 #define MY_BOX implPtr<Box>()
44
45 //=================================================================================================
46 GeomAPI_Box::GeomAPI_Box(const std::shared_ptr<GeomAPI_Ax3>& theCorner,
47                          const double theWidth,
48                          const double theDepth,
49                          const double theHeight)
50   : GeomAPI_Interface(new Box(theCorner, theWidth, theDepth, theHeight))
51 {
52 }
53
54 //=================================================================================================
55 std::shared_ptr<GeomAPI_Ax3> GeomAPI_Box::axes() const
56 {
57   return MY_BOX->myCoordSystem;
58 }
59
60 //=================================================================================================
61 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Box::corner() const
62 {
63   return axes()->origin();
64 }
65
66 //=================================================================================================
67 double GeomAPI_Box::width() const
68 {
69   return MY_BOX->myWidth;
70 }
71
72 //=================================================================================================
73 double GeomAPI_Box::depth() const
74 {
75   return MY_BOX->myDepth;
76 }
77
78 //=================================================================================================
79 double GeomAPI_Box::height() const
80 {
81   return MY_BOX->myHeight;
82 }
83
84 //=================================================================================================
85 bool GeomAPI_Box::isAxesAligned() const
86 {
87   return Abs(MY_BOX->myCoordSystem->dirX()->x() - 1.0) < Precision::Angular() &&
88          Abs(MY_BOX->myCoordSystem->normal()->z() - 1.0) < Precision::Angular();
89 }