Skip to content

Commit

Permalink
Change default flatness parameter to be dynamic (0.1% of bbox diagonal)
Browse files Browse the repository at this point in the history
  • Loading branch information
stribor14 authored and stribor14 committed Oct 1, 2024
1 parent f79db79 commit c0828f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion include/Bezier/bezier.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,19 @@ class Curve
*/
std::pair<Point, Point> 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
Expand Down
5 changes: 5 additions & 0 deletions src/bezier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ Point Curve::controlPoint(unsigned idx) const { return control_points_.row(idx);

std::pair<Point, Point> 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)
Expand Down

0 comments on commit c0828f1

Please sign in to comment.