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

fix Geometry/Arc point in arc function #28

Merged
merged 3 commits into from
Sep 3, 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
3 changes: 2 additions & 1 deletion include/Armorial/Geometry/Arc/Arc.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ namespace Geometry {
/*!
* \brief Checks if a given point is contained in this Arc.
* \param point The given point.
* \param error The error used to consider points in outskirts of the arc
* \return True if the point is contained in this Arc and False otherwise.
*/
[[nodiscard]] bool pointInArc(const Vector2D &point) const;
[[nodiscard]] bool pointInArc(const Vector2D &point, float error = 0.0f) const;

/*!
* \return The absolute angle of an arc.
Expand Down
9 changes: 5 additions & 4 deletions src/Armorial/Geometry/Arc/Arc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ bool Arc::angleWithinArc(const Geometry::Angle &angle) const {
}
}

bool Arc::pointInArc(const Vector2D &point) const {
bool Arc::pointInArc(const Vector2D &point, float error) const {
Vector2D normPoint = point - center();
return (angleWithinArc(normPoint.angle()) && (normPoint.length() <= radius()));
return (angleWithinArc(normPoint.angle()) && (normPoint.length() <= (radius() + error)));
}

float Arc::arcAngle() const{
float temp = _endAngle.value() - _startAngle.value();
float temp = endAngle().value() - startAngle().value();
if(temp < 0){
temp+=M_PI*2;
}
Expand All @@ -92,7 +92,8 @@ std::vector<Vector2D> Arc::intersectionWithLine(const LineSegment &lineSegment)
// For each point in the intersection result, check if it is contained in the arc
// and put it into the vector if True
for(auto p : intersectionsWithCircle) {
if(pointInArc(p)) {
// Vector2D newP = (p - _center) * 0.9 + _center; // decreasing p radius in order to fit properly in pointInArc() function
if(pointInArc(p, 0.01f)) {
intersections.push_back(p);
}
}
Expand Down
Loading