src/types/boundingbox.cpp

changeset 22
6da867fa5429
parent 20
cef43609a374
child 23
3387a84ddaba
equal deleted inserted replaced
21:0133e565e072 22:6da867fa5429
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 double longestMeasure(const BoundingBox& box)
41 { 41 {
42 double dx = box.minimum.x - box.maximum.x; 42 if (box != emptyBoundingBox)
43 double dy = box.minimum.y - box.maximum.y; 43 {
44 double dz = box.minimum.z - box.maximum.z; 44 double dx = box.minimum.x - box.maximum.x;
45 double size = std::max(std::max(dx, dy), dz); 45 double dy = box.minimum.y - box.maximum.y;
46 return std::max(std::abs(size / 2.0), 1.0); 46 double dz = box.minimum.z - box.maximum.z;
47 double size = std::max(std::max(dx, dy), dz);
48 return std::max(std::abs(size / 2.0), 1.0);
49 }
50 else
51 {
52 return 0.0;
53 }
47 } 54 }
48 55
49 56
50 /* 57 /*
51 * Yields the center of the bounding box. 58 * Yields the center of the bounding box.
52 */ 59 */
53 Point3D center(const BoundingBox& box) 60 Point3D boxCenter(const BoundingBox& box)
54 { 61 {
55 return { 62 if (box != emptyBoundingBox)
56 (box.minimum.x + box.maximum.x) / 2, 63 {
57 (box.minimum.y + box.maximum.y) / 2, 64 return {
58 (box.minimum.z + box.maximum.z) / 2 65 (box.minimum.x + box.maximum.x) / 2,
59 }; 66 (box.minimum.y + box.maximum.y) / 2,
67 (box.minimum.z + box.maximum.z) / 2
68 };
69 }
70 else
71 {
72 return origin;
73 }
60 } 74 }
61 75
62 /* 76 /*
63 * Returns the length of the bounding box's space diagonal. 77 * Returns the length of the bounding box's space diagonal.
64 */ 78 */
65 double spaceDiagonal(const BoundingBox& box) 79 double spaceDiagonal(const BoundingBox& box)
66 { 80 {
67 return math::distance(box.minimum, box.maximum); 81 return math::distance(box.minimum, box.maximum);
68 } 82 }
83
84 bool operator==(const BoundingBox &box_1, const BoundingBox &box_2)
85 {
86 return box_1.minimum == box_2.minimum and box_1.maximum == box_2.maximum;
87 }
88
89 bool operator!=(const BoundingBox &box_1, const BoundingBox &box_2)
90 {
91 return not (box_1 == box_2);
92 }

mercurial