3 #include "core/cl/scene_structs.h" 4 #include "core/geo/triangle_vec.h" 10 constexpr glm::vec2 perp(
const glm::vec2& a) {
return glm::vec2(-a.y, a.x); }
12 inline glm::vec2 normal_2d(
const glm::vec2& a,
const glm::vec2& b) {
16 template <
typename It,
typename Out>
17 void normals_2d(It begin, It end, Out o) {
18 const auto dist = std::distance(begin, end);
20 throw std::runtime_error(
"Empty range passed to normal-finder.");
23 throw std::runtime_error(
"Single point passed to normal-finder.");
25 *o++ = normal_2d(*(end - 1), *begin++);
26 for (; begin != end; ++begin) {
27 *o++ = normal_2d(*(begin - 1), *begin);
32 std::array<glm::vec2, n> normals_2d(
const std::array<glm::vec2, n>& u) {
33 std::array<glm::vec2, n> ret;
34 detail::normals_2d(u.begin(), u.end(), ret.begin());
48 return std::tie(a.min, a.max) == std::tie(b.min, b.max);
51 template <
typename It>
52 projection_2d project(It begin, It end,
const glm::vec2& axis) {
54 throw std::runtime_error(
"Null shape passed to projection function.");
57 const auto first = glm::dot(axis, *begin++);
59 for (; begin != end; ++begin) {
60 const auto p = glm::dot(axis, *begin);
61 ret.min = std::min(ret.min, p);
62 ret.max = std::max(ret.max, p);
68 const auto min_max = std::minmax(a, b);
69 return min_max.second.min <= min_max.first.max;
72 template <
typename It,
typename Jt>
74 It i_begin, It i_end, Jt j_begin, Jt j_end,
const glm::vec2& axis) {
75 return overlaps(project(i_begin, i_end, axis),
76 project(j_begin, j_end, axis));
79 template <
typename It,
typename Jt,
typename Kt>
80 bool overlaps(It i_begin,
86 return std::all_of(axes_begin, axes_end, [=](
const auto& i) {
87 return overlaps(i_begin, i_end, j_begin, j_end, i);
95 template <
size_t n,
size_t m>
96 bool overlaps_2d(
const std::array<glm::vec2, n>& a,
97 const std::array<glm::vec2, m>& b) {
98 const auto a_axes = detail::normals_2d(a);
99 const auto b_axes = detail::normals_2d(b);
100 return detail::overlaps(a.begin(),
106 detail::overlaps(a.begin(),
Definition: capsule_base.h:9
Definition: overlaps_2d.h:38