diff --git a/include/Bezier/bezier.h b/include/Bezier/bezier.h index 33df198..d8606ea 100644 --- a/include/Bezier/bezier.h +++ b/include/Bezier/bezier.h @@ -79,12 +79,19 @@ class Curve */ std::pair endPoints() const; + /*! + * \brief Get a polyline representation of the curve as a vector of points on curve + * \return A vector of polyline vertices + * \note Default flatness parameter is calculated as 0.1% for bounding box diagonal + */ + PointVector polyline() const; + /*! * \brief Get a polyline representation of the curve as a vector of points on curve * \param flatness Error tolerance of approximation * \return A vector of polyline vertices */ - PointVector polyline(double flatness = 0.5) const; + PointVector polyline(double flatness) const; /*! * \brief Compute exact arc length using Chebyshev polynomials diff --git a/src/bezier.cpp b/src/bezier.cpp index e78941d..5d5f9f7 100644 --- a/src/bezier.cpp +++ b/src/bezier.cpp @@ -44,6 +44,11 @@ Point Curve::controlPoint(unsigned idx) const { return control_points_.row(idx); std::pair Curve::endPoints() const { return {control_points_.row(0), control_points_.row(N_ - 1)}; } +PointVector Curve::polyline() const +{ + return polyline(boundingBox().diagonal().norm() / 1000); +} + PointVector Curve::polyline(double flatness) const { if (!cached_polyline_ || cached_polyline_flatness_ != flatness)