coord/base: add indices method
This commit is contained in:
parent
ad345f19d5
commit
efb719b822
@ -160,6 +160,21 @@ namespace util::coord {
|
|||||||
std::fill (next, std::end (out), fill);
|
std::fill (next, std::end (out), fill);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
/// returns an instance with elements specified by the Indices
|
||||||
|
/// parameter. eg, point2f p{}.indices<0,2> would return {p.x, p.z}.
|
||||||
|
///
|
||||||
|
/// it's ugly as sin, but simplifies some situations where we don't
|
||||||
|
/// want a temporary.
|
||||||
|
template <std::size_t ...Indices>
|
||||||
|
KLASS<sizeof...(Indices),T>
|
||||||
|
indices (void) const
|
||||||
|
{
|
||||||
|
static_assert (all (make_vector ((Indices < S)...)));
|
||||||
|
return KLASS<sizeof...(Indices),T> { this->data[Indices]... };
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,5 +91,13 @@ main (void)
|
|||||||
tap.expect_eq (limit (val, 0.f, 2.f), util::vector3f { 0, 0, 2 }, "limit with vec/num/num");
|
tap.expect_eq (limit (val, 0.f, 2.f), util::vector3f { 0, 0, 2 }, "limit with vec/num/num");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ensure that klass::indices appears to link correctly
|
||||||
|
{
|
||||||
|
const util::vector3i seq { 0, 1, 2 };
|
||||||
|
const util::vector4i res { 2, 0, 0, 1 };
|
||||||
|
|
||||||
|
tap.expect_eq (seq.indices<2,0,0,1> (), res, "coord::indices expansion");
|
||||||
|
};
|
||||||
|
|
||||||
return tap.status ();
|
return tap.status ();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user