From 4c3c5d9d061b449d242ac0543055473c4c2d0702 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Wed, 11 Jun 2025 00:17:54 +0200 Subject: [PATCH] lottie: readability++ Introduce the _colinear function - checks if a Bezier curve is degenerated to a line. --- src/loaders/lottie/tvgLottieModifier.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/loaders/lottie/tvgLottieModifier.cpp b/src/loaders/lottie/tvgLottieModifier.cpp index 9100ba2b..ecbfa67a 100644 --- a/src/loaders/lottie/tvgLottieModifier.cpp +++ b/src/loaders/lottie/tvgLottieModifier.cpp @@ -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& cmds, Array& 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;