1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 02:07:35 +00:00

AK: Add to_radians and to_degrees math functions

This commit is contained in:
Bastiaan van der Plaat 2023-09-09 14:43:39 +02:00 committed by Sam Atkins
parent 9b7aa8f6b6
commit 494a8cb816
15 changed files with 40 additions and 40 deletions

View file

@ -39,7 +39,7 @@ double Angle::to_degrees() const
case Type::Grad:
return m_value * (360.0 / 400.0);
case Type::Rad:
return m_value * (180.0 / AK::Pi<double>);
return AK::to_degrees(m_value);
case Type::Turn:
return m_value * 360.0;
}
@ -48,7 +48,7 @@ double Angle::to_degrees() const
double Angle::to_radians() const
{
return to_degrees() * (AK::Pi<double> / 180.0);
return AK::to_radians(to_degrees());
}
StringView Angle::unit_name() const

View file

@ -66,7 +66,7 @@ bool LinearGradientStyleValue::equals(StyleValue const& other_) const
float LinearGradientStyleValue::angle_degrees(CSSPixelSize gradient_size) const
{
auto corner_angle_degrees = [&] {
return atan2(gradient_size.height().to_double(), gradient_size.width().to_double()) * 180 / AK::Pi<double>;
return AK::to_degrees(atan2(gradient_size.height().to_double(), gradient_size.width().to_double()));
};
return m_properties.direction.visit(
[&](SideOrCorner side_or_corner) {

View file

@ -313,7 +313,7 @@ JS::NonnullGCPtr<DOMMatrix> DOMMatrix::skew_x_self(double sx)
{
// 1. Post-multiply a skewX transformation on the current matrix by the specified angle sx in degrees. The 2D skewX matrix is described in CSS Transforms with alpha = sx in degrees. [CSS3-TRANSFORMS]
// clang-format off
Gfx::DoubleMatrix4x4 skew_matrix = { 1, tan(sx * M_PI / 180.0), 0, 0,
Gfx::DoubleMatrix4x4 skew_matrix = { 1, tan(AK::to_radians(sx)), 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
@ -330,7 +330,7 @@ JS::NonnullGCPtr<DOMMatrix> DOMMatrix::skew_y_self(double sy)
// 1. Post-multiply a skewX transformation on the current matrix by the specified angle sy in degrees. The 2D skewY matrix is described in CSS Transforms with beta = sy in degrees. [CSS3-TRANSFORMS]
// clang-format off
Gfx::DoubleMatrix4x4 skew_matrix = { 1, 0, 0, 0,
tan(sy * M_PI / 180.0), 1, 0, 0,
tan(AK::to_radians(sy)), 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
// clang-format on

View file

@ -74,9 +74,6 @@ Optional<Gfx::PaintStyle const&> SVGGraphicsElement::stroke_paint_style(SVGPaint
Gfx::AffineTransform transform_from_transform_list(ReadonlySpan<Transform> transform_list)
{
Gfx::AffineTransform affine_transform;
auto to_radians = [](float degrees) {
return degrees * (AK::Pi<float> / 180.0f);
};
for (auto& transform : transform_list) {
transform.operation.visit(
[&](Transform::Translate const& translate) {
@ -90,14 +87,14 @@ Gfx::AffineTransform transform_from_transform_list(ReadonlySpan<Transform> trans
affine_transform.multiply(
Gfx::AffineTransform {}
.translate({ rotate.x, rotate.y })
.rotate_radians(to_radians(rotate.a))
.rotate_radians(AK::to_radians(rotate.a))
.translate({ -rotate.x, -rotate.y }));
},
[&](Transform::SkewX const& skew_x) {
affine_transform.multiply(Gfx::AffineTransform {}.skew_radians(to_radians(skew_x.a), 0));
affine_transform.multiply(Gfx::AffineTransform {}.skew_radians(AK::to_radians(skew_x.a), 0));
},
[&](Transform::SkewY const& skew_y) {
affine_transform.multiply(Gfx::AffineTransform {}.skew_radians(0, to_radians(skew_y.a)));
affine_transform.multiply(Gfx::AffineTransform {}.skew_radians(0, AK::to_radians(skew_y.a)));
},
[&](Transform::Matrix const& matrix) {
affine_transform.multiply(Gfx::AffineTransform {