Skip to content

Commit

Permalink
interpolateCubic -> interpolateCubicNatural. Refs #39.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Steinbeck committed Apr 26, 2020
1 parent 6fb5216 commit 486eee5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/tinyspline.c
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,9 @@ tsError ts_int_relaxed_uniform_cubic_bspline(const tsReal *points, size_t n,
TS_END_TRY_RETURN(err)
}

tsError ts_bspline_interpolate_cubic(const tsReal *points, size_t num_points,
size_t dimension, tsBSpline *spline, tsStatus *status)
tsError ts_bspline_interpolate_cubic_natural(const tsReal *points,
size_t num_points, size_t dimension, tsBSpline *spline,
tsStatus *status)
{
const size_t sof_ctrlp = dimension * sizeof(tsReal);
const size_t len_points = num_points * dimension;
Expand Down
24 changes: 13 additions & 11 deletions src/tinyspline.h
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,8 @@ void ts_deboornet_free(tsDeBoorNet *net);
* *
******************************************************************************/
/**
* Interpolates a cubic spline using the thomas algorithm, see:
* Interpolates a cubic spline with natural end conditions. For more details
* see:
*
* https://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm
* http://www.math.ucla.edu/~baker/149.1.02w/handouts/dd_splines.pdf
Expand Down Expand Up @@ -1008,16 +1009,17 @@ void ts_deboornet_free(tsDeBoorNet *net);
* @return TS_MALLOC
* If allocating memory failed.
*/
tsError ts_bspline_interpolate_cubic(const tsReal *points, size_t num_points,
size_t dimension, tsBSpline *spline, tsStatus *status);
tsError ts_bspline_interpolate_cubic_natural(const tsReal *points,
size_t num_points, size_t dimension, tsBSpline *spline,
tsStatus *status);

/**
* Interpolates a cubic spline by translating the given catmull-rom control
* points into a sequence of bezier curves. In order to avoid division by zero,
* successive control points with distance less than or equals to \p epsilon
* are filtered out. If the resultant sequence contains only a single point, a
* spline of degree 0 (a point) is created. Optionally, the first and last
* control point can be specified (\p first and \p last).
* Interpolates a piecewise cubic spline by translating the given catmull-rom
* control points into a sequence of bezier curves. In order to avoid division
* by zero, successive control points with distance less than or equal to
* \p epsilon are filtered out. If the resultant sequence contains only a
* single point, a spline of degree 0 (a point) is created. Optionally, the
* first and last control point can be specified (\p first and \p last).
*
* @param[in] points
* The points to interpolate.
Expand All @@ -1043,8 +1045,8 @@ tsError ts_bspline_interpolate_cubic(const tsReal *points, size_t num_points,
* as NULL. This is necessary to avoid division by zero.
* @param[in] epsilon
* The maximum distance between points with "same" coordinates. That is,
* if the distance between two points is less than or equals \p epsilon,
* they are considered to be the same point. For the sake of
* if the distance between neighboring points is less than or equal to
* \p epsilon, they are considered to be the same point. For the sake of
* fail-safeness, the sign is removed with fabs. It is advisable to pass a
* value greater than zero, however, it is not necessary.
* @param[out] spline
Expand Down
9 changes: 5 additions & 4 deletions src/tinysplinecxx.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,17 @@ tinyspline::BSpline::~BSpline()
ts_bspline_free(&spline);
}

tinyspline::BSpline tinyspline::BSpline::interpolateCubic(
tinyspline::BSpline tinyspline::BSpline::interpolateCubicNatural(
const std_real_vector_in points, size_t dimension)
{
if (dimension == 0)
throw std::runtime_error("unsupported dimension: 0");
if (std_real_vector_read(points)size() % dimension != 0)
throw std::runtime_error("#points % dim == 0 failed");
throw std::runtime_error("#points % dimension != 0");
tinyspline::BSpline bspline;
tsStatus status;
if (ts_bspline_interpolate_cubic(std_real_vector_read(points)data(),
if (ts_bspline_interpolate_cubic_natural(
std_real_vector_read(points)data(),
std_real_vector_read(points)size()/dimension,
dimension, bspline.data(), &status))
throw std::runtime_error(status.message);
Expand All @@ -247,7 +248,7 @@ tinyspline::BSpline tinyspline::BSpline::interpolateCatmullRom(
if (dimension == 0)
throw std::runtime_error("unsupported dimension: 0");
if (std_real_vector_read(points)size() % dimension != 0)
throw std::runtime_error("#points % dim == 0 failed");
throw std::runtime_error("#points % dimension != 0");
tsReal *fst = NULL;
if (first && first->size() >= dimension)
fst = first->data();
Expand Down
2 changes: 1 addition & 1 deletion src/tinysplinecxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class BSpline {
~BSpline();

/* Create from static method */
static BSpline interpolateCubic(const std_real_vector_in points,
static BSpline interpolateCubicNatural(const std_real_vector_in points,
size_t dimension);
static BSpline interpolateCatmullRom(const std_real_vector_in points,
size_t dimension, tsReal alpha = (tsReal) 0.5f,
Expand Down

0 comments on commit 486eee5

Please sign in to comment.