19 std::optional<Kinesis::AABB2D>
bounds;
26 return name ==
"circle" || name ==
"polygon" || name ==
"stroke" || name ==
"union_bounds"
27 || name ==
"intersect_bounds" || name ==
"subtract_bounds";
48 inner(std::move(value), out, element);
50 element.bounds_hint = hit.
bounds;
58 template <
typename Source,
typename Access>
59 bool hit_fail(
const Source& at,
const std::string& message, std::string& error)
62 "<" + std::string(Access::name(at)) +
"> " + message);
66 template <
typename Source,
typename Access,
typename T>
69 const auto text = Access::attribute(node, name);
75 "has an invalid " + std::string(name) +
" of " + std::string(*text), error);
80 template <
typename Source,
typename Access>
81 bool only_hit_attributes(
const Source& node, std::initializer_list<std::string_view> allowed, std::string& error)
83 return Access::for_each_attribute(node, [&](std::string_view name, std::string_view) {
84 if (std::ranges::find(allowed, name) != allowed.end())
90 template <
typename Source,
typename Access>
91 std::optional<std::function<bool(glm::vec2)>>
read_region(
const Source& node, std::string& error)
93 using Region = std::function<bool(glm::vec2)>;
94 const std::string_view kind = Access::name(node);
96 if (kind ==
"circle") {
104 if (!(radius > 0.F)) {
111 if (kind ==
"polygon" || kind ==
"stroke") {
112 const bool stroke = kind ==
"stroke";
113 std::vector<glm::vec2> points;
114 float half_thickness {};
115 const bool read = stroke
121 if (points.size() < (stroke ? 2U : 3U)) {
123 stroke ?
"needs at least two x y pairs" :
"needs at least three x y pairs", error);
126 if (stroke && !(half_thickness > 0.F)) {
135 std::vector<Region> operands;
136 const bool traversed = Access::for_each_child(node, [&](
const Source& child) {
139 +
"> combines two regions", error);
144 operands.push_back(std::move(*region));
149 if (operands.size() != 2) {
153 if (kind ==
"union_bounds")
155 if (kind ==
"intersect_bounds")
172template <
typename Source,
typename Access = Reflect::RecordAccess<Source>>
175 if (Access::name(child) ==
"bounds") {
184 if (!(box.
max.x > box.
min.x) || !(box.
max.y > box.
min.y))
192 "is a second region, and an <element> has only one", error);
Illustrative geometry functions for common Mapped use cases.
std::function< bool(glm::vec2)> intersect_bounds(std::function< bool(glm::vec2)> a, std::function< bool(glm::vec2)> b)
Intersection of two containment tests.
std::function< bool(glm::vec2)> polygon_bounds(std::span< const glm::vec2 > vertices)
Containment test for a convex or concave polygon.
std::function< bool(glm::vec2)> subtract_bounds(std::function< bool(glm::vec2)> a, std::function< bool(glm::vec2)> b)
Difference of two containment tests.
std::function< bool(glm::vec2)> stroke_bounds(std::span< const glm::vec2 > points, float half_thickness)
Containment test for a polyline with a uniform half-thickness.
std::function< bool(glm::vec2)> circular_bounds(glm::vec2 center, float radius) noexcept
Containment test for a circle.
std::function< bool(glm::vec2)> union_bounds(std::function< bool(glm::vec2)> a, std::function< bool(glm::vec2)> b)
Union of two containment tests.
std::string located_message(uint64_t location, std::string_view message)
A diagnostic message prefixed with the location of the element it concerns.
Axis-aligned bounding rectangle in a 2D coordinate space.
Conversion of authored text to one value type.