From ed6cac89b9357777b3ecf012625b6571b14fc40a Mon Sep 17 00:00:00 2001 From: Callum Law Date: Tue, 12 Aug 2025 23:35:43 +1200 Subject: [PATCH] LibWeb: Discard inaccuracies when interpolating `rotate` --- Libraries/LibWeb/CSS/Interpolation.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/CSS/Interpolation.cpp b/Libraries/LibWeb/CSS/Interpolation.cpp index 36579237f6b..b60608ce6f8 100644 --- a/Libraries/LibWeb/CSS/Interpolation.cpp +++ b/Libraries/LibWeb/CSS/Interpolation.cpp @@ -360,8 +360,15 @@ static FloatVector4 slerp(FloatVector4 const& from, FloatVector4 const& to, floa auto theta = acosf(product); auto w = sinf(delta * theta) / sqrtf(1 - (product * product)); + auto from_multiplier = cosf(delta * theta) - (product * w); - return from * (cosf(delta * theta) - (product * w)) + to * w; + if (abs(w) < AK::NumericLimits::epsilon()) + return from * from_multiplier; + + if (abs(from_multiplier) < AK::NumericLimits::epsilon()) + return to * w; + + return from * from_multiplier + to * w; } static RefPtr interpolate_rotate(DOM::Element& element, CalculationContext calculation_context, StyleValue const& a_from, StyleValue const& a_to, float delta, AllowDiscrete allow_discrete)