Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default flatness parameter to be dynamic (0.1% of bbox diagonal) #49

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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