Wayverb
rect.h
1 #pragma once
2 
3 #include "core/geo/overlaps_2d.h"
4 
5 #include "utilities/range.h"
6 
7 namespace wayverb {
8 namespace core {
9 namespace geo {
10 
11 using rect = util::range<glm::vec2>;
12 
13 namespace detail {
14 std::array<glm::vec2, 2> normals(const rect& r);
15 std::array<glm::vec2, 4> outline(const rect& r);
16 } // namespace detail
17 
18 template <size_t n>
19 bool overlaps(const rect& rect, const std::array<glm::vec2, n>& shape) {
20  const auto rect_axes = detail::normals(rect);
21  const auto rect_outline = detail::outline(rect);
22  const auto shape_axes = detail::normals_2d(shape);
23  return detail::overlaps(rect_outline.begin(),
24  rect_outline.end(),
25  shape.begin(),
26  shape.end(),
27  rect_axes.begin(),
28  rect_axes.end()) &&
29  detail::overlaps(rect_outline.begin(),
30  rect_outline.end(),
31  shape.begin(),
32  shape.end(),
33  shape_axes.begin(),
34  shape_axes.end());
35 }
36 
37 } // namespace geo
38 
39 inline auto inside(const geo::rect& a, const glm::vec2& b) {
40  return glm::all(glm::lessThan(a.get_min(), b)) &&
41  glm::all(glm::lessThan(b, a.get_max()));
42 }
43 } // namespace core
44 } // namespace wayverb
Definition: traits.cpp:2
Definition: range.h:12
Definition: traits.h:46
Definition: capsule_base.h:9