GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
bounding_box.h
Go to the documentation of this file.
1// Copyright 2018 The Draco Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15#ifndef DRACO_CORE_BOUNDING_BOX_H_
16#define DRACO_CORE_BOUNDING_BOX_H_
17
18#include "draco/core/vector_d.h"
19
20namespace draco {
21
22// Class for computing the bounding box of points in 3D space.
24 public:
25 // Creates bounding box object with minimum and maximum points initialized to
26 // the largest positive and the smallest negative values, respectively. The
27 // resulting abstract bounding box effectively has no points and can be
28 // updated by providing any point to Update() method.
30
31 // Creates bounding box object with minimum and maximum points initialized to
32 // |min_point| and |max_point|, respectively.
33 BoundingBox(const Vector3f &min_point, const Vector3f &max_point);
34
35 // Returns the minimum point of the bounding box.
36 inline const Vector3f &GetMinPoint() const { return min_point_; }
37
38 // Returns the maximum point of the bounding box.
39 inline const Vector3f &GetMaxPoint() const { return max_point_; }
40
41 // Checks if the bounding box object was created with the default constructor
42 // then never updated. Internally, checks if the bounding box minimum and
43 // maximum points hold the largest positive and smallest negative values.
44 const bool IsValid() const;
45
46 // Conditionally updates the bounding box with a given |new_point|.
47 void Update(const Vector3f &new_point) {
48 for (int i = 0; i < 3; i++) {
49 if (new_point[i] < min_point_[i]) {
50 min_point_[i] = new_point[i];
51 }
52 if (new_point[i] > max_point_[i]) {
53 max_point_[i] = new_point[i];
54 }
55 }
56 }
57
58 // Updates bounding box with minimum and maximum points of the |other|
59 // bounding box.
60 void Update(const BoundingBox &other) {
61 Update(other.GetMinPoint());
62 Update(other.GetMaxPoint());
63 }
64
65 // Returns the size of the bounding box along each axis.
66 Vector3f Size() const { return max_point_ - min_point_; }
67
68 // Returns the center of the bounding box.
69 Vector3f Center() const { return (min_point_ + max_point_) / 2; }
70
71 private:
72 Vector3f min_point_;
73 Vector3f max_point_;
74};
75} // namespace draco
76
77#endif // DRACO_CORE_BOUNDING_BOX_H_
Vector3f Size() const
Definition bounding_box.h:66
const Vector3f & GetMaxPoint() const
Definition bounding_box.h:39
Vector3f Center() const
Definition bounding_box.h:69
const Vector3f & GetMinPoint() const
Definition bounding_box.h:36
BoundingBox()
Definition bounding_box.cc:19
void Update(const Vector3f &new_point)
Definition bounding_box.h:47
void Update(const BoundingBox &other)
Definition bounding_box.h:60
const bool IsValid() const
Definition bounding_box.cc:30
Definition attribute_octahedron_transform.cc:21
VectorD< float, 3 > Vector3f
Definition vector_d.h:340