21template <
typename D,
typename R>
23 std::function<R(
const D&)>
fn;
37 [[nodiscard]] R
evaluate(
const D& d)
const {
return fn(d); }
65template <
typename D,
typename R,
typename BinaryOp>
68 return { .
fn = [
a,
b, op](
const D& d) -> R {
69 return op(
a(d),
b(d));
82template <
typename A,
typename B,
typename C>
85 return { .
fn = [first, second](
const A&
a) -> C {
86 return second(first(
a));
100 return { .
fn = [t, factor](
const D& d) ->
float {
101 return t(d) * factor;
113 return { .
fn = [t, factor](
const glm::vec3& d) -> glm::vec3 {
114 return t(d) * factor;
129 return { .fn = [t, lo, hi](
const D& d) ->
float {
130 return std::clamp(t(d), lo, hi);
144 return { .
fn = [t, thresh](
const D& d) ->
float {
146 return v < thresh ? 0.0F : v;
159 return { .
fn = [t](
const D& d) ->
float {
171 return { .
fn = [t](
const glm::vec3& d) -> glm::vec3 {
187 return { .
fn = [
a,
b,
weight](
const D& d) ->
float {
189 return a(d) * (1.0F - w) +
b(d) * w;
202template <
typename D,
typename R>
205 return { .
fn = [predicate, then_t, else_t](
const D& d) -> R {
206 return predicate(d) > 0.0F ? then_t(d) : else_t(d);
225 std::vector<double> table(
count);
226 for (
size_t i = 0; i <
count; ++i) {
227 const double t =
count > 1
228 ? from + (to - from) *
static_cast<double>(i) /
static_cast<double>(
count - 1)
BufferProcessingChain * chain
Tendency< D, float > invert(const Tendency< D, float > &t)
Negate a scalar-output tendency.
Tendency< D, R > select(const Tendency< D, float > &predicate, const Tendency< D, R > &then_t, const Tendency< D, R > &else_t)
Select between two tendencies based on a predicate tendency.
Tendency< D, float > scale(const Tendency< D, float > &t, float factor)
Uniform scaling of a scalar-output tendency.
Tendency< D, R > combine(const Tendency< D, R > &a, const Tendency< D, R > &b, BinaryOp op)
Combine two tendencies with a binary operation on their outputs.
Tendency< D, float > lerp(const Tendency< D, float > &a, const Tendency< D, float > &b, const Tendency< D, float > &weight)
Interpolate between two tendencies controlled by a weight tendency.
std::vector< double > tabulate(const Tendency< double, double > &f, size_t count, double from=-1.0, double to=1.0)
Sample a tendency at evenly spaced points into an array.
std::function< R(const D &)> fn
R operator()(const D &d) const
Evaluate the tendency at a point in the domain.
R evaluate(const D &d) const
Named evaluation (identical to operator())
Typed, composable, stateless callable from domain D to range R.