Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/loaders/lottie/tvgLottieBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,29 @@ static void _repeat(LottieGroup* parent, Shape* path, RenderContext* ctx)
}


static void _close(RenderPath& path, const Point& p, bool round, bool rect = false)
Copy link
Member

@hermet hermet Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rectangle itself doesn't need this logic. This kind of patchwork solution looks bad.

{
//the only case where the shape was truly closed via a 'close' command - change important for modifiers to ensure consistency with other cases
if (rect) {
if (!round) {
path.pts.push(p);
path.cmds.last() = PathCommand::LineTo;
path.cmds.push(PathCommand::Close);
}
return;
}
if (round && tvg::zero(path.pts.last() - path.pts[path.pts.count - 2])) path.pts[path.pts.count - 2] = p;
path.pts.last() = p;
}


void LottieBuilder::appendRect(Shape* shape, Point& pos, Point& size, float r, bool clockwise, RenderContext* ctx)
{
auto temp = (ctx->offset) ? Shape::gen() : shape;
auto cnt = SHAPE(temp)->rs.path.pts.count;

temp->appendRect(pos.x, pos.y, size.x, size.y, r, r, clockwise);
_close(SHAPE(temp)->rs.path, SHAPE(temp)->rs.path.pts[cnt], r > 0.0f, true);

if (ctx->transform) {
for (auto i = cnt; i < SHAPE(temp)->rs.path.pts.count; ++i) {
Expand Down Expand Up @@ -489,13 +506,6 @@ void LottieBuilder::updatePath(LottieGroup* parent, LottieObject** child, float
}


static void _close(Array<Point>& pts, const Point& p, bool round)
{
if (round && tvg::zero(pts.last() - pts[pts.count - 2])) pts[pts.count - 2] = p;
pts.last() = p;
}


void LottieBuilder::updateStar(LottiePolyStar* star, float frameNo, Matrix* transform, Shape* merging, RenderContext* ctx, Tween& tween, LottieExpressions* exps)
{
static constexpr auto POLYSTAR_MAGIC_NUMBER = 0.47829f / 0.28f;
Expand Down Expand Up @@ -604,7 +614,7 @@ void LottieBuilder::updateStar(LottiePolyStar* star, float frameNo, Matrix* tran
longSegment = !longSegment;
}
//ensure proper shape closure - important for modifiers that behave differently for degenerate (linear) vs curved cubics
_close(SHAPE(shape)->rs.path.pts, in, hasRoundness);
_close(SHAPE(shape)->rs.path, in, hasRoundness);
shape->close();

if (ctx->modifier) ctx->modifier->modifyPolystar(SHAPE(shape)->rs.path, SHAPE(merging)->rs.path, outerRoundness, hasRoundness);
Expand Down Expand Up @@ -674,7 +684,7 @@ void LottieBuilder::updatePolygon(LottieGroup* parent, LottiePolyStar* star, flo
angle += anglePerPoint * direction;
}
//ensure proper shape closure - important for modifiers that behave differently for degenerate (linear) vs curved cubics
_close(SHAPE(shape)->rs.path.pts, in, hasRoundness);
_close(SHAPE(shape)->rs.path, in, hasRoundness);
shape->close();

if (ctx->modifier) ctx->modifier->modifyPolystar(SHAPE(shape)->rs.path, SHAPE(merging)->rs.path, 0.0f, false);
Expand Down
7 changes: 1 addition & 6 deletions src/loaders/lottie/tvgLottieModifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,7 @@ bool LottieOffsetModifier::modifyPath(PathCommand* inCmds, uint32_t inCmdsCnt, P
}

iPt += 3;
}
else {
if (!tvg::zero(inPts[iPt - 1] - inPts[state.movetoInIndex])) {
out.cmds.push(PathCommand::LineTo);
corner(out, state.line, state.firstLine, state.movetoOutIndex, true);
}
} else {
Copy link

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of additional handling logic in the else branch simplifies the path closure but may obscure the intent for non-rectangle shapes. Consider adding a comment to explain why this change is safe and how it aligns with the overall modifier behavior.

Suggested change
} else {
} else {
// The PathCommand::Close operation is sufficient for closing paths in the current implementation.
// This logic is safe and aligns with the overall behavior of the modifier, as it handles specific path types
// (e.g., rectangles, ellipses) that do not require additional closure handling for non-rectangle shapes.

Copilot uses AI. Check for mistakes.

out.cmds.push(PathCommand::Close);
}
}
Expand Down
Loading