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

◆ centroid() [3/3]

template<PositionCarrying T, std::invocable< const T & > WeightFn>
requires std::convertible_to<std::invoke_result_t<WeightFn, const T&>, float>
glm::vec3 MayaFlux::Kinesis::centroid ( std::span< T >  pts,
WeightFn  weight 
)
noexcept

Scalar-weighted centroid of a PositionCarrying span.

Each point contributes weight(point) to the measure. Suitable for mesh vertices weighted by deformation magnitude, particles weighted by energy (size / thickness field), or any domain-specific scalar.

Falls back to the zero vector when total weight is zero or the span is empty.

Template Parameters
TAny type satisfying PositionCarrying.
WeightFnCallable: const T& -> float (or any float-convertible type).
Parameters
ptsNon-owning span of points.
weightPer-point weight callable.
Returns
Weighted mean position.

Definition at line 70 of file Morphology.hpp.

71{
72 if (pts.empty())
73 return glm::vec3(0.0F);
74 glm::vec3 acc(0.0F);
75 float total = 0.0F;
76 for (const auto& p : pts) {
77 const auto w = static_cast<float>(std::invoke(weight, p));
78 acc += static_cast<glm::vec3>(p.position) * w;
79 total += w;
80 }
81 return total > 0.0F ? acc / total : glm::vec3(0.0F);
82}
double weight

References weight.