mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 20:14:37 +00:00
lottie: readability++
Introduce the _colinear function - checks if a Bezier curve is degenerated to a line.
This commit is contained in:
parent
8f10f45756
commit
4c3c5d9d06
1 changed files with 10 additions and 8 deletions
|
@ -27,6 +27,12 @@
|
|||
/* Internal Class Implementation */
|
||||
/************************************************************************/
|
||||
|
||||
static bool _colinear(const Point* p)
|
||||
{
|
||||
return tvg::zero(*p - *(p + 1)) && tvg::zero(*(p + 2) - *(p + 3));
|
||||
}
|
||||
|
||||
|
||||
static void _roundCorner(Array<PathCommand>& cmds, Array<Point>& pts, Point& prev, Point& curr, Point& next, float r)
|
||||
{
|
||||
auto lenPrev = length(prev - curr);
|
||||
|
@ -192,14 +198,10 @@ bool LottieRoundnessModifier::modifyPath(PathCommand* inCmds, uint32_t inCmdsCnt
|
|||
break;
|
||||
}
|
||||
case PathCommand::CubicTo: {
|
||||
auto& prev = inPts[iPts - 1];
|
||||
auto& curr = inPts[iPts + 2];
|
||||
if (iCmds < inCmdsCnt - 1 &&
|
||||
tvg::zero(inPts[iPts - 1] - inPts[iPts]) &&
|
||||
tvg::zero(inPts[iPts + 1] - inPts[iPts + 2])) {
|
||||
if (inCmds[iCmds + 1] == PathCommand::CubicTo &&
|
||||
tvg::zero(inPts[iPts + 2] - inPts[iPts + 3]) &&
|
||||
tvg::zero(inPts[iPts + 4] - inPts[iPts + 5])) {
|
||||
if (iCmds < inCmdsCnt - 1 && _colinear(inPts + iPts - 1)) {
|
||||
auto& prev = inPts[iPts - 1];
|
||||
auto& curr = inPts[iPts + 2];
|
||||
if (inCmds[iCmds + 1] == PathCommand::CubicTo && _colinear(inPts + iPts + 2)) {
|
||||
_roundCorner(path.cmds, path.pts, prev, curr, inPts[iPts + 5], r);
|
||||
iPts += 3;
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue