Truly independent web browser
Everywhere: Use ak::math over the float methods of Rust's std
Shannon Booth06d7b7cdb561
diff --git a/Libraries/LibCompositing/Rust/src/css_pixels.rs b/Libraries/LibCompositing/Rust/src/css_pixels.rsindex b5cfe475e3d..98cb7be396b 100644--- a/Libraries/LibCompositing/Rust/src/css_pixels.rs+++ b/Libraries/LibCompositing/Rust/src/css_pixels.rs@@ -4,6 +4,8 @@* SPDX-License-Identifier: BSD-2-Clause*/+use ak::math;+// CSSPixels fixed-point arithmetic, bit-exact with the C++ implementation in// PixelUnits.h: an i32 with 6 fractional bits. The parity test on the C++// side compares every operation against the original.@@ -196,7 +198,7 @@ impl CssPixels {// the fraction rebuilt from the ratio is used where it is closer to it.let scaled = |numerator: f64, denominator: f64| {let largest_term = numerator.abs().max(denominator.abs());- let scale = (FRACTION_TERM_MAGNITUDE / largest_term).log2().floor().exp2();+ let scale = math::exp2(math::log2(FRACTION_TERM_MAGNITUDE / largest_term).floor());Self::unscaled_fraction_nearest_values_for(numerator * scale, denominator * scale)};let error = |(numerator, denominator): (CssPixels, CssPixels)| {diff --git a/Libraries/LibCompositing/Rust/src/display_list/depth_sorted_plan.rs b/Libraries/LibCompositing/Rust/src/display_list/depth_sorted_plan.rsindex 7e0c9512db2..e3eaa69ddf2 100644--- a/Libraries/LibCompositing/Rust/src/display_list/depth_sorted_plan.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/depth_sorted_plan.rs@@ -442,6 +442,7 @@ pub fn build_depth_sorted_replay_plan(#[cfg(test)]mod tests {+ use ak::math;use libgfx_rust::{FloatMatrix4x4, IntRect, scale_matrix, translation_matrix};use super::*;@@ -500,8 +501,8 @@ mod tests {}fn rotate_y(radians: f32) -> FloatMatrix4x4 {- let cosine = radians.cos();- let sine = radians.sin();+ let cosine = math::cos(radians);+ let sine = math::sin(radians);FloatMatrix4x4 {elements: [[cosine, 0.0, sine, 0.0],diff --git a/Libraries/LibCompositing/Rust/src/display_list/replay.rs b/Libraries/LibCompositing/Rust/src/display_list/replay.rsindex ba80c26fe91..6aaaec8d994 100644--- a/Libraries/LibCompositing/Rust/src/display_list/replay.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/replay.rs@@ -957,6 +957,7 @@ mod tests {BackdropFilterData, BackfaceVisibilityData, ClipData, ClipMode, EffectsData, MaskData, MaskLayerOrigin,SpatialData, TransformData, TransformDataRole,};+ use ak::math;use libgfx_rust::{CompositingAndBlendingOperator, CornerRadii, FloatRect, MaskKind, scale_matrix, translation_matrix,};@@ -1217,7 +1218,7 @@ mod tests {}fn rotate_y(degrees: f32) -> FloatMatrix4x4 {- let (sin, cos) = degrees.to_radians().sin_cos();+ let (sin, cos) = math::sincos(degrees.to_radians());FloatMatrix4x4 {elements: [[cos, 0.0, sin, 0.0],diff --git a/Libraries/LibCompositing/Rust/src/force_dark.rs b/Libraries/LibCompositing/Rust/src/force_dark.rsindex 28c260df705..c7b558e537b 100644--- a/Libraries/LibCompositing/Rust/src/force_dark.rs+++ b/Libraries/LibCompositing/Rust/src/force_dark.rs@@ -7,6 +7,7 @@//! Force-dark: a paint-time color filter for pages that offer no dark theme of their own. A classifier decides//! whether a color inverts; a filter decides how. Chrome's decision logic, with the inversion in Oklab, not CIE-Lab.+use ak::math;use libgfx_rust::Color;use std::collections::{HashMap, HashSet};@@ -102,7 +103,7 @@ fn srgb_channel_to_linear(c: f32) -> f32 {if c <= 0.04045 {c / 12.92} else {- ((c + 0.055) / 1.055).powf(2.4)+ math::pow((c + 0.055) / 1.055, 2.4)}}@@ -110,7 +111,7 @@ fn linear_channel_to_srgb(c: f32) -> f32 {if c <= 0.0031308 {c * 12.92} else {- 1.055 * c.powf(1.0 / 2.4) - 0.055+ 1.055 * math::pow(c, 1.0 / 2.4) - 0.055}}@@ -119,9 +120,9 @@ pub fn srgb_to_oklab(r: f32, g: f32, b: f32) -> (f32, f32, f32) {let g = srgb_channel_to_linear(g);let b = srgb_channel_to_linear(b);- let l = (0.412_221_46 * r + 0.536_332_55 * g + 0.051_445_995 * b).cbrt();- let m = (0.211_903_5 * r + 0.680_699_5 * g + 0.107_396_96 * b).cbrt();- let s = (0.088_302_46 * r + 0.281_718_85 * g + 0.629_978_7 * b).cbrt();+ let l = math::cbrt(0.412_221_46 * r + 0.536_332_55 * g + 0.051_445_995 * b);+ let m = math::cbrt(0.211_903_5 * r + 0.680_699_5 * g + 0.107_396_96 * b);+ let s = math::cbrt(0.088_302_46 * r + 0.281_718_85 * g + 0.629_978_7 * b);(0.210_454_26 * l + 0.793_617_8 * m - 0.004_072_047 * s,diff --git a/Libraries/LibCompositing/Rust/src/visual_animation.rs b/Libraries/LibCompositing/Rust/src/visual_animation.rsindex 8495d448516..90b9ff462f7 100644--- a/Libraries/LibCompositing/Rust/src/visual_animation.rs+++ b/Libraries/LibCompositing/Rust/src/visual_animation.rs@@ -16,6 +16,7 @@ use crate::host::{FfiVisualAnimationFillMode, FfiVisualAnimationPlaybackDirection, FfiVisualAnimationTargetKind,FfiVisualAnimationTransformOperationKind,};+use ak::math;use libgfx_rust::filter::Filter;use libgfx_rust::{Color, ColorFilterType, FloatMatrix4x4, rotation_matrix, scale_matrix, translation_matrix};@@ -145,8 +146,8 @@ impl VisualAnimationTransformOperation {let first = self.value(0).unwrap_or(0.0);let skew = |x: f32, y: f32| FloatMatrix4x4 {elements: [- [1.0, x.tan(), 0.0, 0.0],- [y.tan(), 1.0, 0.0, 0.0],+ [1.0, math::tan(x), 0.0, 0.0],+ [math::tan(y), 1.0, 0.0, 0.0],[0.0, 0.0, 1.0, 0.0],[0.0, 0.0, 0.0, 1.0],],diff --git a/Libraries/LibCompositing/Rust/src/visual_context/queries.rs b/Libraries/LibCompositing/Rust/src/visual_context/queries.rsindex afb929023ce..af0c3db6bdf 100644--- a/Libraries/LibCompositing/Rust/src/visual_context/queries.rs+++ b/Libraries/LibCompositing/Rust/src/visual_context/queries.rs@@ -9,6 +9,7 @@ use super::{IncludeVisualViewportTransform, SpatialData, SpatialNodeIndex, TransformDataRole, VISUAL_VIEWPORT_NODE_INDEX,VisualContextTree, device_offset_for_index,};+use ak::math;use libgfx_rust::{CompositingAndBlendingOperator, FloatMatrix4x4, FloatPoint, FloatRect, IntPoint, IntRect, map_rect_through_matrix,};@@ -828,7 +829,7 @@ impl VisualContextTree {let origin = transform.origin;let dx = (rect.x - origin.x).abs().max((rect.right() - origin.x).abs());let dy = (rect.y - origin.y).abs().max((rect.bottom() - origin.y).abs());- let radius = dx.hypot(dy);+ let radius = math::hypot(dx, dy);rect = FloatRect::new(origin.x - radius, origin.y - radius, 2.0 * radius, 2.0 * radius);} else {let matrix = self.local_spatial_matrix(index, scroll_offsets).matrix;diff --git a/Libraries/LibGfx/Rust/src/color.rs b/Libraries/LibGfx/Rust/src/color.rsindex 2ff54214201..1887bc37e70 100644--- a/Libraries/LibGfx/Rust/src/color.rs+++ b/Libraries/LibGfx/Rust/src/color.rs@@ -4,6 +4,8 @@* SPDX-License-Identifier: BSD-2-Clause*/+use ak::math;+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]#[repr(transparent)]pub struct Color(pub u32);@@ -97,7 +99,7 @@ impl Color {if srgb_component <= 0.04045 {srgb_component / 12.92} else {- ((srgb_component + 0.055) / 1.055).powf(2.4)+ math::pow((srgb_component + 0.055) / 1.055, 2.4)}}0.2126 * linearized(self.red()) + 0.7152 * linearized(self.green()) + 0.0722 * linearized(self.blue())diff --git a/Libraries/LibGfx/Rust/src/matrix.rs b/Libraries/LibGfx/Rust/src/matrix.rsindex 26c4f1abf10..2373820394b 100644--- a/Libraries/LibGfx/Rust/src/matrix.rs+++ b/Libraries/LibGfx/Rust/src/matrix.rs@@ -5,6 +5,7 @@*/use crate::geometry::{FloatPoint, FloatRect};+use ak::math;#[derive(Clone, Copy, Debug, PartialEq)]#[repr(C)]@@ -78,11 +79,11 @@ impl AffineTransform {}pub fn x_scale(self) -> f32 {- self.a().hypot(self.b())+ math::hypot(self.a(), self.b())}pub fn y_scale(self) -> f32 {- self.c().hypot(self.d())+ math::hypot(self.c(), self.d())}pub fn translated(mut self, x: f32, y: f32) -> Self {@@ -164,11 +165,11 @@ macro_rules! matrix_element {}fn sin(self) -> Self {- <$type>::sin(self)+ math::sin(self)}fn cos(self) -> Self {- <$type>::cos(self)+ math::cos(self)}}};diff --git a/Libraries/LibGfx/Rust/src/path.rs b/Libraries/LibGfx/Rust/src/path.rsindex 1ca2d3affe1..172cc37ed19 100644--- a/Libraries/LibGfx/Rust/src/path.rs+++ b/Libraries/LibGfx/Rust/src/path.rs@@ -339,6 +339,7 @@ impl Eq for Path {}#[cfg(test)]mod tests {use super::*;+ use ak::math;fn point(x: f32, y: f32) -> FloatPoint {FloatPoint { x, y }@@ -491,8 +492,8 @@ mod tests {let vertices = circle.vertices();assert!(vertices.len() > 40);for vertex in &vertices {- assert_approximately(vertex.point.x.hypot(vertex.point.y), 10.0, 0.001);- assert_approximately(vertex.direction.x.hypot(vertex.direction.y), 1.0, 0.001);+ assert_approximately(math::hypot(vertex.point.x, vertex.point.y), 10.0, 0.001);+ assert_approximately(math::hypot(vertex.direction.x, vertex.direction.y), 1.0, 0.001);assert_approximately(vertex.direction.x * vertex.point.x + vertex.direction.y * vertex.point.y,0.0,@@ -504,7 +505,7 @@ mod tests {(pair[0].point.x + pair[1].point.x) / 2.0,(pair[0].point.y + pair[1].point.y) / 2.0,);- assert!(midpoint.x.hypot(midpoint.y) > 10.0 - 0.5 / 16.0);+ assert!(math::hypot(midpoint.x, midpoint.y) > 10.0 - 0.5 / 16.0);}assert_approximately(vertices.first().unwrap().point.x, 10.0, 0.000_000_5);assert_approximately(vertices.last().unwrap().point.x, 10.0, 0.000_000_5);diff --git a/Libraries/LibGfx/Rust/src/path/arcs.rs b/Libraries/LibGfx/Rust/src/path/arcs.rsindex 74093367f42..c5ce4251255 100644--- a/Libraries/LibGfx/Rust/src/path/arcs.rs+++ b/Libraries/LibGfx/Rust/src/path/arcs.rs@@ -16,6 +16,7 @@use super::geometry::PathGeometry;use crate::geometry::FloatPoint;+use ak::math;use std::f64::consts::PI;/// The largest angle of the ellipse that one conic covers.@@ -43,7 +44,7 @@ pub(super) fn append_elliptical_arc(return;}- let (sin_rotation, cos_rotation) = f64::from(x_axis_rotation).sin_cos();+ let (sin_rotation, cos_rotation) = math::sincos(f64::from(x_axis_rotation));let (start_x, start_y) = (f64::from(start.x), f64::from(start.y));let (end_x, end_y) = (f64::from(end.x), f64::from(end.y));@@ -86,9 +87,11 @@ pub(super) fn append_elliptical_arc((-start_in_frame_x - center_in_frame_x) / radius_x,(-start_in_frame_y - center_in_frame_y) / radius_y,);- let start_angle = start_on_circle.1.atan2(start_on_circle.0);- let mut sweep_angle = (start_on_circle.0 * end_on_circle.1 - start_on_circle.1 * end_on_circle.0)- .atan2(start_on_circle.0 * end_on_circle.0 + start_on_circle.1 * end_on_circle.1);+ let start_angle = math::atan2(start_on_circle.1, start_on_circle.0);+ let mut sweep_angle = math::atan2(+ start_on_circle.0 * end_on_circle.1 - start_on_circle.1 * end_on_circle.0,+ start_on_circle.0 * end_on_circle.0 + start_on_circle.1 * end_on_circle.1,+ );if !sweep && sweep_angle > 0.0 {sweep_angle -= 2.0 * PI;} else if sweep && sweep_angle < 0.0 {@@ -112,20 +115,20 @@ pub(super) fn append_elliptical_arc(.ceil().max(1.0) as usize;let angle_per_conic = sweep_angle / conic_count as f64;- let half_angle_cosine = (angle_per_conic / 2.0).cos();+ let half_angle_cosine = math::cos(angle_per_conic / 2.0);let weight = half_angle_cosine as f32;for index in 0..conic_count {let from_angle = start_angle + angle_per_conic * index as f64;let middle_angle = from_angle + angle_per_conic / 2.0;let to_angle = from_angle + angle_per_conic;let control = to_ellipse(- middle_angle.cos() / half_angle_cosine,- middle_angle.sin() / half_angle_cosine,+ math::cos(middle_angle) / half_angle_cosine,+ math::sin(middle_angle) / half_angle_cosine,);let conic_end = if index + 1 == conic_count {end} else {- to_ellipse(to_angle.cos(), to_angle.sin())+ to_ellipse(math::cos(to_angle), math::sin(to_angle))};geometry.contour_conic_to(control, conic_end, weight);}diff --git a/Libraries/LibGfx/Rust/src/path/curves.rs b/Libraries/LibGfx/Rust/src/path/curves.rsindex 98bfb144444..e2db04bef17 100644--- a/Libraries/LibGfx/Rust/src/path/curves.rs+++ b/Libraries/LibGfx/Rust/src/path/curves.rs@@ -8,6 +8,7 @@use super::geometry::Segment;use crate::geometry::FloatPoint;+use ak::math;#[derive(Clone, Copy, Debug, Default, PartialEq)]pub struct Point {@@ -44,7 +45,7 @@ impl Point {}pub fn length(self) -> f64 {- self.x.hypot(self.y)+ math::hypot(self.x, self.y)}pub fn distance_to(self, other: Self) -> f64 {diff --git a/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/context.rs b/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/context.rsindex 31e601ab05c..9bc90dbc498 100644--- a/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/context.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/context.rs@@ -13,6 +13,7 @@ use core::ops::Deref;use core::ptr::NonNull;use ak::Utf16String;+use ak::math;use libcompositing_rust::display_list::canvas_2d::{Compositing, Paint, Stroke};use libcompositing_rust::display_list::canvas_2d_recorder::{AlphaType, ColorSpace, Recorder};use libcompositing_rust::display_list::commands::{Canvas2DShadow, CanvasId};@@ -850,6 +851,6 @@ pub(crate) fn multiply_transforms(transform: AffineTransform, other: AffineTrans/// The transform rotated by the angle in radians, as Gfx::AffineTransform::rotate_radians().pub(crate) fn rotated(transform: AffineTransform, radians: f32) -> AffineTransform {- let (sin, cos) = radians.sin_cos();+ let (sin, cos) = math::sincos(radians);multiply_transforms(transform, AffineTransform::new(cos, sin, -sin, cos, 0.0, 0.0))}diff --git a/Libraries/LibWeb/Bindings/Rust/src/geometry/dom_matrix_read_only.rs b/Libraries/LibWeb/Bindings/Rust/src/geometry/dom_matrix_read_only.rsindex 59268c63e38..083a25c7b2e 100644--- a/Libraries/LibWeb/Bindings/Rust/src/geometry/dom_matrix_read_only.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/geometry/dom_matrix_read_only.rs@@ -9,6 +9,7 @@use core::cell::Cell;use ak::Utf16String;+use ak::math;use libjs_rust::api::{ArrayBuffer, ArrayBufferOrder, ArrayBufferShared, Gc, Trace, TypedArrayBase, TypedArrayKind,create_typed_array_on_buffer, is_typed_array_out_of_bounds, make_typed_array_with_buffer_witness_record,@@ -877,7 +878,7 @@ impl DOMMatrixReadOnly {// angle between the vector (1,0)T and (x,y)T in the clockwise direction. If x and y should both be 0 or -0,// the angle is specified as 0. The 2D rotation matrix is described in CSS Transforms where alpha is the// angle between the vector (1,0)T and (x,y)T in degrees. [CSS3-TRANSFORMS]- let angle = if x == 0.0 && y == 0.0 { 0.0 } else { y.atan2(x) };+ let angle = if x == 0.0 && y == 0.0 { 0.0 } else { math::atan2(y, x) };self.matrix.set(self.matrix.get().multiplied(Matrix4::rotation([0.0, 0.0, 1.0], angle)));}@@ -908,7 +909,7 @@ impl DOMMatrixReadOnly {// 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]let mut skew = Matrix4::identity();- skew.set_element(2, 1, to_radians(sx).tan());+ skew.set_element(2, 1, math::tan(to_radians(sx)));self.matrix.set(self.matrix.get().multiplied(skew));}@@ -917,7 +918,7 @@ impl DOMMatrixReadOnly {// 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]let mut skew = Matrix4::identity();- skew.set_element(1, 2, to_radians(sy).tan());+ skew.set_element(1, 2, math::tan(to_radians(sy)));self.matrix.set(self.matrix.get().multiplied(skew));}diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_path.rs b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_path.rsindex 596643677d3..4fe07cfdf68 100644--- a/Libraries/LibWeb/Bindings/Rust/src/html/canvas_path.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/html/canvas_path.rs@@ -11,6 +11,7 @@//! quadraticCurveTo(), arc() and ellipse() are floats, and those of the rest are doubles that become floats where//! they become points.+use ak::math;use libgfx_rust::{FloatPoint, FloatSize};use crate::ak_format::ak_formatted;@@ -360,7 +361,7 @@ pub(crate) fn ellipse(// positions is just whether our angle is on one of the left quadrants.// NB: The C++ took the sine and the cosine of the rotation with the x87 instruction, in extended precision. Taken// in double precision, they round to the same floats but in rare cases.- let (sin_rotation, cos_rotation) = f64::from(rotation).sin_cos();+ let (sin_rotation, cos_rotation) = math::sincos(f64::from(rotation));#[allow(clippy::cast_possible_truncation,reason = "the C++ kept the sine and the cosine in floats"@@ -368,7 +369,7 @@ pub(crate) fn ellipse(let (sin_rotation, cos_rotation) = (sin_rotation as f32, cos_rotation as f32);let resolve_point_with_angle = |angle: f32| {- let tan_relative = angle.tan();+ let tan_relative = math::tan(angle);let tan2 = tan_relative * tan_relative;let ab = radius_x * radius_y;@@ -382,7 +383,7 @@ pub(crate) fn ellipse(// Make sure to set the correct sign// -1 if 0 ≤ θ < 90° or 270°< θ ≤ 360°// 1 if 90° < θ< 270°- let sn = if angle.cos() >= 0.0 { 1.0 } else { -1.0 };+ let sn = if math::cos(angle) >= 0.0 { 1.0 } else { -1.0 };relative_x_position *= sn;relative_y_position *= sn;@@ -497,7 +498,7 @@ pub(crate) fn arc_to(// (x1, y1), and that has a different point tangent to the half-infinite line that ends at the point (x1, y1)// and crosses the point (x2, y2). The points at which this circle touches these two lines are called the start// and end tangent points respectively.- let adjacent = radius / f64::from((cos_theta.acos() / 2.0).tan());+ let adjacent = radius / f64::from(math::tan(math::acos(cos_theta) / 2.0));let factor1 = adjacent / f64::from(length(v1));let x3 = f64::from(p1.x) + factor1 * f64::from(p0.x - p1.x);let y3 = f64::from(p1.y) + factor1 * f64::from(p0.y - p1.y);diff --git a/Libraries/LibWeb/Rust/src/css/animation.rs b/Libraries/LibWeb/Rust/src/css/animation.rsindex ccfbadff3be..d8d7d7cd349 100644--- a/Libraries/LibWeb/Rust/src/css/animation.rs+++ b/Libraries/LibWeb/Rust/src/css/animation.rs@@ -16,6 +16,7 @@ use crate::css::style_value::{ShadowPayload, StyleValueBox, TransformationPayload, UnresolvedPayload,};use crate::css::style_value_arc::StyleValueArc;+use ak::math;use std::collections::BTreeMap;use std::sync::Arc;@@ -879,10 +880,10 @@ fn normalized_super_ellipse_half_corner(s: f64) -> f64 {// Otherwise// 1. Let k be 0.5^abs(s).- let k = 0.5_f64.powf(s.abs());+ let k = math::pow(0.5_f64, s.abs());// 2. Let convexHalfCorner be 0.5^k.- let convex_half_corner = 0.5_f64.powf(k);+ let convex_half_corner = math::pow(0.5_f64, k);// 3. If s is less than 0, return 1 - convexHalfCorner.if s < 0.0 {@@ -921,10 +922,10 @@ fn interpolation_value_to_super_ellipse_parameter(interpolation_value: f64) -> f}// 3. Let k be ln(0.5) / ln(convexHalfCorner).- let k = 0.5_f64.ln() / convex_half_corner.ln();+ let k = math::log(0.5_f64) / math::log(convex_half_corner);// 4. Let s be log2(k).- let mut s = k.log2();+ let mut s = math::log2(k);// AD-HOC: The logs above can introduce slight inaccuracies, this can interfere with the behaviour of// serializing superellipse style values as their equivalent keywords as that relies on exact@@ -3554,12 +3555,12 @@ fn composite_rotate_impl(underlying: &StyleValueData, animated: &StyleValueData)let to_quaternion = |axis: [f64; 3], angle_degrees: f64| {let length = axis.iter().map(|component| component * component).sum::<f64>().sqrt();let half_angle = angle_degrees.to_radians() / 2.0;- let sin_half_angle = half_angle.sin();+ let sin_half_angle = math::sin(half_angle);[axis[0] / length * sin_half_angle,axis[1] / length * sin_half_angle,axis[2] / length * sin_half_angle,- half_angle.cos(),+ math::cos(half_angle),]};let [x1, y1, z1, w1] = to_quaternion(@@ -3584,7 +3585,7 @@ fn composite_rotate_impl(underlying: &StyleValueData, animated: &StyleValueData)if product[3] < 0.0 {product = product.map(|component| -component);}- let angle = 2.0 * product[3].clamp(-1.0, 1.0).acos();+ let angle = 2.0 * math::acos(product[3].clamp(-1.0, 1.0));let sin_half_angle = (1.0 - product[3] * product[3]).max(0.0).sqrt();let axis = if sin_half_angle < 1e-5 {[0.0, 0.0, 1.0]@@ -5109,15 +5110,14 @@ fn interpolate_scalar_value(// become approximately 0.176), then interpolating those values. The result during the interpolation is// converted back to a <ratio> by inverting the logarithm, then interpreting the result as a <ratio> with the// result as the first value and 1 as the second value.- let from_number = (from_numerator / from_denominator).ln();- let to_number = (to_numerator / to_denominator).ln();- let value = interpolate_f64(+ let from_number = math::log(from_numerator / from_denominator);+ let to_number = math::log(to_numerator / to_denominator);+ let value = math::exp(interpolate_f64(from_number,to_number,delta,accepted_range(property_id, VALUE_TYPE_RATIO, range_overrides),- )- .exp();+ ));owned(StyleValueData::Ratio(StyleValueBox::new(RatioPayload {numerator: RetainedStyleValueData::from_arc(StyleValueArc::new(StyleValueData::Number { value })),denominator: RetainedStyleValueData::from_arc(StyleValueArc::new(StyleValueData::Number {@@ -5249,12 +5249,12 @@ fn interpolate_rotate_3d_with_phases(} else {let to_quaternion = |axis: [f64; 3], angle: f64| {let half_angle = angle / 2.0;- let sin_half_angle = half_angle.sin();+ let sin_half_angle = math::sin(half_angle);[axis[0] * sin_half_angle,axis[1] * sin_half_angle,axis[2] * sin_half_angle,- half_angle.cos(),+ math::cos(half_angle),]};let (from_phase, to_phase) = phases.unwrap_or((from_angle.to_radians(), to_angle.to_radians()));@@ -5280,9 +5280,9 @@ fn interpolate_rotate_3d_with_phases(let interpolated_quaternion = if product.abs() >= 1.0 {from_quaternion} else {- let theta = product.acos();- let weight = (f64::from(delta) * theta).sin() / (1.0 - product * product).sqrt();- let from_multiplier = (f64::from(delta) * theta).cos() - product * weight;+ let theta = math::acos(product);+ let weight = math::sin(f64::from(delta) * theta) / (1.0 - product * product).sqrt();+ let from_multiplier = math::cos(f64::from(delta) * theta) - product * weight;if weight.abs() < f64::from(f32::EPSILON) {from_quaternion.map(|component| component * from_multiplier)} else if from_multiplier.abs() < f64::from(f32::EPSILON) {@@ -5300,7 +5300,7 @@ fn interpolate_rotate_3d_with_phases(let sin_half_angle = (1.0 - interpolated_quaternion[3] * interpolated_quaternion[3]).max(0.0).sqrt();- let angle = 2.0 * interpolated_quaternion[3].clamp(-1.0, 1.0).acos();+ let angle = 2.0 * math::acos(interpolated_quaternion[3].clamp(-1.0, 1.0));if sin_half_angle >= epsilon {axis = axis.map(|component| component / sin_half_angle);} else {@@ -5882,9 +5882,9 @@ fn slerp_quaternions(from: [f64; 4], to: [f64; 4], delta: f32) -> [f64; 4] {if product.abs() >= 1.0 {return from;}- let theta = product.acos();- let weight = (f64::from(delta) * theta).sin() / (1.0 - product * product).sqrt();- let from_multiplier = (f64::from(delta) * theta).cos() - product * weight;+ let theta = math::acos(product);+ let weight = math::sin(f64::from(delta) * theta) / (1.0 - product * product).sqrt();+ let from_multiplier = math::cos(f64::from(delta) * theta) - product * weight;if weight.abs() < f64::from(f32::EPSILON) {return from.map(|component| component * from_multiplier);}@@ -5961,8 +5961,8 @@ fn transformation_to_matrix(return identity_matrix();}let [x, y, z] = axis.map(|component| component / axis_length);- let cosine = angle.cos();- let sine = angle.sin();+ let cosine = math::cos(angle);+ let sine = math::sin(angle);let one_minus_cosine = 1.0 - cosine;[[@@ -6051,18 +6051,18 @@ fn transformation_to_matrix(}(TRANSFORM_FUNCTION_SKEW | TRANSFORM_FUNCTION_SKEW_X, [x]) => {let mut matrix = identity_matrix();- matrix[0][1] = angle(x)?.tan();+ matrix[0][1] = math::tan(angle(x)?);Some(matrix)}(TRANSFORM_FUNCTION_SKEW, [x, y]) => {let mut matrix = identity_matrix();- matrix[0][1] = angle(x)?.tan();- matrix[1][0] = angle(y)?.tan();+ matrix[0][1] = math::tan(angle(x)?);+ matrix[1][0] = math::tan(angle(y)?);Some(matrix)}(TRANSFORM_FUNCTION_SKEW_Y, [y]) => {let mut matrix = identity_matrix();- matrix[1][0] = angle(y)?.tan();+ matrix[1][0] = math::tan(angle(y)?);Some(matrix)}_ => None,@@ -6460,12 +6460,12 @@ fn rotation_quaternion(axis: [f64; 3], angle: f64) -> Option<[f64; 4]> {if length < 1e-5 {return (angle == 0.0).then_some([0.0, 0.0, 0.0, 1.0]);}- let sin_half_angle = (angle / 2.0).sin();+ let sin_half_angle = math::sin(angle / 2.0);Some([axis[0] / length * sin_half_angle,axis[1] / length * sin_half_angle,axis[2] / length * sin_half_angle,- (angle / 2.0).cos(),+ math::cos(angle / 2.0),])}@@ -6531,7 +6531,7 @@ fn accumulate_rotate_3d(if sin_half_angle < 1e-9 {return Some(rotation([0.0, 0.0, 1.0], 0.0));}- let angle = 2.0 * sin_half_angle.atan2(quaternion[3]);+ let angle = 2.0 * math::atan2(sin_half_angle, quaternion[3]);Some(rotation(axis.map(|component| component / sin_half_angle),angle.to_degrees(),diff --git a/Libraries/LibWeb/Rust/src/css/calc.rs b/Libraries/LibWeb/Rust/src/css/calc.rsindex 474f21edead..89c557069b8 100644--- a/Libraries/LibWeb/Rust/src/css/calc.rs+++ b/Libraries/LibWeb/Rust/src/css/calc.rs@@ -18,6 +18,7 @@ use crate::css::style_value::{AnchorPayload, AnchorSizePayload, CalculatedPayload, RandomValueSharingPayload, StyleValueBox,};use crate::css::style_value_arc::StyleValueArc;+use ak::math;use std::sync::Arc;use crate::css::style_value::{RetainedStyleValueData, StyleValueData};@@ -1594,9 +1595,9 @@ impl CalcNode {_ => unreachable!("trigonometric argument must be a number or an angle"),};let result = match self {- CalcNode::Sin(..) => radians.sin(),- CalcNode::Cos(..) => radians.cos(),- _ => radians.tan(),+ CalcNode::Sin(..) => math::sin(radians),+ CalcNode::Cos(..) => math::cos(radians),+ _ => math::tan(radians),};Some(CalcResult {value: result,@@ -1617,9 +1618,9 @@ impl CalcNode {degrees};let result = match self {- CalcNode::Asin(..) => normalize_angle(number.asin(), -90.0, 90.0),- CalcNode::Acos(..) => normalize_angle(number.acos(), 0.0, 180.0),- _ => normalize_angle(number.atan(), -90.0, 90.0),+ CalcNode::Asin(..) => normalize_angle(math::asin(number), -90.0, 90.0),+ CalcNode::Acos(..) => normalize_angle(math::acos(number), 0.0, 180.0),+ _ => normalize_angle(math::atan(number), -90.0, 90.0),};let mut angle_type = CalcNumericType::default();angle_type.exponents[1] = Some(1);@@ -1633,7 +1634,7 @@ impl CalcNode {let y_value = y.try_canonical_result(context)?;let x_value = x.try_canonical_result(context)?;let input_consistent_type = y_value.numeric_type?.added_to(&x_value.numeric_type?)?;- let mut degrees = y_value.value.atan2(x_value.value).to_degrees();+ let mut degrees = math::atan2(y_value.value, x_value.value).to_degrees();while degrees <= -180.0 {degrees += 360.0;}@@ -1655,7 +1656,7 @@ impl CalcNode {.numeric_type(leaf_type)?.added_to(&exponent.numeric_type(leaf_type)?)?;Some(CalcResult {- value: a.powf(b),+ value: math::pow(a, b),numeric_type: Some(consistent_type),})}@@ -1672,7 +1673,7 @@ impl CalcNode {let number = value.try_number()?;let base_number = base.try_number()?;Some(CalcResult {- value: number.ln() / base_number.ln(),+ value: math::log(number) / math::log(base_number),numeric_type: CalcNumericType::default().made_consistent_with(&value.numeric_type(leaf_type)?),})}@@ -1680,7 +1681,7 @@ impl CalcNode {CalcNode::Exp(child) => {let number = child.try_number()?;Some(CalcResult {- value: number.exp(),+ value: math::exp(number),numeric_type: CalcNumericType::default().made_consistent_with(&child.numeric_type(leaf_type)?),})}diff --git a/Libraries/LibWeb/Rust/src/css/color_conversion.rs b/Libraries/LibWeb/Rust/src/css/color_conversion.rsindex 65bc709d6c6..f0357b97849 100644--- a/Libraries/LibWeb/Rust/src/css/color_conversion.rs+++ b/Libraries/LibWeb/Rust/src/css/color_conversion.rs@@ -6,6 +6,8 @@//! Color-space conversions used by CSS color interpolation.+use ak::math;+pub(crate) type Components = [f32; 4];// Colors are converted in double precision with the full-precision matrices of CSS Color 4's sample code, since the hue@@ -163,7 +165,7 @@ fn srgb_to_linear_srgb(srgb: Color) -> Color {if absolute <= 0.04045 {component / 12.92} else {- component.signum() * ((absolute + 0.055) / 1.055).powf(2.4)+ component.signum() * math::pow((absolute + 0.055) / 1.055, 2.4)}})}@@ -174,7 +176,7 @@ fn linear_srgb_to_srgb(linear: Color) -> Color {map_rgb(linear, |component| {let absolute = component.abs();if absolute > 0.0031308 {- component.signum() * (1.055 * absolute.powf(1.0 / 2.4) - 0.055)+ component.signum() * (1.055 * math::pow(absolute, 1.0 / 2.4) - 0.055)} else {12.92 * component}@@ -185,13 +187,13 @@ fn linear_srgb_to_srgb(linear: Color) -> Color {// https://drafts.csswg.org/css-color-4/#color-conversion-codefn a98_rgb_to_linear_a98_rgb(color: Color) -> Color {map_rgb(color, |component| {- component.signum() * component.abs().powf(563.0 / 256.0)+ component.signum() * math::pow(component.abs(), 563.0 / 256.0)})}fn linear_a98_rgb_to_a98_rgb(color: Color) -> Color {map_rgb(color, |component| {- component.signum() * component.abs().powf(256.0 / 563.0)+ component.signum() * math::pow(component.abs(), 256.0 / 563.0)})}@@ -203,7 +205,7 @@ fn prophoto_rgb_to_linear_prophoto_rgb(color: Color) -> Color {if absolute <= 16.0 / 512.0 {component / 16.0} else {- component.signum() * absolute.powf(1.8)+ component.signum() * math::pow(absolute, 1.8)}})}@@ -214,7 +216,7 @@ fn linear_prophoto_rgb_to_prophoto_rgb(color: Color) -> Color {if absolute <= 1.0 / 512.0 {component * 16.0} else {- component.signum() * absolute.powf(1.0 / 1.8)+ component.signum() * math::pow(absolute, 1.0 / 1.8)}})}@@ -226,7 +228,7 @@ fn rec2020_to_linear_rec2020(color: Color) -> Color {if absolute < REC2020_BETA * 4.5 {component / 4.5} else {- component.signum() * ((absolute + REC2020_ALPHA - 1.0) / REC2020_ALPHA).powf(1.0 / 0.45)+ component.signum() * math::pow((absolute + REC2020_ALPHA - 1.0) / REC2020_ALPHA, 1.0 / 0.45)}})}@@ -237,7 +239,7 @@ fn linear_rec2020_to_rec2020(color: Color) -> Color {if absolute < REC2020_BETA {4.5 * component} else {- component.signum() * (REC2020_ALPHA * absolute.powf(0.45) - (REC2020_ALPHA - 1.0))+ component.signum() * (REC2020_ALPHA * math::pow(absolute, 0.45) - (REC2020_ALPHA - 1.0))}})}@@ -269,7 +271,7 @@ fn xyz50_to_lab(color: Color) -> Color {let [x, y, z, alpha] = color;let convert = |value: f64| {if value > LAB_EPSILON {- value.cbrt()+ math::cbrt(value)} else {(LAB_KAPPA * value + 16.0) / 116.0}@@ -289,17 +291,25 @@ fn oklab_to_xyz65(color: Color) -> Color {// https://drafts.csswg.org/css-color-4/#color-conversion-codefn xyz65_to_oklab(color: Color) -> Color {let [long, medium, short, alpha] = multiply(&XYZ65_TO_LMS, color);- multiply(&LMS_TO_OKLAB, [long.cbrt(), medium.cbrt(), short.cbrt(), alpha])+ multiply(+ &LMS_TO_OKLAB,+ [math::cbrt(long), math::cbrt(medium), math::cbrt(short), alpha],+ )}fn polar_to_rectangular(color: Color) -> Color {let radians = color[2].to_radians();- [color[0], color[1] * radians.cos(), color[1] * radians.sin(), color[3]]+ [+ color[0],+ color[1] * math::cos(radians),+ color[1] * math::sin(radians),+ color[3],+ ]}fn rectangular_to_polar(color: Color) -> Color {- let chroma = color[1].hypot(color[2]);- let mut hue = color[2].atan2(color[1]).to_degrees();+ let chroma = math::hypot(color[1], color[2]);+ let mut hue = math::atan2(color[2], color[1]).to_degrees();if hue < 0.0 {hue += 360.0;}diff --git a/Libraries/LibWeb/Rust/src/css/color_resolution.rs b/Libraries/LibWeb/Rust/src/css/color_resolution.rsindex cf10a76a2d1..cccda0e99c7 100644--- a/Libraries/LibWeb/Rust/src/css/color_resolution.rs+++ b/Libraries/LibWeb/Rust/src/css/color_resolution.rs@@ -15,6 +15,7 @@ use crate::css::style_value::{CalculatedPayload, ColorFunctionPayload, ColorMixPayload, LightDarkPayload, StyleValueBox,};use crate::css::style_value_arc::StyleValueArc;+use ak::math;use crate::css::calc::{ANGLE_UNIT_CANONICAL_RATIOS, ResolveAs, resolve_as_from_fields, resolve_calculated_angle_with_channels,@@ -249,7 +250,7 @@ impl Rgba {if srgb <= 0.04045 {srgb / 12.92} else {- ((srgb + 0.055) / 1.055).powf(2.4)+ math::pow((srgb + 0.055) / 1.055, 2.4)}}0.2126 * linearize(self.r) + 0.7152 * linearize(self.g) + 0.0722 * linearize(self.b)@@ -984,8 +985,8 @@ fn construct_color(color_type: u8, c1: f64, c2: f64, c3: f64, alpha: f64) -> Optlet hue_radians = c3.to_radians();Rgba::from_lab(l as f32,- (c2 * hue_radians.cos()) as f32,- (c2 * hue_radians.sin()) as f32,+ (c2 * math::cos(hue_radians)) as f32,+ (c2 * math::sin(hue_radians)) as f32,alpha as f32,)}@@ -996,8 +997,8 @@ fn construct_color(color_type: u8, c1: f64, c2: f64, c3: f64, alpha: f64) -> Optlet hue_radians = c3.to_radians();Rgba::from_oklab(l as f32,- (chroma * hue_radians.cos()) as f32,- (chroma * hue_radians.sin()) as f32,+ (chroma * math::cos(hue_radians)) as f32,+ (chroma * math::sin(hue_radians)) as f32,alpha as f32,)}diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rsindex d9f6aead9b1..98130af05da 100644--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs@@ -28,6 +28,7 @@ use crate::css::style_value::{ShorthandPayload, UrlPayload,};use crate::css::style_value_arc::StyleValueArc;+use ak::math;use smallvec::SmallVec;use std::ffi::c_void;use std::sync::OnceLock;@@ -783,7 +784,7 @@ fn compute_font_size(// - Otherwise if B = 1 then multiply S by scriptPercentScaleDown and// decrement E by 1.// 5. Multiply S by C^E.- scale *= size_ratio.powf(e);+ scale *= math::pow(size_ratio, e);// 6. Return S if InvertScaleFactor is false and 1/S otherwise.if !invert_scale_factor { scale } else { 1.0 / scale }};diff --git a/Libraries/LibWeb/Rust/src/css/table_group_builder.rs b/Libraries/LibWeb/Rust/src/css/table_group_builder.rsindex edd733a2ab5..d7dcb823cee 100644--- a/Libraries/LibWeb/Rust/src/css/table_group_builder.rs+++ b/Libraries/LibWeb/Rust/src/css/table_group_builder.rs@@ -21,6 +21,7 @@ use crate::css::style_value::{GridTrackSizeListPayload, PositionPayload, RatioPayload, RectPayload, ScrollbarColorPayload, ShadowPayload,TransformationPayload,};+use ak::math;use std::collections::HashMap;use std::ffi::c_void;@@ -1193,26 +1194,26 @@ pub(crate) fn transformation_to_matrix(functions::SKEW => {if count == 1 {let mut matrix = matrix_identity();- matrix[1] = get_value(0).tan();+ matrix[1] = math::tan(get_value(0));return matrix;}if count == 2 {let mut matrix = matrix_identity();- matrix[1] = get_value(0).tan();- matrix[4] = get_value(1).tan();+ matrix[1] = math::tan(get_value(0));+ matrix[4] = math::tan(get_value(1));return matrix;}}functions::SKEW_X => {if count == 1 {let mut matrix = matrix_identity();- matrix[1] = get_value(0).tan();+ matrix[1] = math::tan(get_value(0));return matrix;}}functions::SKEW_Y if count == 1 => {let mut matrix = matrix_identity();- matrix[4] = get_value(0).tan();+ matrix[4] = math::tan(get_value(0));return matrix;}_ => {}diff --git a/Libraries/LibWeb/Rust/src/painting/corner_shape.rs b/Libraries/LibWeb/Rust/src/painting/corner_shape.rsindex 37fc952055a..dc05a07776c 100644--- a/Libraries/LibWeb/Rust/src/painting/corner_shape.rs+++ b/Libraries/LibWeb/Rust/src/painting/corner_shape.rs@@ -9,6 +9,7 @@//! https://drafts.csswg.org/css-borders-4/#corner-shape-renderinguse crate::css::computed_value_views::ComputedValuesView;+use ak::math;use libgfx_rust::path::Path;use libgfx_rust::{CornerRadii, CornerRadius, FloatPoint, FloatRect};@@ -94,7 +95,7 @@ impl Vector {}fn normalized(self) -> Vector {- let length = self.x.hypot(self.y);+ let length = math::hypot(self.x, self.y);if length == 0.0 {return self;}@@ -131,8 +132,8 @@ fn normalized_superellipse_half_corner(k: f64) -> f64 {if k == f64::INFINITY {return 1.0;}- let n = 2f64.powf(k.abs());- let convex_half_corner = 0.5f64.powf(1.0 / n);+ let n = math::pow(2f64, k.abs());+ let convex_half_corner = math::pow(0.5f64, 1.0 / n);if k < 0.0 {1.0 - convex_half_corner} else {@@ -371,7 +372,7 @@ fn border_aligned_corner_clip_out_path(inputs: CornerInputs) -> Option<Vec<Point// 37. Otherwise, if K is greater than zero or less than or equal to -1:else if k > 0.0 || k <= -1.0 {// 1. Let n be 2^abs(K).- let n = 2f64.powf(k.abs());+ let n = math::pow(2f64, k.abs());// 2. Let curveCenter be adjustedCornerOuter if K is less than zero, adjustedCornerCenter otherwise.let curve_center = if k < 0.0 {adjusted_corner_outer@@ -384,8 +385,8 @@ fn border_aligned_corner_clip_out_path(inputs: CornerInputs) -> Option<Vec<Pointfor step in 0..=SEGMENTS_PER_CURVED_CORNER {let t = f64::from(step) / f64::from(SEGMENTS_PER_CURVED_CORNER);path.push(map_point_to_corner(- t.powf(1.0 / n),- (1.0 - t).powf(1.0 / n),+ math::pow(t, 1.0 / n),+ math::pow(1.0 - t, 1.0 / n),adjusted_corner_start,adjusted_corner_end,curve_center,diff --git a/Libraries/LibWeb/Rust/src/painting/record/paint/gradient_resolution.rs b/Libraries/LibWeb/Rust/src/painting/record/paint/gradient_resolution.rsindex fdfe00fbeee..2c399418edb 100644--- a/Libraries/LibWeb/Rust/src/painting/record/paint/gradient_resolution.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/paint/gradient_resolution.rs@@ -6,6 +6,7 @@use crate::css::style_value::{ConicGradientPayload, LinearGradientPayload, RadialGradientPayload};use crate::painting::record::trace::Observer;+use ak::math;use crate::css::color_resolution::{ColorResolutionInput, to_color};use crate::css::computed_value_views::ComputedValuesView;@@ -115,11 +116,11 @@ fn ak_pow_f32(x: f32, y: f32) -> f32 {}return result;}- ((y * ak_log2_f32(x)) as f64).exp2() as f32+ math::exp2((y * ak_log2_f32(x)) as f64) as f32}fn ak_log_f32(x: f32) -> f32 {- (x as f64).ln() as f32+ math::log(x as f64) as f32}fn color_stop_step(previous_stop: &GradientStop, next_stop: &GradientStop, position: f32) -> f32 {@@ -666,8 +667,10 @@ fn linear_gradient_angle_degrees(angle as f32}} else {- let corner_angle_degrees =- || gradient_size.height.to_double().atan2(gradient_size.width.to_double()) * 180.0 / std::f64::consts::PI;+ let corner_angle_degrees = || {+ math::atan2(gradient_size.height.to_double(), gradient_size.width.to_double()) * 180.0+ / std::f64::consts::PI+ };let angle = match SideOrCorner::from_computed_value(side_or_corner) {SideOrCorner::Top => 0.0,SideOrCorner::Bottom => 180.0,@@ -690,8 +693,8 @@ fn linear_gradient_angle_degrees(fn calculate_gradient_length(gradient_size: CssPixelSize, gradient_angle: f32) -> f32 {let real_angle = 90.0 - gradient_angle;let radians = real_angle * std::f32::consts::PI / 180.0;- let sin_angle = (radians as f64).sin() as f32;- let cos_angle = (radians as f64).cos() as f32;+ let sin_angle = math::sin(radians as f64) as f32;+ let cos_angle = math::cos(radians as f64) as f32;(gradient_size.height.to_float() * sin_angle).abs() + (gradient_size.width.to_float() * cos_angle).abs()}diff --git a/Libraries/LibWeb/Rust/src/painting/visual_context/offset_transform.rs b/Libraries/LibWeb/Rust/src/painting/visual_context/offset_transform.rsindex a20fdf9238d..6438fb511b5 100644--- a/Libraries/LibWeb/Rust/src/painting/visual_context/offset_transform.rs+++ b/Libraries/LibWeb/Rust/src/painting/visual_context/offset_transform.rs@@ -17,6 +17,7 @@ use crate::css::style_value::{BorderRadiusPayload, BorderRadiusRectPayload, Posiuse crate::layout::node_data::NodeSlotId;use crate::painting::paint_read::PaintRead;use crate::painting::style_queries;+use ak::math;use libgfx_rust::{FloatMatrix4x4, FloatPoint, rotation_matrix, translation_matrix};use super::basic_shapes::{basic_shape_kind, position_resolved};@@ -111,7 +112,7 @@ fn ray_length(size: u16, origin: (f64, f64), rect: CssPixelRect, angle_degrees:let (x, y) = origin;let side_distances = [(x - left).abs(), (right - x).abs(), (y - top).abs(), (bottom - y).abs()];let corner_distances = [(left, top), (right, top), (right, bottom), (left, bottom)]- .map(|(corner_x, corner_y)| (corner_x - x).hypot(corner_y - y));+ .map(|(corner_x, corner_y)| math::hypot(corner_x - x, corner_y - y));match size {// The distance from the ray's starting point to whichever side of the containing block is closest.keyword::CLOSEST_SIDE => side_distances.into_iter().fold(f64::INFINITY, f64::min),@@ -132,7 +133,7 @@ fn ray_length(size: u16, origin: (f64, f64), rect: CssPixelRect, angle_degrees:return 0.0;}let radians = angle_degrees.to_radians();- let (dx, dy) = (radians.sin(), -radians.cos());+ let (dx, dy) = (math::sin(radians), -math::cos(radians));let along = |delta: f64, low: f64, high: f64, position: f64| {if delta > 1e-9 {(high - position) / delta@@ -239,7 +240,10 @@ pub(crate) fn compute_offset_transform((length,Box::new(move |distance| PathPosition {- point: (origin.0 + distance * radians.sin(), origin.1 - distance * radians.cos()),+ point: (+ origin.0 + distance * math::sin(radians),+ origin.1 - distance * math::cos(radians),+ ),// NB: Bearing angles point up at 0deg, while the path direction is measured from the positive// X axis.direction: angle - 90.0,@@ -315,7 +319,7 @@ pub(crate) fn compute_offset_transform(let direction = if tangent_x == 0.0 && tangent_y == 0.0 {0.0} else {- f64::from(tangent_y).atan2(f64::from(tangent_x)).to_degrees()+ math::atan2(f64::from(tangent_y), f64::from(tangent_x)).to_degrees()};PathPosition {point: (offset.0 + f64::from(x), offset.1 + f64::from(y)),diff --git a/clippy.toml b/clippy.tomlindex 276ae37f31f..9dc5bfa7dfd 100644--- a/clippy.toml+++ b/clippy.toml@@ -1,4 +1,54 @@disallowed-methods = [{ path = "std::slice::from_raw_parts", reason = "a null pointer is undefined behavior even for an empty slice, and an empty AK container lends one: use ak::slice_from_raw_parts" },{ path = "std::slice::from_raw_parts_mut", reason = "a null pointer is undefined behavior even for an empty slice, and an empty AK container lends one: use ak::slice_from_raw_parts_mut" },+ { path = "f32::acos", reason = "the C library of each platform computes this differently: use ak::math::acos" },+ { path = "f32::asin", reason = "the C library of each platform computes this differently: use ak::math::asin" },+ { path = "f32::atan", reason = "the C library of each platform computes this differently: use ak::math::atan" },+ { path = "f32::atan2", reason = "the C library of each platform computes this differently: use ak::math::atan2" },+ { path = "f32::cbrt", reason = "the C library of each platform computes this differently: use ak::math::cbrt" },+ { path = "f32::cos", reason = "the C library of each platform computes this differently: use ak::math::cos" },+ { path = "f32::cosh", reason = "the C library of each platform computes this differently: use ak::math::cosh" },+ { path = "f32::exp", reason = "the C library of each platform computes this differently: use ak::math::exp" },+ { path = "f32::exp2", reason = "the C library of each platform computes this differently: use ak::math::exp2" },+ { path = "f32::exp_m1", reason = "the C library of each platform computes this differently: use ak::math::expm1" },+ { path = "f32::hypot", reason = "the C library of each platform computes this differently: use ak::math::hypot" },+ { path = "f32::ln", reason = "the C library of each platform computes this differently: use ak::math::log" },+ { path = "f32::ln_1p", reason = "the C library of each platform computes this differently: use ak::math::log1p" },+ { path = "f32::log", reason = "the C library of each platform computes this differently: use ak::math::log(x) / log(base)" },+ { path = "f32::log10", reason = "the C library of each platform computes this differently: use ak::math::log10" },+ { path = "f32::log2", reason = "the C library of each platform computes this differently: use ak::math::log2" },+ { path = "f32::powf", reason = "the C library of each platform computes this differently: use ak::math::pow" },+ { path = "f32::sin", reason = "the C library of each platform computes this differently: use ak::math::sin" },+ { path = "f32::sin_cos", reason = "the C library of each platform computes this differently: use ak::math::sincos" },+ { path = "f32::sinh", reason = "the C library of each platform computes this differently: use ak::math::sinh" },+ { path = "f32::tan", reason = "the C library of each platform computes this differently: use ak::math::tan" },+ { path = "f32::tanh", reason = "the C library of each platform computes this differently: use ak::math::tanh" },+ { path = "f32::asinh", reason = "the C library of each platform computes this differently: use ak::math::asinh" },+ { path = "f32::acosh", reason = "the C library of each platform computes this differently: use ak::math::acosh" },+ { path = "f32::atanh", reason = "the C library of each platform computes this differently: use ak::math::atanh" },+ { path = "f64::acos", reason = "the C library of each platform computes this differently: use ak::math::acos" },+ { path = "f64::asin", reason = "the C library of each platform computes this differently: use ak::math::asin" },+ { path = "f64::atan", reason = "the C library of each platform computes this differently: use ak::math::atan" },+ { path = "f64::atan2", reason = "the C library of each platform computes this differently: use ak::math::atan2" },+ { path = "f64::cbrt", reason = "the C library of each platform computes this differently: use ak::math::cbrt" },+ { path = "f64::cos", reason = "the C library of each platform computes this differently: use ak::math::cos" },+ { path = "f64::cosh", reason = "the C library of each platform computes this differently: use ak::math::cosh" },+ { path = "f64::exp", reason = "the C library of each platform computes this differently: use ak::math::exp" },+ { path = "f64::exp2", reason = "the C library of each platform computes this differently: use ak::math::exp2" },+ { path = "f64::exp_m1", reason = "the C library of each platform computes this differently: use ak::math::expm1" },+ { path = "f64::hypot", reason = "the C library of each platform computes this differently: use ak::math::hypot" },+ { path = "f64::ln", reason = "the C library of each platform computes this differently: use ak::math::log" },+ { path = "f64::ln_1p", reason = "the C library of each platform computes this differently: use ak::math::log1p" },+ { path = "f64::log", reason = "the C library of each platform computes this differently: use ak::math::log(x) / log(base)" },+ { path = "f64::log10", reason = "the C library of each platform computes this differently: use ak::math::log10" },+ { path = "f64::log2", reason = "the C library of each platform computes this differently: use ak::math::log2" },+ { path = "f64::powf", reason = "the C library of each platform computes this differently: use ak::math::pow" },+ { path = "f64::sin", reason = "the C library of each platform computes this differently: use ak::math::sin" },+ { path = "f64::sin_cos", reason = "the C library of each platform computes this differently: use ak::math::sincos" },+ { path = "f64::sinh", reason = "the C library of each platform computes this differently: use ak::math::sinh" },+ { path = "f64::tan", reason = "the C library of each platform computes this differently: use ak::math::tan" },+ { path = "f64::tanh", reason = "the C library of each platform computes this differently: use ak::math::tanh" },+ { path = "f64::asinh", reason = "the C library of each platform computes this differently: use ak::math::asinh" },+ { path = "f64::acosh", reason = "the C library of each platform computes this differently: use ak::math::acosh" },+ { path = "f64::atanh", reason = "the C library of each platform computes this differently: use ak::math::atanh" },]