lottie: code refactoring.

Maintains compact lines of code and functions without altering logic,
consistently prioritizing simplicity in software complexity metrics.
This commit is contained in:
Hermet Park 2024-03-03 13:21:46 +09:00
parent 3b6b538a19
commit f606903470
3 changed files with 41 additions and 55 deletions

View file

@ -31,6 +31,7 @@
#define MATH_PI 3.14159265358979323846f
#define MATH_PI2 1.57079632679489661923f
#define PATH_KAPPA 0.552284f
#define mathMin(x, y) (((x) < (y)) ? (x) : (y))
#define mathMax(x, y) (((x) > (y)) ? (x) : (y))

View file

@ -23,6 +23,7 @@
#include <cstring>
#include "tvgCommon.h"
#include "tvgMath.h"
#include "tvgPaint.h"
#include "tvgShape.h"
#include "tvgInlist.h"
@ -34,8 +35,6 @@
/************************************************************************/
/* Internal Class Implementation */
/************************************************************************/
constexpr auto PATH_KAPPA = 0.552284f;
struct RenderRepeater
{
@ -373,24 +372,19 @@ static void _repeat(LottieGroup* parent, unique_ptr<Shape> path, RenderContext*
}
static void _appendSharpRect(Shape* shape, float x, float y, float w, float h, float r)
static void _appendRect(Shape* shape, float x, float y, float w, float h, float r)
{
constexpr int commandsCnt = 5;
PathCommand commands[commandsCnt] = {
//sharp rect
if (mathZero(r)) {
PathCommand commands[] = {
PathCommand::MoveTo, PathCommand::LineTo, PathCommand::LineTo,
PathCommand::LineTo, PathCommand::Close
};
constexpr int pointsCnt = 4;
Point points[pointsCnt] = {{x + w, y}, {x + w, y + h}, {x, y + h}, {x, y}};
shape->appendPath(commands, commandsCnt, points, pointsCnt);
}
static void _appendRoundedRect(Shape* shape, float x, float y, float w, float h, float r)
{
constexpr int commandsCnt = 10;
PathCommand commands[commandsCnt] = {
Point points[] = {{x + w, y}, {x + w, y + h}, {x, y + h}, {x, y}};
shape->appendPath(commands, 5, points, 4);
//round rect
} else {
PathCommand commands[] = {
PathCommand::MoveTo, PathCommand::LineTo, PathCommand::CubicTo,
PathCommand::LineTo, PathCommand::CubicTo, PathCommand::LineTo,
PathCommand::CubicTo, PathCommand::LineTo, PathCommand::CubicTo,
@ -399,15 +393,12 @@ static void _appendRoundedRect(Shape* shape, float x, float y, float w, float h,
auto halfW = w * 0.5f;
auto halfH = h * 0.5f;
auto rx = r > halfW ? halfW : r;
auto ry = r > halfH ? halfH : r;
auto hrx = rx * PATH_KAPPA;
auto hry = ry * PATH_KAPPA;
constexpr int pointsCnt = 17;
Point points[pointsCnt] = {
Point points[] = {
{x + w, y + ry}, //moveTo
{x + w, y + h - ry}, //lineTo
{x + w, y + h - ry + hry}, {x + w - rx + hrx, y + h}, {x + w - rx, y + h}, //cubicTo
@ -419,14 +410,8 @@ static void _appendRoundedRect(Shape* shape, float x, float y, float w, float h,
{x + w - rx + hrx, y}, {x + w, y + ry - hry}, {x + w, y + ry} //cubicTo
};
shape->appendPath(commands, commandsCnt, points, pointsCnt);
}
static void _appendRect(Shape* shape, float x, float y, float w, float h, float r)
{
if (mathZero(r)) _appendSharpRect(shape, x, y, w, h, r);
else _appendRoundedRect(shape, x, y, w, h, r);
shape->appendPath(commands, 10, points, 17);
}
}
static void _updateRect(LottieGroup* parent, LottieObject** child, float frameNo, TVG_UNUSED Inlist<RenderContext>& contexts, RenderContext* ctx)

View file

@ -26,7 +26,7 @@
/************************************************************************/
/* Internal Class Implementation */
/************************************************************************/
constexpr auto PATH_KAPPA = 0.552284f;
/************************************************************************/
/* External Class Implementation */