mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 17:07:47 +00:00
LibWeb: Change calc node representation from float to double
This commit is contained in:
parent
f5da6d61b4
commit
421559d725
22 changed files with 75 additions and 75 deletions
|
@ -16,13 +16,13 @@ Angle::Angle(int value, Type type)
|
|||
{
|
||||
}
|
||||
|
||||
Angle::Angle(float value, Type type)
|
||||
Angle::Angle(double value, Type type)
|
||||
: m_type(type)
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
Angle Angle::make_degrees(float value)
|
||||
Angle Angle::make_degrees(double value)
|
||||
{
|
||||
return { value, Type::Deg };
|
||||
}
|
||||
|
@ -37,17 +37,17 @@ ErrorOr<String> Angle::to_string() const
|
|||
return String::formatted("{}deg", to_degrees());
|
||||
}
|
||||
|
||||
float Angle::to_degrees() const
|
||||
double Angle::to_degrees() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case Type::Deg:
|
||||
return m_value;
|
||||
case Type::Grad:
|
||||
return m_value * (360.0f / 400.0f);
|
||||
return m_value * (360.0 / 400.0);
|
||||
case Type::Rad:
|
||||
return m_value * (180.0f / AK::Pi<float>);
|
||||
return m_value * (180.0 / AK::Pi<double>);
|
||||
case Type::Turn:
|
||||
return m_value * 360.0f;
|
||||
return m_value * 360.0;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
|
@ -23,15 +23,15 @@ public:
|
|||
static Optional<Type> unit_from_name(StringView);
|
||||
|
||||
Angle(int value, Type type);
|
||||
Angle(float value, Type type);
|
||||
static Angle make_degrees(float);
|
||||
Angle(double value, Type type);
|
||||
static Angle make_degrees(double);
|
||||
Angle percentage_of(Percentage const&) const;
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
float to_degrees() const;
|
||||
double to_degrees() const;
|
||||
|
||||
Type type() const { return m_type; }
|
||||
float raw_value() const { return m_value; }
|
||||
double raw_value() const { return m_value; }
|
||||
|
||||
bool operator==(Angle const& other) const
|
||||
{
|
||||
|
@ -42,7 +42,7 @@ private:
|
|||
StringView unit_name() const;
|
||||
|
||||
Type m_type;
|
||||
float m_value { 0 };
|
||||
double m_value { 0 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ public:
|
|||
bool operator==(BorderData const&) const = default;
|
||||
};
|
||||
|
||||
using TransformValue = Variant<CSS::AngleOrCalculated, CSS::LengthPercentage, float>;
|
||||
using TransformValue = Variant<CSS::AngleOrCalculated, CSS::LengthPercentage, double>;
|
||||
|
||||
struct Transformation {
|
||||
CSS::TransformFunction function;
|
||||
|
|
|
@ -15,13 +15,13 @@ Frequency::Frequency(int value, Type type)
|
|||
{
|
||||
}
|
||||
|
||||
Frequency::Frequency(float value, Type type)
|
||||
Frequency::Frequency(double value, Type type)
|
||||
: m_type(type)
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
Frequency Frequency::make_hertz(float value)
|
||||
Frequency Frequency::make_hertz(double value)
|
||||
{
|
||||
return { value, Type::Hz };
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ ErrorOr<String> Frequency::to_string() const
|
|||
return String::formatted("{}hz", to_hertz());
|
||||
}
|
||||
|
||||
float Frequency::to_hertz() const
|
||||
double Frequency::to_hertz() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case Type::Hz:
|
||||
|
|
|
@ -20,15 +20,15 @@ public:
|
|||
static Optional<Type> unit_from_name(StringView);
|
||||
|
||||
Frequency(int value, Type type);
|
||||
Frequency(float value, Type type);
|
||||
static Frequency make_hertz(float);
|
||||
Frequency(double value, Type type);
|
||||
static Frequency make_hertz(double);
|
||||
Frequency percentage_of(Percentage const&) const;
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
float to_hertz() const;
|
||||
double to_hertz() const;
|
||||
|
||||
Type type() const { return m_type; }
|
||||
float raw_value() const { return m_value; }
|
||||
double raw_value() const { return m_value; }
|
||||
|
||||
bool operator==(Frequency const& other) const
|
||||
{
|
||||
|
@ -39,7 +39,7 @@ private:
|
|||
StringView unit_name() const;
|
||||
|
||||
Type m_type;
|
||||
float m_value { 0 };
|
||||
double m_value { 0 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -25,21 +25,21 @@ public:
|
|||
, m_type(Type::Number)
|
||||
{
|
||||
}
|
||||
Number(Type type, float value)
|
||||
Number(Type type, double value)
|
||||
: m_value(value)
|
||||
, m_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
Type type() const { return m_type; }
|
||||
float value() const { return m_value; }
|
||||
double value() const { return m_value; }
|
||||
i64 integer_value() const
|
||||
{
|
||||
// https://www.w3.org/TR/css-values-4/#numeric-types
|
||||
// When a value cannot be explicitly supported due to range/precision limitations, it must be converted
|
||||
// to the closest value supported by the implementation, but how the implementation defines "closest"
|
||||
// is explicitly undefined as well.
|
||||
return llroundf(m_value);
|
||||
return llround(m_value);
|
||||
}
|
||||
bool is_integer() const { return m_type == Type::Integer || m_type == Type::IntegerWithExplicitSign; }
|
||||
bool is_integer_with_explicit_sign() const { return m_type == Type::IntegerWithExplicitSign; }
|
||||
|
@ -83,7 +83,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
float m_value { 0 };
|
||||
double m_value { 0 };
|
||||
Type m_type;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -23,13 +23,13 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
explicit Percentage(float value)
|
||||
explicit Percentage(double value)
|
||||
: m_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
float value() const { return m_value; }
|
||||
float as_fraction() const { return m_value * 0.01f; }
|
||||
double value() const { return m_value; }
|
||||
double as_fraction() const { return m_value * 0.01; }
|
||||
|
||||
ErrorOr<String> to_string() const
|
||||
{
|
||||
|
@ -39,7 +39,7 @@ public:
|
|||
bool operator==(Percentage const& other) const { return m_value == other.m_value; }
|
||||
|
||||
private:
|
||||
float m_value;
|
||||
double m_value;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1015,7 +1015,7 @@ StyleComputer::AnimationStepTransition StyleComputer::Animation::step(CSS::Time
|
|||
remaining_delay = CSS::Time { 0, CSS::Time::Type::Ms };
|
||||
time_step_ms -= delay_ms;
|
||||
|
||||
float added_progress = static_cast<float>(time_step_ms / duration.to_milliseconds());
|
||||
auto added_progress = time_step_ms / duration.to_milliseconds();
|
||||
auto new_progress = progress.as_fraction() + added_progress;
|
||||
auto changed_iteration = false;
|
||||
if (new_progress >= 1) {
|
||||
|
@ -1250,7 +1250,7 @@ ErrorOr<void> StyleComputer::Animation::collect_into(StyleProperties& style_prop
|
|||
|
||||
bool StyleComputer::Animation::is_done() const
|
||||
{
|
||||
return progress.as_fraction() >= 0.9999f && iteration_count.has_value() && iteration_count.value() == 0;
|
||||
return progress.as_fraction() >= 0.9999 && iteration_count.has_value() && iteration_count.value() == 0;
|
||||
}
|
||||
|
||||
float StyleComputer::Animation::compute_output_progress(float input_progress) const
|
||||
|
|
|
@ -513,7 +513,7 @@ void CalculatedStyleValue::CalculationResult::add_or_subtract_internal(SumOperat
|
|||
void CalculatedStyleValue::CalculationResult::multiply_by(CalculationResult const& other, Layout::Node const* layout_node)
|
||||
{
|
||||
// We know from validation when resolving the type, that at least one side must be a <number> or <integer>.
|
||||
// Both of these are represented as a float.
|
||||
// Both of these are represented as a double.
|
||||
VERIFY(m_value.has<Number>() || other.m_value.has<Number>());
|
||||
bool other_is_number = other.m_value.has<Number>();
|
||||
|
||||
|
@ -552,7 +552,7 @@ void CalculatedStyleValue::CalculationResult::divide_by(CalculationResult const&
|
|||
// Both of these are represented as a Number.
|
||||
auto denominator = other.m_value.get<Number>().value();
|
||||
// FIXME: Dividing by 0 is invalid, and should be caught during parsing.
|
||||
VERIFY(denominator != 0.0f);
|
||||
VERIFY(denominator != 0.0);
|
||||
|
||||
m_value.visit(
|
||||
[&](Number const& number) {
|
||||
|
@ -745,7 +745,7 @@ Optional<Time> CalculatedStyleValue::resolve_time_percentage(Time const& percent
|
|||
});
|
||||
}
|
||||
|
||||
Optional<float> CalculatedStyleValue::resolve_number() const
|
||||
Optional<double> CalculatedStyleValue::resolve_number() const
|
||||
{
|
||||
auto result = m_calculation->resolve(nullptr, {});
|
||||
if (result.value().has<Number>())
|
||||
|
|
|
@ -94,7 +94,7 @@ public:
|
|||
|
||||
bool resolves_to_integer() const { return m_resolved_type == ResolvedType::Integer; }
|
||||
bool resolves_to_number() const { return resolves_to_integer() || m_resolved_type == ResolvedType::Number; }
|
||||
Optional<float> resolve_number() const;
|
||||
Optional<double> resolve_number() const;
|
||||
Optional<i64> resolve_integer();
|
||||
|
||||
bool contains_percentage() const;
|
||||
|
|
|
@ -40,7 +40,7 @@ float Filter::HueRotate::angle_degrees() const
|
|||
// Default value when omitted is 0deg.
|
||||
if (!angle.has_value())
|
||||
return 0.0f;
|
||||
return angle->visit([&](Angle const& a) { return a.to_degrees(); }, [&](auto) { return 0.0f; });
|
||||
return angle->visit([&](Angle const& a) { return a.to_degrees(); }, [&](auto) { return 0.0; });
|
||||
}
|
||||
|
||||
float Filter::Color::resolved_amount() const
|
||||
|
|
|
@ -66,35 +66,35 @@ bool LinearGradientStyleValue::equals(StyleValue const& other_) const
|
|||
float LinearGradientStyleValue::angle_degrees(CSSPixelSize gradient_size) const
|
||||
{
|
||||
auto corner_angle_degrees = [&] {
|
||||
return static_cast<float>(atan2(gradient_size.height().value(), gradient_size.width().value())) * 180 / AK::Pi<float>;
|
||||
return atan2(gradient_size.height().value(), gradient_size.width().value()) * 180 / AK::Pi<double>;
|
||||
};
|
||||
return m_properties.direction.visit(
|
||||
[&](SideOrCorner side_or_corner) {
|
||||
auto angle = [&] {
|
||||
switch (side_or_corner) {
|
||||
case SideOrCorner::Top:
|
||||
return 0.0f;
|
||||
return 0.0;
|
||||
case SideOrCorner::Bottom:
|
||||
return 180.0f;
|
||||
return 180.0;
|
||||
case SideOrCorner::Left:
|
||||
return 270.0f;
|
||||
return 270.0;
|
||||
case SideOrCorner::Right:
|
||||
return 90.0f;
|
||||
return 90.0;
|
||||
case SideOrCorner::TopRight:
|
||||
return corner_angle_degrees();
|
||||
case SideOrCorner::BottomLeft:
|
||||
return corner_angle_degrees() + 180.0f;
|
||||
return corner_angle_degrees() + 180.0;
|
||||
case SideOrCorner::TopLeft:
|
||||
return -corner_angle_degrees();
|
||||
case SideOrCorner::BottomRight:
|
||||
return -(corner_angle_degrees() + 180.0f);
|
||||
return -(corner_angle_degrees() + 180.0);
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}();
|
||||
// Note: For unknowable reasons the angles are opposite on the -webkit- version
|
||||
if (m_properties.gradient_type == GradientType::WebKit)
|
||||
return angle + 180.0f;
|
||||
return angle + 180.0;
|
||||
return angle;
|
||||
},
|
||||
[&](Angle const& angle) {
|
||||
|
|
|
@ -15,13 +15,13 @@ Time::Time(int value, Type type)
|
|||
{
|
||||
}
|
||||
|
||||
Time::Time(float value, Type type)
|
||||
Time::Time(double value, Type type)
|
||||
: m_type(type)
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
Time Time::make_seconds(float value)
|
||||
Time Time::make_seconds(double value)
|
||||
{
|
||||
return { value, Type::S };
|
||||
}
|
||||
|
@ -36,13 +36,13 @@ ErrorOr<String> Time::to_string() const
|
|||
return String::formatted("{}s", to_seconds());
|
||||
}
|
||||
|
||||
float Time::to_seconds() const
|
||||
double Time::to_seconds() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case Type::S:
|
||||
return m_value;
|
||||
case Type::Ms:
|
||||
return m_value / 1000.0f;
|
||||
return m_value / 1000.0;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
@ -51,9 +51,9 @@ double Time::to_milliseconds() const
|
|||
{
|
||||
switch (m_type) {
|
||||
case Type::S:
|
||||
return static_cast<double>(m_value) * 1000.0;
|
||||
return m_value * 1000.0;
|
||||
case Type::Ms:
|
||||
return static_cast<double>(m_value);
|
||||
return m_value;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
|
@ -21,16 +21,16 @@ public:
|
|||
static Optional<Type> unit_from_name(StringView);
|
||||
|
||||
Time(int value, Type type);
|
||||
Time(float value, Type type);
|
||||
static Time make_seconds(float);
|
||||
Time(double value, Type type);
|
||||
static Time make_seconds(double);
|
||||
Time percentage_of(Percentage const&) const;
|
||||
|
||||
ErrorOr<String> to_string() const;
|
||||
float to_seconds() const;
|
||||
double to_milliseconds() const;
|
||||
double to_seconds() const;
|
||||
|
||||
Type type() const { return m_type; }
|
||||
float raw_value() const { return m_value; }
|
||||
double raw_value() const { return m_value; }
|
||||
|
||||
bool operator==(Time const& other) const
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ private:
|
|||
StringView unit_name() const;
|
||||
|
||||
Type m_type;
|
||||
float m_value { 0 };
|
||||
double m_value { 0 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue