mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
sw_engine shape: expand the algorithm to draw arcs with negative angles
The _appendArc function allows to draw angles only in a clockwise direction. The introduced improvement allows to change this direction by giving the 'sweep' argument with a negative value.
This commit is contained in:
parent
ac43ec591e
commit
d3bd55dbc7
1 changed files with 4 additions and 4 deletions
|
@ -153,14 +153,15 @@ Result Shape::appendArc(float cx, float cy, float radius, float startAngle, floa
|
||||||
const float M_PI_HALF = M_PI * 0.5f;
|
const float M_PI_HALF = M_PI * 0.5f;
|
||||||
|
|
||||||
//just circle
|
//just circle
|
||||||
if (sweep >= 360) return appendCircle(cx, cy, radius, radius);
|
if (sweep >= 360 || sweep <= -360) return appendCircle(cx, cy, radius, radius);
|
||||||
|
|
||||||
startAngle = (startAngle * M_PI) / 180;
|
startAngle = (startAngle * M_PI) / 180;
|
||||||
sweep = sweep * M_PI / 180;
|
sweep = sweep * M_PI / 180;
|
||||||
|
|
||||||
auto nCurves = ceil(abs(sweep / M_PI_HALF));
|
auto nCurves = ceil(abs(sweep / M_PI_HALF));
|
||||||
|
auto sweepSign = (sweep < 0 ? -1 : 1);
|
||||||
auto fract = fmod(sweep, M_PI_HALF);
|
auto fract = fmod(sweep, M_PI_HALF);
|
||||||
fract = (fract < std::numeric_limits<float>::epsilon()) ? M_PI_HALF : fract;
|
fract = (abs(fract) < std::numeric_limits<float>::epsilon()) ? M_PI_HALF : fract;
|
||||||
|
|
||||||
//Start from here
|
//Start from here
|
||||||
Point start = {radius * cos(startAngle), radius * sin(startAngle)};
|
Point start = {radius * cos(startAngle), radius * sin(startAngle)};
|
||||||
|
@ -173,8 +174,7 @@ Result Shape::appendArc(float cx, float cy, float radius, float startAngle, floa
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < nCurves; ++i) {
|
for (int i = 0; i < nCurves; ++i) {
|
||||||
|
auto endAngle = startAngle + ((i != nCurves - 1) ? M_PI_HALF * sweepSign : fract);
|
||||||
auto endAngle = startAngle + ((i != nCurves - 1) ? M_PI_HALF : fract);
|
|
||||||
Point end = {radius * cos(endAngle), radius * sin(endAngle)};
|
Point end = {radius * cos(endAngle), radius * sin(endAngle)};
|
||||||
|
|
||||||
//variables needed to calculate bezier control points
|
//variables needed to calculate bezier control points
|
||||||
|
|
Loading…
Add table
Reference in a new issue