lottie: readability++

Introduce the _colinear function - checks if a Bezier curve
is degenerated to a line.
This commit is contained in:
Mira Grudzinska 2025-06-11 00:17:54 +02:00 committed by Hermet Park
parent 8f10f45756
commit 4c3c5d9d06

View file

@ -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: {
if (iCmds < inCmdsCnt - 1 && _colinear(inPts + iPts - 1)) {
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 (inCmds[iCmds + 1] == PathCommand::CubicTo && _colinear(inPts + iPts + 2)) {
_roundCorner(path.cmds, path.pts, prev, curr, inPts[iPts + 5], r);
iPts += 3;
break;