mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-13 11:36:25 +00:00
common: fix a precision issue in appendArc api
For angles close to multiples of pi/2, precision based on FLT_EPSILON was insufficient. It either led to the creation of an additional cubic segment filled with erroneous values or NaNs, or it resulted in the drawing of an angle for a sweep close to 0.
This commit is contained in:
parent
6503fcc8a8
commit
d27a9782d4
1 changed files with 4 additions and 2 deletions
|
@ -145,13 +145,15 @@ Result Shape::appendArc(float cx, float cy, float radius, float startAngle, floa
|
||||||
//just circle
|
//just circle
|
||||||
if (sweep >= 360.0f || sweep <= -360.0f) return appendCircle(cx, cy, radius, radius);
|
if (sweep >= 360.0f || sweep <= -360.0f) return appendCircle(cx, cy, radius, radius);
|
||||||
|
|
||||||
|
const float arcPrecision = 1e-5f;
|
||||||
startAngle = mathDeg2Rad(startAngle);
|
startAngle = mathDeg2Rad(startAngle);
|
||||||
sweep = mathDeg2Rad(sweep);
|
sweep = mathDeg2Rad(sweep);
|
||||||
|
|
||||||
auto nCurves = ceil(fabsf(sweep / MATH_PI2));
|
auto nCurves = static_cast<int>(fabsf(sweep / MATH_PI2));
|
||||||
|
if (fabsf(sweep / MATH_PI2) - nCurves > arcPrecision) ++nCurves;
|
||||||
auto sweepSign = (sweep < 0 ? -1 : 1);
|
auto sweepSign = (sweep < 0 ? -1 : 1);
|
||||||
auto fract = fmodf(sweep, MATH_PI2);
|
auto fract = fmodf(sweep, MATH_PI2);
|
||||||
fract = (mathZero(fract)) ? MATH_PI2 * sweepSign : fract;
|
fract = (fabsf(fract) < arcPrecision) ? MATH_PI2 * sweepSign : fract;
|
||||||
|
|
||||||
//Start from here
|
//Start from here
|
||||||
Point start = {radius * cosf(startAngle), radius * sinf(startAngle)};
|
Point start = {radius * cosf(startAngle), radius * sinf(startAngle)};
|
||||||
|
|
Loading…
Add table
Reference in a new issue