common: Use explicit floating-point value types.

Co-Authored-By: Hermet Park <hermet@lottiefiles.com>
This commit is contained in:
faxe1008 2025-01-10 11:55:06 +09:00 committed by Hermet Park
parent 9a8173cc22
commit 0c09580cd4
9 changed files with 23 additions and 23 deletions

View file

@ -183,7 +183,7 @@ float strToFloat(const char *nPtr, char **endPtr)
auto scale = 1.0f;
while (exponentPart >= 8U) {
scale *= 1E8;
scale *= 1E8f;
exponentPart -= 8U;
}
while (exponentPart > 0U) {

View file

@ -1375,7 +1375,7 @@ void LottieBuilder::updateEffect(LottieLayer* layer, float frameNo)
auto effect = static_cast<LottieFxTint*>(*ef);
auto black = effect->black(frameNo);
auto white = effect->white(frameNo);
layer->scene->push(SceneEffect::Tint, black.rgb[0], black.rgb[1], black.rgb[2], white.rgb[0], white.rgb[1], white.rgb[2], effect->intensity(frameNo));
layer->scene->push(SceneEffect::Tint, black.rgb[0], black.rgb[1], black.rgb[2], white.rgb[0], white.rgb[1], white.rgb[2], (double)effect->intensity(frameNo));
break;
}
case LottieEffect::Fill: {
@ -1401,12 +1401,12 @@ void LottieBuilder::updateEffect(LottieLayer* layer, float frameNo)
auto effect = static_cast<LottieFxDropShadow*>(*ef);
auto color = effect->color(frameNo);
//seems the opacity range in dropshadow is 0 ~ 256
layer->scene->push(SceneEffect::DropShadow, color.rgb[0], color.rgb[1], color.rgb[2], std::min(255, (int)effect->opacity(frameNo)), effect->angle(frameNo), effect->distance(frameNo), effect->blurness(frameNo) * BLUR_TO_SIGMA, QUALITY);
layer->scene->push(SceneEffect::DropShadow, color.rgb[0], color.rgb[1], color.rgb[2], std::min(255, (int)effect->opacity(frameNo)), (double)effect->angle(frameNo), (double)effect->distance(frameNo), (double)effect->blurness(frameNo) * BLUR_TO_SIGMA, QUALITY);
break;
}
case LottieEffect::GaussianBlur: {
auto effect = static_cast<LottieFxGaussianBlur*>(*ef);
layer->scene->push(SceneEffect::GaussianBlur, effect->blurness(frameNo) * BLUR_TO_SIGMA, effect->direction(frameNo) - 1, effect->wrap(frameNo), QUALITY);
layer->scene->push(SceneEffect::GaussianBlur, (double)effect->blurness(frameNo) * BLUR_TO_SIGMA, effect->direction(frameNo) - 1, effect->wrap(frameNo), QUALITY);
break;
}
default: break;

View file

