92 {
93 using Region = std::function<bool(glm::vec2)>;
94 const std::string_view kind = Access::name(node);
95
96 if (kind == "circle") {
97 glm::vec2 center {};
98 float radius {};
102 return std::nullopt;
103 }
104 if (!(radius > 0.F)) {
106 return std::nullopt;
107 }
109 }
110
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
120 return std::nullopt;
121 if (points.size() < (stroke ? 2U : 3U)) {
123 stroke ? "needs at least two x y pairs" : "needs at least three x y pairs", error);
124 return std::nullopt;
125 }
126 if (stroke && !(half_thickness > 0.F)) {
128 return std::nullopt;
129 }
131 }
132
134 return std::nullopt;
135 std::vector<Region> operands;
136 const bool traversed = Access::for_each_child(node, [&](const Source& child) {
139 + "> combines two regions", error);
140 }
142 if (!region)
143 return false;
144 operands.push_back(std::move(*region));
145 return true;
146 });
147 if (!traversed)
148 return std::nullopt;
149 if (operands.size() != 2) {
151 return std::nullopt;
152 }
153 if (kind == "union_bounds")
155 if (kind == "intersect_bounds")
158 }
void error(Component component, Context context, std::source_location location, std::string_view message)
Log an error message and optionally throw an exception.
@ Kinesis
General mathematical and physics algorithns.
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.