35#include <glm/geometric.hpp>
77 const Vec3 &
m1,
double h,
double s) {
78 const double s2 =
s *
s;
79 const double s3 =
s2 *
s;
81 const double w00 = 2.0 *
s3 - 3.0 *
s2 + 1.0;
82 const double w10 =
s3 - 2.0 *
s2 +
s;
83 const double w01 = -2.0 *
s3 + 3.0 *
s2;
88 m1 *
static_cast<float>(
w11 *
h);
105 const size_t n =
i + 1u;
145 return static_cast<float>(
total);
188 const size_t n =
path.size();
194 for (
size_t i = 0;
i <
n; ++
i) {
200 }
else if (
i == 0
u) {
202 }
else if (
i + 1u ==
n) {
208 const float len = glm::length(
dir);
255 const size_t n =
path.size();
257 return std::vector<float>();
261 for (
size_t i = 0;
i <
n; ++
i) {
270 const float v_len = glm::length(
v);
274 const float cross_len = glm::length(glm::cross(
v, a));
336 const size_t n =
path.size();
337 if (
step <= 0.0f ||
n < 2u) {
343 return std::vector<Vec3>(1u,
path[0]);
350 const double steps = std::max(
351 3.0, std::round(
total /
static_cast<double>(
step)));
355 std::vector<Vec3>
out;
368 const double seg_len = glm::length(b - a);
373 out.push_back(a +
static_cast<float>(
u) * (b - a));
427 std::vector<Vec3>
path;
446 const double s =
static_cast<double>(
k) /
static_cast<double>(
samples);
502 float alpha = 0.5f) {
503 std::vector<Vec3>
path;
505 const size_t n =
pts.size();
514 for (
size_t i = 0;
i <
n; ++
i) {
526 std::vector<double>
knot(
n, 0.0);
527 for (
size_t i = 1;
i <
n; ++
i) {
535 for (
size_t i = 0;
i <
n; ++
i) {
543 }
else if (
i == 0
u) {
550 }
else if (
i + 1u ==
n) {
576 const double s =
static_cast<double>(
k) /
static_cast<double>(
samples);
617 std::vector<Vec3>
path;
619 const size_t n =
pts.size();
628 const auto basis = [](
double s,
double &
b0,
double &
b1,
double &
b2,
double &
b3) {
629 const double s2 =
s *
s;
630 const double s3 =
s2 *
s;
631 b0 = (1.0 - 3.0 *
s + 3.0 *
s2 -
s3) / 6.0;
632 b1 = (4.0 - 6.0 *
s2 + 3.0 *
s3) / 6.0;
633 b2 = (1.0 + 3.0 *
s + 3.0 *
s2 - 3.0 *
s3) / 6.0;
654 for (
int k = 0;
k <
emit; ++
k) {
655 const double s =
static_cast<double>(
k) /
static_cast<double>(
samples);
658 path.push_back(
static_cast<float>(
b0) *
p0 +
659 static_cast<float>(
b1) *
p1 +
660 static_cast<float>(
b2) *
p2 +
661 static_cast<float>(
b3) *
p3);
699 std::vector<Vec3>
path;
705 const int count = std::max(2,
samples);
706 path.reserve(
static_cast<size_t>(count));
708 std::vector<Vec3>
work(
n);
709 for (
int k = 0;
k < count; ++
k) {
712 const float u =
static_cast<float>(
k) /
static_cast<float>(count - 1);
715 for (
size_t i = 0;
i <
level; ++
i) {
int sample_count(int samples_per_segment)
Clamp a requested sample count to at least one.
constexpr double kMinKnotInterval
Smallest knot interval, to keep a degenerate point pair from producing a zero-length interval (and a ...
constexpr double kArcLengthEpsilon
Tolerance used when deciding whether an arc-length sample coincides with the end of a path,...
size_t next_index(size_t i, size_t num_points, bool closed)
Index of the point after i, wrapping around for closed curves.
constexpr size_t kMinPathPoints
Minimum number of points that can describe a path.
Vec3 hermite_segment(const Vec3 &p0, const Vec3 &p1, const Vec3 &m0, const Vec3 &m1, double h, double s)
Cubic Hermite basis evaluation of a single curve segment.
size_t segment_count(size_t num_points, bool closed)
Number of segments a sampling function has to emit.
std::vector< Vec3 > bspline_path(const std::vector< Vec3 > &points, int samples_per_segment=8, bool closed=false)
Sample a uniform cubic B-spline through the given points.
std::vector< Vec3 > catmull_rom_path(const std::vector< Vec3 > &points, int samples_per_segment=8, bool closed=false, float alpha=0.5f)
Sample a non-uniform Catmull-Rom curve through the given points.
std::vector< Vec3 > path_tangents(const std::vector< Vec3 > &path, bool closed=false)
Unit tangent direction at every point of a path.
float path_length(const std::vector< Vec3 > &path, bool closed=false)
Total length of a polyline path.
std::vector< float > path_curvature(const std::vector< Vec3 > &path, bool closed=false)
Discrete curvature at every point of a path.
std::vector< Vec3 > resample_by_arclength(const std::vector< Vec3 > &path, float step, bool closed=false)
Resample a path at a fixed arc-length step.
glm::vec3 Vec3
3-component floating-point vector (xyz).
std::vector< Vec3 > bezier_path(const std::vector< Vec3 > &control_points, int samples=64)
Sample a Bezier curve from a control polygon.
std::vector< Vec3 > hermite_path(const std::vector< Vec3 > &points, const std::vector< Vec3 > &tangents, int samples_per_segment=8, bool closed=false)
Sample a cubic Hermite curve with caller-supplied tangents.
std::vector< Vec3 > remove_duplicate_points(const std::vector< Vec3 > &path, float epsilon=1e-6f)
Remove points that repeat their predecessor.
int x
Left edge of the bitmap, in image pixels.
Fundamental types used throughout the scimesh rendering engine.