Skip to content

Commit

Permalink
Path2d::angleHelper() is now an anonymous namespace function.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhoux committed Jan 8, 2024
1 parent 8b71336 commit 76ddae2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
4 changes: 1 addition & 3 deletions include/cinder/Path2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,7 @@ class CI_API Path2d {
private:
void arcHelper( const vec2 &center, float radius, float startRadians, float endRadians, bool forward );
void arcSegmentAsCubicBezier( const vec2 &center, float radius, float startRadians, float endRadians );

float angleHelper( const vec2 &u, const vec2 &v ) const;


//! Returns the minimum distance from point \a pt to segment \a segment. The \a firstPoint parameter can be used as an optimization if known, otherwise pass 0.
float calcDistance( const vec2 &pt, size_t segment, size_t firstPoint ) const;

Expand Down
20 changes: 12 additions & 8 deletions src/cinder/Path2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,6 @@ void Path2d::arcSegmentAsCubicBezier( const vec2 &center, float radius, float st
center.y + r_sin_B - h * r_cos_B, center.x + r_cos_B, center.y + r_sin_B );
}

float Path2d::angleHelper( const vec2 &u, const vec2 &v ) const
{
// See: equation 5.4 of https://www.w3.org/TR/SVG/implnote.html
const float c = u.x * v.y - u.y * v.x;
const float d = glm::dot( glm::normalize( u ), glm::normalize( v ) );
return c < 0 ? -math<float>::acos( d ) : math<float>::acos( d );
}

// Implementation courtesy of Lennart Kudling
void Path2d::arcTo( const vec2 &p1, const vec2 &t, float radius )
{
Expand Down Expand Up @@ -395,6 +387,18 @@ void Path2d::arcTo( const vec2 &p1, const vec2 &t, float radius )
}
}

namespace {

float angleHelper( const vec2 &u, const vec2 &v )
{
// See: equation 5.4 of https://www.w3.org/TR/SVG/implnote.html
const float c = u.x * v.y - u.y * v.x;
const float d = glm::dot( glm::normalize( u ), glm::normalize( v ) );
return c < 0 ? -math<float>::acos( d ) : math<float>::acos( d );
}

} // namespace

void Path2d::arcTo( float rx, float ry, float phi, bool largeArcFlag, bool sweepFlag, const vec2 &p2 )
{
// See: https://www.w3.org/TR/SVG/implnote.html
Expand Down

0 comments on commit 76ddae2

Please sign in to comment.