Bounding box feature
Wzshun opened this issue · 5 comments
Can it support the bounding box function.
For now I use this library to convert the self-defined spline
to bspline
, then call toBeziers()
, then get their respective boxes, and then united them.
I will have a look at how to compute the bounding box for B-Splines.
It looks like there is no general analytical solution for computing the bounding box of a spline of any degree. For splines with degree 3 and less, your approach (converting the spline into a sequence of bezier curves, computing the bounding box of each bezier curve, and merging the bounding boxes into a single bounding box) seems to be the way to go. I could implement a function which applies these steps for spline of degree 3 and less, and falls back to a sampling based approach for spline of higher degree.
That said, sampling the spline and computing the bounding box of the resulting polyline (linear search for the minimum and maximum values) could serve as a first quick fix for your issue.
It looks like that computing the bounding box analytically works only if a spline is function-like, i.e., the control points are monotonically increasing in x. Because TinySpline supports splines of any shape, the provided function will in most cases compute the bounding box numerically, i.e., by sampling the spline with a resolution.
Because TinySpline supports splines of any shape, the provided function will in most cases compute the bounding box numerically, i.e., by sampling the spline with a resolution.
It seems so. I found an awesome lib for spline, hope it works for you.
splines-lib
SplineLib
looks like a well-implemented library for splines. Does ExactBounds
work with arbitrarily shaped splines, in particular, splines whose coordinates are not sorted?