Sat, 14 Dec 2019 22:36:06 +0200
added missing files
19 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
3 | * Copyright (C) 2013 - 2019 Teemu Piippo | |
4 | * | |
5 | * This program is free software: you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | #include "boundingbox.h" | |
20 | ||
21 | BoundingBox& BoundingBox::operator<<(const Point3D& vertex) | |
22 | { | |
23 | this->consider(vertex); | |
24 | return *this; | |
25 | } | |
26 | ||
27 | void BoundingBox::consider(const Point3D& vertex) | |
28 | { | |
29 | this->minimum.x = std::min(vertex.x, this->minimum.x); | |
30 | this->minimum.y = std::min(vertex.y, this->minimum.y); | |
31 | this->minimum.z = std::min(vertex.z, this->minimum.z); | |
32 | this->maximum.x = std::max(vertex.x, this->maximum.x); | |
33 | this->maximum.y = std::max(vertex.y, this->maximum.y); | |
34 | this->maximum.z = std::max(vertex.z, this->maximum.z); | |
35 | } | |
36 | ||
37 | /* | |
38 | * Returns the length of the bounding box on the longest measure. | |
39 | */ | |
40 | double longestMeasure(const BoundingBox& box) | |
41 | { | |
42 | double dx = box.minimum.x - box.maximum.x; | |
43 | double dy = box.minimum.y - box.maximum.y; | |
44 | double dz = box.minimum.z - box.maximum.z; | |
45 | double size = std::max(std::max(dx, dy), dz); | |
46 | return std::max(std::abs(size / 2.0), 1.0); | |
47 | } | |
48 | ||
49 | ||
50 | /* | |
51 | * Yields the center of the bounding box. | |
52 | */ | |
53 | Point3D center(const BoundingBox& box) | |
54 | { | |
55 | return { | |
56 | (box.minimum.x + box.maximum.x) / 2, | |
57 | (box.minimum.y + box.maximum.y) / 2, | |
58 | (box.minimum.z + box.maximum.z) / 2 | |
59 | }; | |
60 | } | |
61 | ||
62 | /* | |
63 | * Returns the length of the bounding box's space diagonal. | |
64 | */ | |
65 | double spaceDiagonal(const BoundingBox& box) | |
66 | { | |
67 | return distance(box.minimum, box.maximum); | |
68 | } |