ladybird/Libraries/LibWeb/CSS/EasingFunction.h
Andreas Kling bc3bd28378 LibWeb: Use Newton-Raphson for cubic-bezier easing evaluation
Replace the previous caching/binary-search approach with
Newton-Raphson iteration and bisection fallback. This is the
same algorithm used by WebKit, Chromium, and Firefox.

The old code had a broken binary search comparator that could never
return 0 (the second condition was always true when the first was
false), leading to out-of-bounds vector accesses and crashes.

Fixes #3628.
2026-03-21 18:21:31 -05:00

58 lines
1.3 KiB
C++

/*
* Copyright (c) 2025, Callum Law <callumlaw1709@outlook.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/CSS/StyleValues/StyleValue.h>
namespace Web::CSS {
struct LinearEasingFunction {
struct ControlPoint {
Optional<double> input;
double output;
};
Vector<ControlPoint> control_points;
String stringified;
double evaluate_at(double input_progress, bool before_flag) const;
};
struct CubicBezierEasingFunction {
double x1;
double y1;
double x2;
double y2;
String stringified;
double evaluate_at(double input_progress, bool before_flag) const;
};
struct StepsEasingFunction {
i64 interval_count;
StepPosition position;
String stringified;
double evaluate_at(double input_progress, bool before_flag) const;
};
struct EasingFunction : public Variant<LinearEasingFunction, CubicBezierEasingFunction, StepsEasingFunction> {
using Variant::Variant;
static EasingFunction linear();
static EasingFunction ease_in();
static EasingFunction ease_out();
static EasingFunction ease_in_out();
static EasingFunction ease();
static EasingFunction from_style_value(StyleValue const&);
double evaluate_at(double input_progress, bool before_flag) const;
String to_string() const;
};
}