header_utils
Loading...
Searching...
No Matches
shape_concepts.h
1
4
5#pragma once
6
7#include "geometry_common.h"
8
10{
12
13 /*
14 T edge_length() const;
15 glm::tvec2<T> edge_point_alpha(T t) const;
16 glm::tvec2<T> edge_point(T t) const;
17 trec2<T> bounding_box() const;
18 glm::tvec2<T> projected(glm::tvec2<T> pt) const;
19 */
20
21
22 template <typename SHAPE, typename T>
23 concept shape = requires (SHAPE const& shape, glm::tvec2<T> pt, T t) {
24 { shape.edge_length() } -> std::convertible_to<T>;
25 { shape.edge_point_alpha(t) } -> std::convertible_to<glm::tvec2<T>>;
26 { shape.edge_point(t) } -> std::convertible_to<glm::tvec2<T>>;
27 { shape.bounding_box() } -> std::convertible_to<trec2<T>>;
28
30 { shape.projected(pt) } -> std::convertible_to<glm::tvec2<T>>;
31
33
35 };
36
37 template <typename T, shape<T> S> auto distance(S const& sh, glm::tvec2<T> pt) { return glm::distance(sh.projected(pt), pt); }
38 template <typename T, shape<T> S> auto distance(glm::tvec2<T> pt, S const& sh) { return glm::distance(sh.projected(pt), pt); }
39
40 template <typename T, shape<T> S> auto distance_squared(S const& sh, glm::tvec2<T> pt) { const auto d = sh.projected(pt) - pt; return glm::dot(d, d); }
41 template <typename T, shape<T> S> auto distance_squared(glm::tvec2<T> pt, S const& sh) { const auto d = sh.projected(pt) - pt; return glm::dot(d, d); }
42
44
45 /*
46 bool contains(glm::tvec2<T> pt) const;
47 T calculate_area() const;
48 */
49
50 template <typename SHAPE, typename T>
51 concept area_shape = shape<SHAPE, T> && requires (SHAPE const& shape, glm::tvec2<T> pt, T t) {
52 { shape.contains(pt) } -> std::convertible_to<bool>;
53 { shape.calculate_area() } -> std::convertible_to<T>;
54 };
55
56}
constexpr auto bit_count
Equal to the number of bits in the type.
Definition bits.h:33