diff -r 0133e565e072 -r 6da867fa5429 src/types/boundingbox.cpp --- a/src/types/boundingbox.cpp Wed Jan 01 17:45:56 2020 +0200 +++ b/src/types/boundingbox.cpp Sun Jan 19 02:54:48 2020 +0200 @@ -39,24 +39,38 @@ */ double longestMeasure(const BoundingBox& box) { - double dx = box.minimum.x - box.maximum.x; - double dy = box.minimum.y - box.maximum.y; - double dz = box.minimum.z - box.maximum.z; - double size = std::max(std::max(dx, dy), dz); - return std::max(std::abs(size / 2.0), 1.0); + if (box != emptyBoundingBox) + { + double dx = box.minimum.x - box.maximum.x; + double dy = box.minimum.y - box.maximum.y; + double dz = box.minimum.z - box.maximum.z; + double size = std::max(std::max(dx, dy), dz); + return std::max(std::abs(size / 2.0), 1.0); + } + else + { + return 0.0; + } } /* * Yields the center of the bounding box. */ -Point3D center(const BoundingBox& box) +Point3D boxCenter(const BoundingBox& box) { - return { - (box.minimum.x + box.maximum.x) / 2, - (box.minimum.y + box.maximum.y) / 2, - (box.minimum.z + box.maximum.z) / 2 - }; + if (box != emptyBoundingBox) + { + return { + (box.minimum.x + box.maximum.x) / 2, + (box.minimum.y + box.maximum.y) / 2, + (box.minimum.z + box.maximum.z) / 2 + }; + } + else + { + return origin; + } } /* @@ -66,3 +80,13 @@ { return math::distance(box.minimum, box.maximum); } + +bool operator==(const BoundingBox &box_1, const BoundingBox &box_2) +{ + return box_1.minimum == box_2.minimum and box_1.maximum == box_2.maximum; +} + +bool operator!=(const BoundingBox &box_1, const BoundingBox &box_2) +{ + return not (box_1 == box_2); +}