7#include "geometry_common.h"
17 template <
typename T,
typename SHAPE>
18 concept shape =
requires (SHAPE
const&
shape, glm::tvec2<T> pt, T t)
21 {
shape.edge_length() } -> std::convertible_to<T>;
25 {
shape.edge_point_alpha(t) } -> std::convertible_to<glm::tvec2<T>>;
29 {
shape.edge_point(t) } -> std::convertible_to<glm::tvec2<T>>;
32 {
shape.bounding_box() } -> std::convertible_to<trec2<T>>;
35 {
shape.closest_point_to(pt) } -> std::convertible_to<glm::tvec2<T>>;
41 template <
typename T, shape<T> S>
auto distance(S
const& sh, glm::tvec2<T> pt) {
return glm::distance(sh.closest_point_to(pt), pt); }
42 template <
typename T, shape<T> S>
auto distance(glm::tvec2<T> pt, S
const& sh) {
return glm::distance(sh.closest_point_to(pt), pt); }
44 template <
typename T, shape<T> S>
auto distance_squared(S
const& sh, glm::tvec2<T> pt) {
const auto d = sh.closest_point_to(pt) - pt;
return glm::dot(d, d); }
45 template <
typename T, shape<T> S>
auto distance_squared(glm::tvec2<T> pt, S
const& sh) {
const auto d = sh.closest_point_to(pt) - pt;
return glm::dot(d, d); }
48 std::optional<T> axis_overlaps(
shape<T> auto const& a,
shape<T> auto const& b, glm::vec2
const& axis)
53 return first.overlaps(second) ? first.overlap(second) : std::nullopt;
57 template <
typename T,
typename SHAPE>
59 {
shape.contains(pt) } -> std::convertible_to<bool>;
60 {
shape.calculate_area() } -> std::convertible_to<T>;
61 {
shape.centroid() } -> std::convertible_to<glm::tvec2<T>>;
71 template <
typename T,
typename SHAPE>
73 {
shape.for_each_edge([](glm::tvec2<T>
const& a, glm::tvec2<T>
const& b) {}) };
74 {
shape.for_each_vertex([](glm::tvec2<T>
const& vertex) {}) };
75 {
shape.vertex_count() } -> std::convertible_to<size_t>;
76 {
shape.edge_count() } -> std::convertible_to<size_t>;
77 {
shape.edge(
size_t{}) } -> std::convertible_to<std::optional<std::pair<glm::tvec2<T>, glm::tvec2<T>>>>;
78 {
shape.vertex(
size_t{}) } -> std::convertible_to<std::optional<glm::tvec2<T>>>;
82 template <
typename T,
typename SHAPE>
86 template <
typename POLY>
90 { polygon[i] } -> is_specialization_of<glm::tvec2>;
A shape for which the concept of an "area" has a finite interpretation.
Any type that we can index into which will return a tvec2 of some sort. This includes,...
An area_shape with vertices and edges.
A shape with vertices and edges.
Any contiguous non-empty set of 2D points.
auto distance(S const &sh, glm::tvec2< T > pt)
Returns the distance between a shape and a point.
For interval<T> projected_on_axis(glm::tvec2<T> axis) const;.