src/types/boundingbox.cpp

changeset 33
4c41bfe2ec6e
parent 23
3387a84ddaba
child 189
815fbaae9cb2
equal deleted inserted replaced
32:767592024ec5 33:4c41bfe2ec6e
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #include "boundingbox.h" 19 #include "boundingbox.h"
20 20
21 BoundingBox& BoundingBox::operator<<(const Point3D& vertex) 21 BoundingBox& BoundingBox::operator<<(const glm::vec3& vertex)
22 { 22 {
23 this->consider(vertex); 23 this->consider(vertex);
24 return *this; 24 return *this;
25 } 25 }
26 26
27 void BoundingBox::consider(const Point3D& vertex) 27 void BoundingBox::consider(const glm::vec3& vertex)
28 { 28 {
29 this->minimum.x = math::min(vertex.x, this->minimum.x); 29 this->minimum.x = math::min(vertex.x, this->minimum.x);
30 this->minimum.y = math::min(vertex.y, this->minimum.y); 30 this->minimum.y = math::min(vertex.y, this->minimum.y);
31 this->minimum.z = math::min(vertex.z, this->minimum.z); 31 this->minimum.z = math::min(vertex.z, this->minimum.z);
32 this->maximum.x = math::max(vertex.x, this->maximum.x); 32 this->maximum.x = math::max(vertex.x, this->maximum.x);
35 } 35 }
36 36
37 /* 37 /*
38 * Returns the length of the bounding box on the longest measure. 38 * Returns the length of the bounding box on the longest measure.
39 */ 39 */
40 double longestMeasure(const BoundingBox& box) 40 float longestMeasure(const BoundingBox& box)
41 { 41 {
42 if (box != emptyBoundingBox) 42 if (box != emptyBoundingBox)
43 { 43 {
44 const double dx = std::abs(box.minimum.x - box.maximum.x); 44 const float dx = std::abs(box.minimum.x - box.maximum.x);
45 const double dy = std::abs(box.minimum.y - box.maximum.y); 45 const float dy = std::abs(box.minimum.y - box.maximum.y);
46 const double dz = std::abs(box.minimum.z - box.maximum.z); 46 const float dz = std::abs(box.minimum.z - box.maximum.z);
47 const double size = std::max(std::max(dx, dy), dz); 47 const float size = std::max(std::max(dx, dy), dz);
48 return std::max(size / 2.0, 1.0); 48 return std::max(size / 2.0f, 1.0f);
49 } 49 }
50 else 50 else
51 { 51 {
52 return 0.0; 52 return 0.0f;
53 } 53 }
54 } 54 }
55 55
56 56
57 /* 57 /*
58 * Yields the center of the bounding box. 58 * Yields the center of the bounding box.
59 */ 59 */
60 Point3D boxCenter(const BoundingBox& box) 60 glm::vec3 boxCenter(const BoundingBox& box)
61 { 61 {
62 if (box != emptyBoundingBox) 62 if (box != emptyBoundingBox)
63 { 63 {
64 return { 64 return {
65 (box.minimum.x + box.maximum.x) / 2, 65 (box.minimum.x + box.maximum.x) / 2,
67 (box.minimum.z + box.maximum.z) / 2 67 (box.minimum.z + box.maximum.z) / 2
68 }; 68 };
69 } 69 }
70 else 70 else
71 { 71 {
72 return origin; 72 return glm::vec3{0, 0, 0};
73 } 73 }
74 } 74 }
75 75
76 /* 76 /*
77 * Returns the length of the bounding box's space diagonal. 77 * Returns the length of the bounding box's space diagonal.
78 */ 78 */
79 double spaceDiagonal(const BoundingBox& box) 79 float spaceDiagonal(const BoundingBox& box)
80 { 80 {
81 return math::distance(box.minimum, box.maximum); 81 return glm::distance(box.minimum, box.maximum);
82 } 82 }
83 83
84 bool operator==(const BoundingBox &box_1, const BoundingBox &box_2) 84 bool operator==(const BoundingBox &box_1, const BoundingBox &box_2)
85 { 85 {
86 return box_1.minimum == box_2.minimum and box_1.maximum == box_2.maximum; 86 return box_1.minimum == box_2.minimum and box_1.maximum == box_2.maximum;

mercurial