Antkeeper  0.0.1
bounding-volume.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_GEOM_BOUNDING_VOLUME_HPP
21 #define ANTKEEPER_GEOM_BOUNDING_VOLUME_HPP
22 
23 #include <engine/math/vector.hpp>
24 #include <stdexcept>
25 
26 namespace geom {
27 
28 template <class T>
29 struct sphere;
30 template <class T>
31 struct aabb;
32 
35 {
36  aabb,
37  sphere,
39 };
40 
46 template <class T>
48 {
49 public:
52 
54  virtual bool intersects(const sphere<T>& sphere) const = 0;
55 
57  virtual bool intersects(const aabb<T>& aabb) const = 0;
58 
60  virtual bool contains(const sphere<T>& sphere) const = 0;
61 
63  virtual bool contains(const aabb<T>& aabb) const = 0;
64 
66  virtual bool contains(const math::vector<T, 3>& point) const = 0;
67 
69  bool intersects(const bounding_volume& volume) const;
70 };
71 
73 template <class T>
75 {
77  switch (type)
78  {
80  return intersects(static_cast<const sphere<T>&>(volume));
81  break;
82 
84  return intersects(static_cast<const aabb<T>&>(volume));
85  break;
86 
87  default:
88  throw std::runtime_error("unimplemented");
89  break;
90  }
91 }
92 
93 } // namespace geom
94 
95 #endif // ANTKEEPER_GEOM_BOUNDING_VOLUME_HPP
Abstract base class for bounding volumes.
virtual bool intersects(const sphere< T > &sphere) const =0
Tests for intersection between this bounding volume and a bounding sphere.
virtual bool contains(const aabb< T > &aabb) const =0
Tests whether this bounding volume contains an axis-aligned bounding box.
virtual bounding_volume_type get_bounding_volume_type() const =0
Returns the enumerated type of this bounding volume.
virtual bool contains(const math::vector< T, 3 > &point) const =0
Tests whether this bounding volume contains a point.
virtual bool contains(const sphere< T > &sphere) const =0
Tests whether this bounding volume contains a sphere.
virtual bool intersects(const aabb< T > &aabb) const =0
Tests for intersection between this bounding volume and an axis-aligned bounding box.
bool intersects(const bounding_volume &volume) const
Tests for intersection between this bounding volume and another bounding volume.
hypersphere< T, 3 > sphere
3-dimensional hypersphere.
Geometry.
Definition: aabb.hpp:30
bounding_volume_type
Enumerates bounding volume types.
@ sphere
Indicates the bounding volume is a sphere.
@ aabb
Indicates the bounding volume is an axis-aligned bounding box.
Text and typography.
Definition: bitmap-font.cpp:24
Axis-aligned bounding box.
Definition: aabb.hpp:37
A plane-bounded convex hull.
Definition: convex-hull.hpp:37
Bounding sphere.
Definition: sphere.hpp:35