0026650: Coding rules - fix misprint in NCollection_Vec3::operator/()
[occt.git] / src / BVH / BVH_Box.lxx
1 // Created on: 2013-12-20
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <Standard_ShortReal.hxx>
17
18 // =======================================================================
19 // function : Clear
20 // purpose  :
21 // =======================================================================
22 template<class T, int N>
23 void BVH_Box<T, N>::Clear()
24 {
25   myIsInited = Standard_False;
26 }
27
28 // =======================================================================
29 // function : Clear
30 // purpose  :
31 // =======================================================================
32 template<class T, int N>
33 Standard_Boolean BVH_Box<T, N>::IsValid() const
34 {
35   return myIsInited;
36 }
37
38 // =======================================================================
39 // function : Add
40 // purpose  :
41 // =======================================================================
42 template<class T, int N>
43 void BVH_Box<T, N>::Add (const BVH_VecNt& thePoint)
44 {
45   if (!myIsInited)
46   {
47     myMinPoint = thePoint;
48     myMaxPoint = thePoint;
49
50     myIsInited = Standard_True;
51   }
52   else
53   {
54     myMinPoint = myMinPoint.cwiseMin (thePoint);
55     myMaxPoint = myMaxPoint.cwiseMax (thePoint);
56   }
57 }
58
59 // =======================================================================
60 // function : Combine
61 // purpose  :
62 // =======================================================================
63 template<class T, int N>
64 void BVH_Box<T, N>::Combine (const BVH_Box& theBox)
65 {
66   if (theBox.myIsInited)
67   {
68     if (!myIsInited)
69     {
70       myMinPoint = theBox.myMinPoint;
71       myMaxPoint = theBox.myMaxPoint;
72
73       myIsInited = Standard_True;
74     }
75     else
76     {
77       BVH::BoxMinMax<T, N>::CwiseMin (myMinPoint, theBox.myMinPoint);
78       BVH::BoxMinMax<T, N>::CwiseMax (myMaxPoint, theBox.myMaxPoint);
79     }
80   }
81 }
82
83 // =======================================================================
84 // function : Area
85 // purpose  :
86 // =======================================================================
87 template<class T, int N>
88 T BVH_Box<T, N>::Area() const
89 {
90   return !myIsInited ? static_cast<T> (0.0) :
91     BVH::SurfaceCalculator<T, N>::Area (myMaxPoint - myMinPoint);
92 }
93
94 // =======================================================================
95 // function : CornerMin
96 // purpose  :
97 // =======================================================================
98 template<class T, int N>
99 const typename BVH_Box<T, N>::BVH_VecNt& BVH_Box<T, N>::CornerMin() const
100 {
101   return myMinPoint;
102 }
103
104 // =======================================================================
105 // function : CornerMax
106 // purpose  :
107 // =======================================================================
108 template<class T, int N>
109 const typename BVH_Box<T, N>::BVH_VecNt& BVH_Box<T, N>::CornerMax() const
110 {
111   return myMaxPoint;
112 }
113
114 // =======================================================================
115 // function : CornerMin
116 // purpose  :
117 // =======================================================================
118 template<class T, int N>
119 typename BVH_Box<T, N>::BVH_VecNt& BVH_Box<T, N>::CornerMin()
120 {
121   return myMinPoint;
122 }
123
124 // =======================================================================
125 // function : CornerMax
126 // purpose  :
127 // =======================================================================
128 template<class T, int N>
129 typename BVH_Box<T, N>::BVH_VecNt& BVH_Box<T, N>::CornerMax()
130 {
131   return myMaxPoint;
132 }
133
134 // =======================================================================
135 // function : Size
136 // purpose  :
137 // =======================================================================
138 template<class T, int N>
139 typename BVH_Box<T, N>::BVH_VecNt BVH_Box<T, N>::Size() const
140 {
141   return myMaxPoint - myMinPoint;
142 }
143
144 // =======================================================================
145 // function : Center
146 // purpose  :
147 // =======================================================================
148 template<class T, int N>
149 typename BVH_Box<T, N>::BVH_VecNt BVH_Box<T, N>::Center() const
150 {
151   return (myMinPoint + myMaxPoint) * static_cast<T> (0.5);
152 }
153
154 // =======================================================================
155 // function : Center
156 // purpose  :
157 // =======================================================================
158 template<class T, int N>
159 T BVH_Box<T, N>::Center (const Standard_Integer theAxis) const
160 {
161   return BVH::CenterAxis<T, N>::Center (*this, theAxis);
162 }