Wed, 25 May 2022 17:24:51 +0300
made editing tools not a polymorphic class tree
/* * LDForge: LDraw parts authoring CAD * Copyright (C) 2013 - 2019 Teemu Piippo * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "boundingbox.h" /** * @brief Resizes @c box so that @c vertex fits inside * @param box * @param vertex */ void addPointToBox(BoundingBox &box, const glm::vec3 &vertex) { box.minimum.x = math::min(vertex.x, box.minimum.x); box.minimum.y = math::min(vertex.y, box.minimum.y); box.minimum.z = math::min(vertex.z, box.minimum.z); box.maximum.x = math::max(vertex.x, box.maximum.x); box.maximum.y = math::max(vertex.y, box.maximum.y); box.maximum.z = math::max(vertex.z, box.maximum.z); } /* * Returns the length of the bounding box on the longest measure. */ float longestMeasure(const BoundingBox& box) { if (box != emptyBoundingBox) { const float dx = std::abs(box.minimum.x - box.maximum.x); const float dy = std::abs(box.minimum.y - box.maximum.y); const float dz = std::abs(box.minimum.z - box.maximum.z); const float size = std::max(std::max(dx, dy), dz); return std::max(size / 2.0f, 1.0f); } else { return 0.0f; } } /* * Yields the center of the bounding box. */ glm::vec3 boxCenter(const BoundingBox& box) { 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 glm::vec3{0, 0, 0}; } } /* * Returns the length of the bounding box's space diagonal. */ float spaceDiagonal(const BoundingBox& box) { return glm::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); }