@ -484,7 +484,7 @@ static jerry_value_t _linear(const jerry_call_info_t* info, const jerry_value_t
static jerry_value_t _ease(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt)
{
auto t = (float) jerry_value_as_number(args[0]);
t = (t < 0.5) ? (4 * t * t * t) : (1.0f - pow(-2.0f * t + 2.0f, 3) * 0.5f);
t = (t < 0.5f) ? (4 * t * t * t) : (1.0f - powf(-2.0f * t + 2.0f, 3) * 0.5f);
return _interp(t, args, jerry_value_as_uint32(argsCnt));
}
@ -501,7 +501,7 @@ static jerry_value_t _easeIn(const jerry_call_info_t* info, const jerry_value_t
static jerry_value_t _easeOut(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt)
{
auto t = (float) jerry_value_as_number(args[0]);
t = 1.0f - pow(1.0f - t, 3);
t = 1.0f - powf(1.0f - t, 3);
return _interp(t, args, jerry_value_as_uint32(argsCnt));
}

View file

@ -79,7 +79,7 @@ float LottieInterpolator::getTForX(float aX)
// instead.
auto initialSlope = _getSlope(guessForT, outTangent.x, inTangent.x);
if (initialSlope >= NEWTON_MIN_SLOPE) return NewtonRaphsonIterate(aX, guessForT);
else if (initialSlope == 0.0) return guessForT;
else if (initialSlope == 0.0f) return guessForT;
else return binarySubdivide(aX, intervalStart, intervalStart + SAMPLE_STEP_SIZE);
}

View file

@ -170,7 +170,7 @@ static float _gradientToFloat(const SvgParser* svgParse, const char* str, bool&
isPercentage = false;
if (strstr(str, "%")) {
parsedValue = parsedValue / 100.0;
parsedValue = parsedValue / 100.0f;
isPercentage = true;
}
else if (strstr(str, "cm")) parsedValue *= PX_PER_CM;
@ -195,7 +195,7 @@ static float _toOffset(const char* str)
auto ptr = strstr(str, "%");
if (ptr) {
parsedValue = parsedValue / 100.0;
parsedValue = parsedValue / 100.0f;
if (end != ptr || (end + 1) != strEnd) return 0;
} else if (end != strEnd) return 0;

View file

@ -374,10 +374,10 @@ static bool _processCommand(Array<PathCommand>* cmds, Array<Point>* pts, char cm
case 'q':
case 'Q': {
Point p[3];
float ctrl_x0 = (cur->x + 2 * arr[0]) * (1.0 / 3.0);
float ctrl_y0 = (cur->y + 2 * arr[1]) * (1.0 / 3.0);
float ctrl_x1 = (arr[2] + 2 * arr[0]) * (1.0 / 3.0);
float ctrl_y1 = (arr[3] + 2 * arr[1]) * (1.0 / 3.0);
float ctrl_x0 = (cur->x + 2 * arr[0]) * (1.0f / 3.0f);
float ctrl_y0 = (cur->y + 2 * arr[1]) * (1.0f / 3.0f);
float ctrl_x1 = (arr[2] + 2 * arr[0]) * (1.0f / 3.0f);
float ctrl_y1 = (arr[3] + 2 * arr[1]) * (1.0f / 3.0f);
cmds->push(PathCommand::CubicTo);
p[0] = {ctrl_x0, ctrl_y0};
p[1] = {ctrl_x1, ctrl_y1};
@ -400,10 +400,10 @@ static bool _processCommand(Array<PathCommand>* cmds, Array<Point>* pts, char cm
} else {
ctrl = *cur;
}
float ctrl_x0 = (cur->x + 2 * ctrl.x) * (1.0 / 3.0);
float ctrl_y0 = (cur->y + 2 * ctrl.y) * (1.0 / 3.0);
float ctrl_x1 = (arr[0] + 2 * ctrl.x) * (1.0 / 3.0);
float ctrl_y1 = (arr[1] + 2 * ctrl.y) * (1.0 / 3.0);
float ctrl_x0 = (cur->x + 2 * ctrl.x) * (1.0f / 3.0f);
float ctrl_y0 = (cur->y + 2 * ctrl.y) * (1.0f / 3.0f);
float ctrl_x1 = (arr[0] + 2 * ctrl.x) * (1.0f / 3.0f);
float ctrl_y1 = (arr[1] + 2 * ctrl.y) * (1.0f / 3.0f);
cmds->push(PathCommand::CubicTo);
p[0] = {ctrl_x0, ctrl_y0};
p[1] = {ctrl_x1, ctrl_y1};

View file

@ -88,7 +88,7 @@ float Animation::duration() const noexcept
Result Animation::segment(float begin, float end) noexcept
{
if (begin < 0.0 || end > 1.0 || begin > end) return Result::InvalidArguments;
if (begin < 0.0f || end > 1.0f || begin > end) return Result::InvalidArguments;
auto loader = PICTURE(pImpl->picture)->loader;
if (!loader) return Result::InsufficientCondition;

View file

@ -343,7 +343,7 @@ struct RenderEffectTint : RenderEffect
inst->white[0] = va_arg(args, int);
inst->white[1] = va_arg(args, int);
inst->white[2] = va_arg(args, int);
inst->intensity = (uint8_t)(va_arg(args, double) * 2.55f);
inst->intensity = (uint8_t)(va_arg(args, double) * 2.55);
inst->type = SceneEffect::Tint;
return inst;
}

View file

@ -308,16 +308,16 @@ TEST_CASE("Animation Segment", "[tvgAnimation]")
//Get current segment
REQUIRE(animation->segment(&begin, &end) == Result::Success);
REQUIRE(begin == 0.25);
REQUIRE(end == 0.5);
REQUIRE(begin == 0.25f);
REQUIRE(end == 0.5f);
//Get only segment begin
REQUIRE(animation->segment(&begin) == Result::Success);
REQUIRE(begin == 0.25);
REQUIRE(begin == 0.25f);
//Get only segment end
REQUIRE(animation->segment(nullptr, &end) == Result::Success);
REQUIRE(end == 0.5);
REQUIRE(end == 0.5f);
//Segment by invalid range
REQUIRE(animation->segment(-0.5, 1.5) == Result::InvalidArguments);