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

Refactor: Use CubicBezierSampler to sample curves #479

Merged
merged 3 commits into from
Mar 11, 2025

Conversation

yungyuc
Copy link
Member

@yungyuc yungyuc commented Mar 11, 2025

Make a (new) common helper class template CubicBezierSampler to sample for a single cubic Bezier curve or a sequence of cubic Bezier curves in CurvePad.

@@ -49,6 +49,11 @@ class Point3d

using value_type = T;

Point3d(T x, T y)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need new constructors of Point3d and Segment3d.

{
}

CubicBezierSampler() = delete;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The helper class template does not need default and copy constructors.


static size_t sample_to(bezier_type const & c, segment_pad_type & segment, size_t nlocus);

std::shared_ptr<segment_pad_type> m_segments;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internal segment pad.

}; /* end class CubicBezierSampler */

template <typename T>
size_t CubicBezierSampler<T>::calc_nlocus(Bezier3d<T> const & c, T length)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calculate number of locus based on p0-p3.

}

template <typename T>
size_t CubicBezierSampler<T>::sample_to(bezier_type const & c, segment_pad_type & segments, size_t nlocus)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a naive sampling algorithm to add segments to a container.

}
spad->set(iseg, lastp, tp3);
++iseg;
sample_to(c, *m_segments, nlocus);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add sampled segments to the internal pad.

template <typename T>
std::shared_ptr<SegmentPad<T>> CubicBezierSampler<T>::operator()(bezier_type const & curve, size_t nlocus, bool inplace)
{
std::shared_ptr<segment_pad_type> segments = inplace ? m_segments : segment_pad_type::construct(m_segments->ndim());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow switching between a new or internal pad.

@yungyuc yungyuc added the refactor Change code without changing tests label Mar 11, 2025
@yungyuc yungyuc self-assigned this Mar 11, 2025
@yungyuc yungyuc added the geometry Geometry entities and manipulation label Mar 11, 2025
@yungyuc yungyuc merged commit 2be6101 into solvcon:master Mar 11, 2025
12 checks passed
@yungyuc yungyuc deleted the refactor/CubicBezierSampler branch March 11, 2025 14:27
@yungyuc
Copy link
Member Author

yungyuc commented Mar 11, 2025

@YenPeiChen07 @j8xixo12 please take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
geometry Geometry entities and manipulation refactor Change code without changing tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant