Jet  v1.3.3
bounding_box2.h
Go to the documentation of this file.
1 // Copyright (c) 2018 Doyub Kim
2 //
3 // I am making my contributions/submissions to this project solely in my
4 // personal capacity and am not conveying any rights to any intellectual
5 // property of any third parties.
6 
7 #ifndef INCLUDE_JET_BOUNDING_BOX2_H_
8 #define INCLUDE_JET_BOUNDING_BOX2_H_
9 
10 #include <jet/bounding_box.h>
11 #include <jet/ray2.h>
12 #include <jet/vector2.h>
13 #include <limits>
14 
15 namespace jet {
16 
22 template <typename T>
25  bool isIntersecting = false;
26 
29 
32 };
33 
40 template <typename T>
41 class BoundingBox<T, 2> {
42  public:
45 
48 
51 
53  BoundingBox(const Vector2<T>& point1, const Vector2<T>& point2);
54 
56  BoundingBox(const BoundingBox& other);
57 
59  T width() const;
60 
62  T height() const;
63 
65  T length(size_t axis);
66 
68  bool overlaps(const BoundingBox& other) const;
69 
71  bool contains(const Vector2<T>& point) const;
72 
74  bool intersects(const Ray2<T>& ray) const;
75 
81  const Ray2<T>& ray) const;
82 
85 
87  T diagonalLength() const;
88 
91 
93  void reset();
94 
96  void merge(const Vector2<T>& point);
97 
99  void merge(const BoundingBox& other);
100 
104  void expand(T delta);
105 
107  Vector2<T> corner(size_t idx) const;
108 
110  Vector2<T> clamp(const Vector2<T>& pt) const;
111 
113  bool isEmpty() const;
114 };
115 
117 template <typename T>
119 
122 
125 
128 
131 
132 } // namespace jet
133 
134 #include "detail/bounding_box2-inl.h"
135 
136 #endif // INCLUDE_JET_BOUNDING_BOX2_H_
jet::BoundingBox2F
BoundingBox2< float > BoundingBox2F
Float-type 2-D BoundingBox.
Definition: bounding_box2.h:121
jet::BoundingBox< T, 2 >::upperCorner
Vector2< T > upperCorner
Upper corner of the bounding box.
Definition: bounding_box2.h:47
jet::BoundingBox< T, 2 >::reset
void reset()
Resets this box to initial state (min=infinite, max=-infinite).
jet::BoundingBox< T, 2 >::diagonalLengthSquared
T diagonalLengthSquared() const
Returns squared diagonal length of this box.
jet::BoundingBoxRayIntersection2D
BoundingBoxRayIntersection2< double > BoundingBoxRayIntersection2D
Double-type 2-D box-ray intersection result.
Definition: bounding_box2.h:130
jet::max
Point2< T > max(const Point2< T > &a, const Point2< T > &b)
Returns element-wise max point: (max(a.x, b.x), max(a.y, b.y)).
jet::BoundingBox< T, 2 >::contains
bool contains(const Vector2< T > &point) const
Returns true if the input point is inside of this box.
jet::BoundingBox< T, 2 >::clamp
Vector2< T > clamp(const Vector2< T > &pt) const
Returns the clamped point.
jet::Ray< T, 2 >
Class for 2-D ray.
Definition: ray2.h:21
jet::BoundingBox< T, 2 >::BoundingBox
BoundingBox(const Vector2< T > &point1, const Vector2< T > &point2)
Constructs a box that tightly covers two points.
jet::BoundingBox2D
BoundingBox2< double > BoundingBox2D
Double-type 2-D BoundingBox.
Definition: bounding_box2.h:124
jet::BoundingBox< T, 2 >::isEmpty
bool isEmpty() const
Returns true if the box is empty.
jet::BoundingBoxRayIntersection2::tNear
T tNear
Distance to the first intersection point.
Definition: bounding_box2.h:28
bounding_box.h
jet::BoundingBox< T, 2 >::length
T length(size_t axis)
Returns length of the box in given axis.
jet
Definition: advection_solver2.h:18
jet::BoundingBox< T, 2 >::width
T width() const
Returns width of the box.
vector2.h
ray2.h
jet::BoundingBox< T, 2 >::height
T height() const
Returns height of the box.
jet::BoundingBox< T, 2 >::BoundingBox
BoundingBox()
Default constructor.
jet::BoundingBox< T, 2 >::merge
void merge(const BoundingBox &other)
Merges this and other box.
jet::Vector< T, 2 >
2-D vector class.
Definition: vector2.h:24
jet::BoundingBox< T, 2 >::midPoint
Vector2< T > midPoint() const
Returns the mid-point of this box.
jet::BoundingBox< T, 2 >::overlaps
bool overlaps(const BoundingBox &other) const
Returns true of this box and other box overlaps.
jet::BoundingBox< T, 2 >::lowerCorner
Vector2< T > lowerCorner
Lower corner of the bounding box.
Definition: bounding_box2.h:44
jet::BoundingBoxRayIntersection2
2-D box-ray intersection result.
Definition: bounding_box2.h:23
jet::BoundingBox< T, 2 >::corner
Vector2< T > corner(size_t idx) const
Returns corner position. Index starts from x-first order.
jet::BoundingBoxRayIntersection2::isIntersecting
bool isIntersecting
True if the box and ray intersects.
Definition: bounding_box2.h:25
jet::BoundingBox< T, 2 >::expand
void expand(T delta)
jet::BoundingBox
Generic N-D axis-aligned bounding box class.
Definition: bounding_box.h:21
jet::BoundingBox< T, 2 >
2-D axis-aligned bounding box class.
Definition: bounding_box2.h:41
jet::BoundingBox< T, 2 >::merge
void merge(const Vector2< T > &point)
Merges this and other point.
jet::BoundingBox< T, 2 >::intersects
bool intersects(const Ray2< T > &ray) const
Returns true if the input ray is intersecting with this box.
jet::BoundingBox< T, 2 >::closestIntersection
BoundingBoxRayIntersection2< T > closestIntersection(const Ray2< T > &ray) const
jet::BoundingBoxRayIntersection2F
BoundingBoxRayIntersection2< float > BoundingBoxRayIntersection2F
Float-type 2-D box-ray intersection result.
Definition: bounding_box2.h:127
jet::BoundingBoxRayIntersection2::tFar
T tFar
Distance to the second (and the last) intersection point.
Definition: bounding_box2.h:31
jet::BoundingBox< T, 2 >::diagonalLength
T diagonalLength() const
Returns diagonal length of this box.
jet::BoundingBox< T, 2 >::BoundingBox
BoundingBox(const BoundingBox &other)
Constructs a box with other box instance.