MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ read_hit_child()

template<typename Source, typename Access = Reflect::RecordAccess<Source>>
bool MayaFlux::Portal::Forma::read_hit_child ( const Source & child,
ElementHit & hit,
std::string & error )
nodiscard

Read one spatial child of an element into hit.

bounds is Element::with_bounds, with min and max. A region is Element::with_contains over the Kinesis function of the same name: circle (center, radius), polygon (points), stroke (points, half_thickness), and union_bounds, intersect_bounds and subtract_bounds, each of two regions. An element has at most one bounds and one region.

Parameters
errorReceives a located message when false is returned.

Definition at line 173 of file ElementHit.hpp.

174{
175 if (Access::name(child) == "bounds") {
176 if (hit.bounds)
177 return Detail::hit_fail<Source, Access>(child, "may appear only once in an <element>", error);
178 Kinesis::AABB2D box {};
179 if (!Detail::only_hit_attributes<Source, Access>(child, { "min", "max" }, error)
180 || !Detail::read_hit_attribute<Source, Access>(child, "min", box.min, error)
181 || !Detail::read_hit_attribute<Source, Access>(child, "max", box.max, error)) {
182 return false;
183 }
184 if (!(box.max.x > box.min.x) || !(box.max.y > box.min.y))
185 return Detail::hit_fail<Source, Access>(child, "needs a max above its min", error);
186 hit.bounds = box;
187 return true;
188 }
189
190 if (hit.contains) {
192 "is a second region, and an <element> has only one", error);
193 }
194 auto region = Detail::read_region<Source, Access>(child, error);
195 if (!region)
196 return false;
197 hit.contains = std::move(*region);
198 return true;
199}
std::optional< std::function< bool(glm::vec2)> > read_region(const Source &node, std::string &error)
bool hit_fail(const Source &at, const std::string &message, std::string &error)
bool only_hit_attributes(const Source &node, std::initializer_list< std::string_view > allowed, std::string &error)
bool read_hit_attribute(const Source &node, std::string_view name, T &value, std::string &error)
Axis-aligned bounding rectangle in a 2D coordinate space.
Definition Bounds.hpp:63
std::optional< Kinesis::AABB2D > bounds
std::function< bool(glm::vec2)> contains

References MayaFlux::Portal::Forma::ElementHit::bounds, MayaFlux::Portal::Forma::ElementHit::contains, MayaFlux::Portal::Forma::Detail::hit_fail(), MayaFlux::Kinesis::AABB2D::max, MayaFlux::Kinesis::AABB2D::min, MayaFlux::Portal::Forma::Detail::only_hit_attributes(), MayaFlux::Portal::Forma::Detail::read_hit_attribute(), and MayaFlux::Portal::Forma::Detail::read_region().

Referenced by MayaFlux::Portal::Forma::Detail::DocumentWalk< Source, Access >::read_element().

Here is the call graph for this function:
Here is the caller graph for this function: