mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 14:18:04 +08:00
Remove stray float literal .0 suffixes in lieu of just ending with a point (#4233)
Remove the .0 suffix on floats in lieu of just ending with a point
This commit is contained in:
@@ -280,8 +280,8 @@ impl App {
|
||||
let viewport_offset_y = y / window_size.height as f64;
|
||||
render_state.set_viewport_offset([viewport_offset_x as f32, viewport_offset_y as f32]);
|
||||
|
||||
let viewport_scale_x = if width != 0.0 { window_size.width as f64 / width } else { 1.0 };
|
||||
let viewport_scale_y = if height != 0.0 { window_size.height as f64 / height } else { 1.0 };
|
||||
let viewport_scale_x = if width != 0. { window_size.width as f64 / width } else { 1. };
|
||||
let viewport_scale_y = if height != 0. { window_size.height as f64 / height } else { 1. };
|
||||
render_state.set_viewport_scale([viewport_scale_x as f32, viewport_scale_y as f32]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,16 +8,16 @@ pub(crate) const SCROLL_LINE_HEIGHT: usize = 40;
|
||||
pub(crate) const SCROLL_LINE_WIDTH: usize = 40;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub(crate) const SCROLL_SPEED_X: f32 = 3.0;
|
||||
pub(crate) const SCROLL_SPEED_X: f32 = 3.;
|
||||
#[cfg(target_os = "linux")]
|
||||
pub(crate) const SCROLL_SPEED_Y: f32 = 3.0;
|
||||
pub(crate) const SCROLL_SPEED_Y: f32 = 3.;
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub(crate) const SCROLL_SPEED_X: f32 = 1.0;
|
||||
pub(crate) const SCROLL_SPEED_X: f32 = 1.;
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub(crate) const SCROLL_SPEED_Y: f32 = 1.0;
|
||||
pub(crate) const SCROLL_SPEED_Y: f32 = 1.;
|
||||
|
||||
pub(crate) const PINCH_ZOOM_SPEED: f64 = 300.0;
|
||||
pub(crate) const PINCH_ZOOM_SPEED: f64 = 300.;
|
||||
|
||||
pub(crate) const MULTICLICK_TIMEOUT: Duration = Duration::from_millis(DOUBLE_CLICK_MILLISECONDS);
|
||||
pub(crate) const MULTICLICK_ALLOWED_TRAVEL: usize = 4;
|
||||
|
||||
@@ -174,8 +174,8 @@ impl RenderState {
|
||||
sampler,
|
||||
desired_width: size.width,
|
||||
desired_height: size.height,
|
||||
viewport_scale: [1.0, 1.0],
|
||||
viewport_offset: [0.0, 0.0],
|
||||
viewport_scale: [1., 1.],
|
||||
viewport_offset: [0., 0.],
|
||||
viewport_texture: None,
|
||||
overlays_texture: None,
|
||||
ui_texture: None,
|
||||
|
||||
@@ -228,10 +228,10 @@ pub fn text_width(text: &str, font_size: f64) -> f64 {
|
||||
let typesetting = TypesettingConfig {
|
||||
font_size,
|
||||
line_height_ratio: 1.2,
|
||||
character_spacing: 0.0,
|
||||
character_spacing: 0.,
|
||||
max_width: None,
|
||||
max_height: None,
|
||||
tilt: 0.0,
|
||||
tilt: 0.,
|
||||
align: TextAlign::AlignLeft,
|
||||
};
|
||||
|
||||
|
||||
@@ -1215,7 +1215,7 @@ impl OverlayContextInternal {
|
||||
|
||||
fn snap_to_physical_pixel(&self, p: DVec2) -> DVec2 {
|
||||
let s = self.viewport.scale();
|
||||
if !s.is_finite() || s <= 0.0 {
|
||||
if !s.is_finite() || s <= 0. {
|
||||
return p.round();
|
||||
}
|
||||
(p * s).round() / s
|
||||
@@ -1223,7 +1223,7 @@ impl OverlayContextInternal {
|
||||
|
||||
fn snap_to_physical_pixel_center(&self, p: DVec2) -> DVec2 {
|
||||
let s = self.viewport.scale();
|
||||
if !s.is_finite() || s <= 0.0 {
|
||||
if !s.is_finite() || s <= 0. {
|
||||
return p.round() - DVec2::splat(0.5);
|
||||
}
|
||||
self.snap_to_physical_pixel(p) - DVec2::splat(0.5 / s)
|
||||
|
||||
@@ -17,7 +17,7 @@ impl Default for ViewportMessageHandler {
|
||||
offset: Point { x: 0., y: 0. },
|
||||
size: Point { x: 0., y: 0. },
|
||||
},
|
||||
scale: 1.0,
|
||||
scale: 1.,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -400,14 +400,14 @@ impl FromWithScale<Bounds> for PhysicalBounds {
|
||||
impl Mul<f64> for Point {
|
||||
type Output = Point;
|
||||
fn mul(self, rhs: f64) -> Self::Output {
|
||||
assert_ne!(rhs, 0.0, "Cannot multiply point by zero");
|
||||
assert_ne!(rhs, 0., "Cannot multiply point by zero");
|
||||
Point { x: self.x * rhs, y: self.y * rhs }
|
||||
}
|
||||
}
|
||||
impl Div<f64> for Point {
|
||||
type Output = Point;
|
||||
fn div(self, rhs: f64) -> Self::Output {
|
||||
assert_ne!(rhs, 0.0, "Cannot divide point by zero");
|
||||
assert_ne!(rhs, 0., "Cannot divide point by zero");
|
||||
Point { x: self.x / rhs, y: self.y / rhs }
|
||||
}
|
||||
}
|
||||
@@ -426,16 +426,16 @@ impl Sub<f64> for Point {
|
||||
impl Mul<Point> for Point {
|
||||
type Output = Point;
|
||||
fn mul(self, rhs: Point) -> Self::Output {
|
||||
assert_ne!(rhs.x, 0.0, "Cannot multiply point by zero");
|
||||
assert_ne!(rhs.y, 0.0, "Cannot multiply point by zero");
|
||||
assert_ne!(rhs.x, 0., "Cannot multiply point by zero");
|
||||
assert_ne!(rhs.y, 0., "Cannot multiply point by zero");
|
||||
Point { x: self.x * rhs.x, y: self.y * rhs.y }
|
||||
}
|
||||
}
|
||||
impl Div<Point> for Point {
|
||||
type Output = Point;
|
||||
fn div(self, rhs: Point) -> Self::Output {
|
||||
assert_ne!(rhs.x, 0.0, "Cannot multiply point by zero");
|
||||
assert_ne!(rhs.y, 0.0, "Cannot multiply point by zero");
|
||||
assert_ne!(rhs.x, 0., "Cannot multiply point by zero");
|
||||
assert_ne!(rhs.y, 0., "Cannot multiply point by zero");
|
||||
Point { x: self.x / rhs.x, y: self.y / rhs.y }
|
||||
}
|
||||
}
|
||||
@@ -455,7 +455,7 @@ impl Sub<Point> for Point {
|
||||
impl Mul<f64> for Bounds {
|
||||
type Output = Bounds;
|
||||
fn mul(self, rhs: f64) -> Self::Output {
|
||||
assert_ne!(rhs, 0.0, "Cannot multiply bounds by zero");
|
||||
assert_ne!(rhs, 0., "Cannot multiply bounds by zero");
|
||||
Bounds {
|
||||
offset: self.offset * rhs,
|
||||
size: self.size * rhs,
|
||||
@@ -465,7 +465,7 @@ impl Mul<f64> for Bounds {
|
||||
impl Div<f64> for Bounds {
|
||||
type Output = Bounds;
|
||||
fn div(self, rhs: f64) -> Self::Output {
|
||||
assert_ne!(rhs, 0.0, "Cannot divide bounds by zero");
|
||||
assert_ne!(rhs, 0., "Cannot divide bounds by zero");
|
||||
Bounds {
|
||||
offset: self.offset / rhs,
|
||||
size: self.size / rhs,
|
||||
|
||||
@@ -111,8 +111,8 @@ lazy_static! {
|
||||
map.insert(
|
||||
"invcot",
|
||||
Box::new(|values| match values {
|
||||
[Value::Number(Number::Real(real))] => Some(Value::Number(Number::Real((PI / 2.0 - real).atan()))),
|
||||
[Value::Number(Number::Complex(complex))] => Some(Value::Number(Number::Complex((Complex::new(PI / 2.0, 0.0) - complex).atan()))),
|
||||
[Value::Number(Number::Real(real))] => Some(Value::Number(Number::Real((PI / 2. - real).atan()))),
|
||||
[Value::Number(Number::Complex(complex))] => Some(Value::Number(Number::Complex((Complex::new(PI / 2., 0.) - complex).atan()))),
|
||||
_ => None,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -63,38 +63,38 @@ mod tests {
|
||||
}
|
||||
|
||||
eval_tests! {
|
||||
test_addition: Value::from_f64(7.0) => Node::BinOp {
|
||||
lhs: Box::new(Node::Lit(Literal::Float(3.0))),
|
||||
test_addition: Value::from_f64(7.) => Node::BinOp {
|
||||
lhs: Box::new(Node::Lit(Literal::Float(3.))),
|
||||
op: BinaryOp::Add,
|
||||
rhs: Box::new(Node::Lit(Literal::Float(4.0))),
|
||||
rhs: Box::new(Node::Lit(Literal::Float(4.))),
|
||||
},
|
||||
test_subtraction: Value::from_f64(1.0) => Node::BinOp {
|
||||
lhs: Box::new(Node::Lit(Literal::Float(5.0))),
|
||||
test_subtraction: Value::from_f64(1.) => Node::BinOp {
|
||||
lhs: Box::new(Node::Lit(Literal::Float(5.))),
|
||||
op: BinaryOp::Sub,
|
||||
rhs: Box::new(Node::Lit(Literal::Float(4.0))),
|
||||
rhs: Box::new(Node::Lit(Literal::Float(4.))),
|
||||
},
|
||||
test_multiplication: Value::from_f64(12.0) => Node::BinOp {
|
||||
lhs: Box::new(Node::Lit(Literal::Float(3.0))),
|
||||
test_multiplication: Value::from_f64(12.) => Node::BinOp {
|
||||
lhs: Box::new(Node::Lit(Literal::Float(3.))),
|
||||
op: BinaryOp::Mul,
|
||||
rhs: Box::new(Node::Lit(Literal::Float(4.0))),
|
||||
rhs: Box::new(Node::Lit(Literal::Float(4.))),
|
||||
},
|
||||
test_division: Value::from_f64(2.5) => Node::BinOp {
|
||||
lhs: Box::new(Node::Lit(Literal::Float(5.0))),
|
||||
lhs: Box::new(Node::Lit(Literal::Float(5.))),
|
||||
op: BinaryOp::Div,
|
||||
rhs: Box::new(Node::Lit(Literal::Float(2.0))),
|
||||
rhs: Box::new(Node::Lit(Literal::Float(2.))),
|
||||
},
|
||||
test_negation: Value::from_f64(-3.0) => Node::UnaryOp {
|
||||
expr: Box::new(Node::Lit(Literal::Float(3.0))),
|
||||
test_negation: Value::from_f64(-3.) => Node::UnaryOp {
|
||||
expr: Box::new(Node::Lit(Literal::Float(3.))),
|
||||
op: UnaryOp::Neg,
|
||||
},
|
||||
test_sqrt: Value::from_f64(2.0) => Node::UnaryOp {
|
||||
expr: Box::new(Node::Lit(Literal::Float(4.0))),
|
||||
test_sqrt: Value::from_f64(2.) => Node::UnaryOp {
|
||||
expr: Box::new(Node::Lit(Literal::Float(4.))),
|
||||
op: UnaryOp::Sqrt,
|
||||
},
|
||||
test_power: Value::from_f64(8.0) => Node::BinOp {
|
||||
lhs: Box::new(Node::Lit(Literal::Float(2.0))),
|
||||
test_power: Value::from_f64(8.) => Node::BinOp {
|
||||
lhs: Box::new(Node::Lit(Literal::Float(2.))),
|
||||
op: BinaryOp::Pow,
|
||||
rhs: Box::new(Node::Lit(Literal::Float(3.0))),
|
||||
rhs: Box::new(Node::Lit(Literal::Float(3.))),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,20 +130,20 @@ mod tests {
|
||||
constant_pi: "pi" => (std::f64::consts::PI, Unit::BASE_UNIT),
|
||||
constant_e: "e" => (std::f64::consts::E, Unit::BASE_UNIT),
|
||||
constant_phi: "phi" => (1.61803398875, Unit::BASE_UNIT),
|
||||
constant_tau: "tau" => (2.0 * std::f64::consts::PI, Unit::BASE_UNIT),
|
||||
constant_tau: "tau" => (2. * std::f64::consts::PI, Unit::BASE_UNIT),
|
||||
constant_infinity: "inf" => (f64::INFINITY, Unit::BASE_UNIT),
|
||||
constant_infinity_symbol: "∞" => (f64::INFINITY, Unit::BASE_UNIT),
|
||||
multiply_pi: "2 * pi" => (2.0 * std::f64::consts::PI, Unit::BASE_UNIT),
|
||||
add_e_constant: "e + 1" => (std::f64::consts::E + 1.0, Unit::BASE_UNIT),
|
||||
multiply_phi_constant: "phi * 2" => (1.61803398875 * 2.0, Unit::BASE_UNIT),
|
||||
exponent_tau: "2^tau" => (2f64.powf(2.0 * std::f64::consts::PI), Unit::BASE_UNIT),
|
||||
multiply_pi: "2 * pi" => (2. * std::f64::consts::PI, Unit::BASE_UNIT),
|
||||
add_e_constant: "e + 1" => (std::f64::consts::E + 1., Unit::BASE_UNIT),
|
||||
multiply_phi_constant: "phi * 2" => (1.61803398875 * 2., Unit::BASE_UNIT),
|
||||
exponent_tau: "2^tau" => (2f64.powf(2. * std::f64::consts::PI), Unit::BASE_UNIT),
|
||||
infinity_subtract_large_number: "inf - 1000" => (f64::INFINITY, Unit::BASE_UNIT),
|
||||
|
||||
// Trigonometric functions
|
||||
trig_sin_pi: "sin(pi)" => (0.0, Unit::BASE_UNIT),
|
||||
trig_cos_zero: "cos(0)" => (1.0, Unit::BASE_UNIT),
|
||||
trig_tan_pi_div_four: "tan(pi/4)" => (1.0, Unit::BASE_UNIT),
|
||||
trig_sin_tau: "sin(tau)" => (0.0, Unit::BASE_UNIT),
|
||||
trig_cos_tau_div_two: "cos(tau/2)" => (-1.0, Unit::BASE_UNIT),
|
||||
trig_sin_pi: "sin(pi)" => (0., Unit::BASE_UNIT),
|
||||
trig_cos_zero: "cos(0)" => (1., Unit::BASE_UNIT),
|
||||
trig_tan_pi_div_four: "tan(pi/4)" => (1., Unit::BASE_UNIT),
|
||||
trig_sin_tau: "sin(tau)" => (0., Unit::BASE_UNIT),
|
||||
trig_cos_tau_div_two: "cos(tau/2)" => (-1., Unit::BASE_UNIT),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ impl NodeMetadata {
|
||||
}
|
||||
|
||||
fn parse_unit(pairs: Pairs<Rule>) -> Result<(Unit, f64), ParseError> {
|
||||
let mut scale = 1.0;
|
||||
let mut scale = 1.;
|
||||
let mut length = 0;
|
||||
let mut mass = 0;
|
||||
let mut time = 0;
|
||||
@@ -102,9 +102,9 @@ fn parse_unit(pairs: Pairs<Rule>) -> Result<(Unit, f64), ParseError> {
|
||||
fn parse_const(pair: Pair<Rule>) -> Literal {
|
||||
match pair.as_rule() {
|
||||
Rule::infinity => Literal::Float(f64::INFINITY),
|
||||
Rule::imaginary_unit => Literal::Complex(Complex::new(0.0, 1.0)),
|
||||
Rule::imaginary_unit => Literal::Complex(Complex::new(0., 1.)),
|
||||
Rule::pi => Literal::Float(std::f64::consts::PI),
|
||||
Rule::tau => Literal::Float(2.0 * std::f64::consts::PI),
|
||||
Rule::tau => Literal::Float(2. * std::f64::consts::PI),
|
||||
Rule::euler_number => Literal::Float(std::f64::consts::E),
|
||||
Rule::golden_ratio => Literal::Float(1.61803398875),
|
||||
_ => unreachable!("Unexpected constant: {:?}", pair),
|
||||
@@ -327,52 +327,52 @@ mod tests {
|
||||
}
|
||||
|
||||
test_parser! {
|
||||
test_parse_int_literal: "42" => Node::Lit(Literal::Float(42.0)),
|
||||
test_parse_int_literal: "42" => Node::Lit(Literal::Float(42.)),
|
||||
test_parse_float_literal: "3.14" => Node::Lit(Literal::Float(#[allow(clippy::approx_constant)] 3.14)),
|
||||
test_parse_ident: "x" => Node::Var("x".to_string()),
|
||||
test_parse_unary_neg: "-42" => Node::UnaryOp {
|
||||
expr: Box::new(Node::Lit(Literal::Float(42.0))),
|
||||
expr: Box::new(Node::Lit(Literal::Float(42.))),
|
||||
op: UnaryOp::Neg,
|
||||
},
|
||||
test_parse_binary_add: "1 + 2" => Node::BinOp {
|
||||
lhs: Box::new(Node::Lit(Literal::Float(1.0))),
|
||||
lhs: Box::new(Node::Lit(Literal::Float(1.))),
|
||||
op: BinaryOp::Add,
|
||||
rhs: Box::new(Node::Lit(Literal::Float(2.0))),
|
||||
rhs: Box::new(Node::Lit(Literal::Float(2.))),
|
||||
},
|
||||
test_parse_binary_mul: "3 * 4" => Node::BinOp {
|
||||
lhs: Box::new(Node::Lit(Literal::Float(3.0))),
|
||||
lhs: Box::new(Node::Lit(Literal::Float(3.))),
|
||||
op: BinaryOp::Mul,
|
||||
rhs: Box::new(Node::Lit(Literal::Float(4.0))),
|
||||
rhs: Box::new(Node::Lit(Literal::Float(4.))),
|
||||
},
|
||||
test_parse_binary_pow: "2 ^ 3" => Node::BinOp {
|
||||
lhs: Box::new(Node::Lit(Literal::Float(2.0))),
|
||||
lhs: Box::new(Node::Lit(Literal::Float(2.))),
|
||||
op: BinaryOp::Pow,
|
||||
rhs: Box::new(Node::Lit(Literal::Float(3.0))),
|
||||
rhs: Box::new(Node::Lit(Literal::Float(3.))),
|
||||
},
|
||||
test_parse_unary_sqrt: "sqrt(16)" => Node::UnaryOp {
|
||||
expr: Box::new(Node::Lit(Literal::Float(16.0))),
|
||||
expr: Box::new(Node::Lit(Literal::Float(16.))),
|
||||
op: UnaryOp::Sqrt,
|
||||
},
|
||||
test_parse_sqr_ident: "sqr(16)" => Node::FnCall {
|
||||
name:"sqr".to_string(),
|
||||
expr: vec![Node::Lit(Literal::Float(16.0))]
|
||||
expr: vec![Node::Lit(Literal::Float(16.))]
|
||||
},
|
||||
|
||||
test_parse_complex_expr: "(1 + 2) 3 - 4 ^ 2" => Node::BinOp {
|
||||
lhs: Box::new(Node::BinOp {
|
||||
lhs: Box::new(Node::BinOp {
|
||||
lhs: Box::new(Node::Lit(Literal::Float(1.0))),
|
||||
lhs: Box::new(Node::Lit(Literal::Float(1.))),
|
||||
op: BinaryOp::Add,
|
||||
rhs: Box::new(Node::Lit(Literal::Float(2.0))),
|
||||
rhs: Box::new(Node::Lit(Literal::Float(2.))),
|
||||
}),
|
||||
op: BinaryOp::Mul,
|
||||
rhs: Box::new(Node::Lit(Literal::Float(3.0))),
|
||||
rhs: Box::new(Node::Lit(Literal::Float(3.))),
|
||||
}),
|
||||
op: BinaryOp::Sub,
|
||||
rhs: Box::new(Node::BinOp {
|
||||
lhs: Box::new(Node::Lit(Literal::Float(4.0))),
|
||||
lhs: Box::new(Node::Lit(Literal::Float(4.))),
|
||||
op: BinaryOp::Pow,
|
||||
rhs: Box::new(Node::Lit(Literal::Float(2.0))),
|
||||
rhs: Box::new(Node::Lit(Literal::Float(2.))),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ impl Number {
|
||||
}
|
||||
|
||||
(Number::Real(lhs), Number::Complex(rhs)) => {
|
||||
let lhs_complex = Complex::new(lhs, 0.0);
|
||||
let lhs_complex = Complex::new(lhs, 0.);
|
||||
let result = match op {
|
||||
BinaryOp::Add => lhs_complex + rhs,
|
||||
BinaryOp::Sub => lhs_complex - rhs,
|
||||
@@ -89,7 +89,7 @@ impl Number {
|
||||
}
|
||||
|
||||
(Number::Complex(lhs), Number::Real(rhs)) => {
|
||||
let rhs_complex = Complex::new(rhs, 0.0);
|
||||
let rhs_complex = Complex::new(rhs, 0.);
|
||||
let result = match op {
|
||||
BinaryOp::Add => lhs + rhs_complex,
|
||||
BinaryOp::Sub => lhs - rhs_complex,
|
||||
|
||||
@@ -146,7 +146,7 @@ impl AnimationParams {
|
||||
|
||||
/// Get the frame delay in centiseconds (GIF uses 10ms units)
|
||||
pub fn frame_delay_centiseconds(&self) -> u16 {
|
||||
((100.0 / self.fps).round() as u16).max(1)
|
||||
((100. / self.fps).round() as u16).max(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -701,7 +701,7 @@ mod graphic_is_opaque_tests {
|
||||
use super::*;
|
||||
|
||||
fn color_graphic(alpha: f64) -> Graphic {
|
||||
let color = Color::from_rgbaf32(1.0, 0.0, 0.0, alpha as f32).unwrap();
|
||||
let color = Color::from_rgbaf32(1., 0., 0., alpha as f32).unwrap();
|
||||
Graphic::Color(List::new_from_element(color))
|
||||
}
|
||||
|
||||
@@ -713,7 +713,7 @@ mod graphic_is_opaque_tests {
|
||||
|
||||
#[test]
|
||||
fn opaque_color_is_opaque() {
|
||||
let g = color_graphic(1.0);
|
||||
let g = color_graphic(1.);
|
||||
assert!(g.is_opaque());
|
||||
}
|
||||
|
||||
@@ -731,8 +731,8 @@ mod graphic_is_opaque_tests {
|
||||
|
||||
#[test]
|
||||
fn gradient_with_all_opaque_stops_is_opaque() {
|
||||
let color_1 = Color::from_rgbaf32(1.0, 0.0, 0.0, 1.).unwrap();
|
||||
let color_2 = Color::from_rgbaf32(1.0, 0.0, 0.0, 1.).unwrap();
|
||||
let color_1 = Color::from_rgbaf32(1., 0., 0., 1.).unwrap();
|
||||
let color_2 = Color::from_rgbaf32(1., 0., 0., 1.).unwrap();
|
||||
let gradient = GradientStops::new(vec![
|
||||
GradientStop {
|
||||
position: 0.,
|
||||
@@ -751,8 +751,8 @@ mod graphic_is_opaque_tests {
|
||||
|
||||
#[test]
|
||||
fn gradient_with_transparent_stop_is_not_opaque() {
|
||||
let color_1 = Color::from_rgbaf32(1.0, 0.0, 0.0, 0.5).unwrap();
|
||||
let color_2 = Color::from_rgbaf32(1.0, 0.0, 0.0, 1.).unwrap();
|
||||
let color_1 = Color::from_rgbaf32(1., 0., 0., 0.5).unwrap();
|
||||
let color_2 = Color::from_rgbaf32(1., 0., 0., 1.).unwrap();
|
||||
let gradient = GradientStops::new(vec![
|
||||
GradientStop {
|
||||
position: 0.,
|
||||
|
||||
@@ -261,12 +261,12 @@ impl RGB for Luma {
|
||||
impl Pixel for Luma {}
|
||||
|
||||
/// Structure that represents a color.
|
||||
/// Internally alpha is stored as `f32` that ranges from `0.0` (transparent) to `1.0` (opaque).
|
||||
/// The other components (RGB) are stored as `f32` that range from `0.0` up to `f32::MAX`,
|
||||
/// the values encode the brightness of each channel proportional to the light intensity in cd/m² (nits) in HDR, and `0.0` (black) to `1.0` (white) in SDR color.
|
||||
/// Internally alpha is stored as `f32` that ranges from `0.` (transparent) to `1.` (opaque).
|
||||
/// The other components (RGB) are stored as `f32` that range from `0.` up to `f32::MAX`,
|
||||
/// the values encode the brightness of each channel proportional to the light intensity in cd/m² (nits) in HDR, and `0.` (black) to `1.` (white) in SDR color.
|
||||
/// Linear-light sRGB color with `f32` channels (alpha unassociated for swatch/UI colors, associated/premultiplied for pixel data inside [`Image<Color>`]).
|
||||
///
|
||||
/// Channels range from `0.0` to `f32::MAX`, encoding brightness proportional to light intensity (cd/m² nits in HDR, or `0..=1` mapped to white for SDR).
|
||||
/// Channels range from `0.` to `f32::MAX`, encoding brightness proportional to light intensity (cd/m² nits in HDR, or `0..=1` mapped to white for SDR).
|
||||
///
|
||||
/// Anything crossing the Wasm/JS boundary must go through [`SRGBA8`] instead.
|
||||
#[repr(C)]
|
||||
@@ -452,8 +452,8 @@ impl Color {
|
||||
alpha: 0.,
|
||||
};
|
||||
|
||||
/// Returns `Some(Color)` if `red`, `green`, `blue` and `alpha` have a valid value. Negative numbers (including `-0.0`), NaN, and infinity are not valid values and return `None`.
|
||||
/// Alpha values greater than `1.0` are not valid.
|
||||
/// Returns `Some(Color)` if `red`, `green`, `blue` and `alpha` have a valid value. Negative numbers (including `-0.`), NaN, and infinity are not valid values and return `None`.
|
||||
/// Alpha values greater than `1.` are not valid.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
@@ -593,7 +593,7 @@ impl Color {
|
||||
self.blue
|
||||
}
|
||||
|
||||
/// Return the `alpha` component without checking its expected `0.0` to `1.0` range.
|
||||
/// Return the `alpha` component without checking its expected `0.` to `1.` range.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
|
||||
@@ -62,7 +62,7 @@ pub fn float_to_srgb_u8(mut f: f32) -> u8 {
|
||||
f = 1.;
|
||||
}
|
||||
|
||||
// Shift away slightly from 0.0 to reduce exponent range.
|
||||
// Shift away slightly from 0 to reduce exponent range.
|
||||
const C: f32 = 0.009842521f32;
|
||||
let u = (f + C).to_bits() - C.to_bits();
|
||||
if u > (1. + C).to_bits() - C.to_bits() {
|
||||
|
||||
@@ -214,16 +214,16 @@ pub fn pathseg_find_tvalues_for_x(segment: PathSeg, x: f64) -> impl Iterator<Ite
|
||||
if a.abs() > MAX_ABSOLUTE_DIFFERENCE { [Some(-b / a), None, None] } else { [None; 3] }
|
||||
}
|
||||
PathSeg::Quad(QuadBez { p0, p1, p2 }) => {
|
||||
let a = p2.x - 2.0 * p1.x + p0.x;
|
||||
let b = 2.0 * (p1.x - p0.x);
|
||||
let a = p2.x - 2. * p1.x + p0.x;
|
||||
let b = 2. * (p1.x - p0.x);
|
||||
let c = p0.x - x;
|
||||
let r = solve_quadratic(c, b, a);
|
||||
[r.first().copied(), r.get(1).copied(), None]
|
||||
}
|
||||
PathSeg::Cubic(CubicBez { p0, p1, p2, p3 }) => {
|
||||
let a = p3.x - 3.0 * p2.x + 3.0 * p1.x - p0.x;
|
||||
let b = 3.0 * (p2.x - 2.0 * p1.x + p0.x);
|
||||
let c = 3.0 * (p1.x - p0.x);
|
||||
let a = p3.x - 3. * p2.x + 3. * p1.x - p0.x;
|
||||
let b = 3. * (p2.x - 2. * p1.x + p0.x);
|
||||
let c = 3. * (p1.x - p0.x);
|
||||
let d = p0.x - x;
|
||||
let r = solve_cubic(d, c, b, a);
|
||||
[r.first().copied(), r.get(1).copied(), r.get(2).copied()]
|
||||
|
||||
@@ -96,14 +96,14 @@ pub fn solve_spline_first_handle_closed(points: &[DVec2]) -> Vec<DVec2> {
|
||||
|
||||
// Handle from from `1` to `len_points - 2` (inclusive).
|
||||
for ix in 1..=(len_points - 2) {
|
||||
let m = 1.0 / (b[ix] - a[ix] * cmod[ix - 1]);
|
||||
let m = 1. / (b[ix] - a[ix] * cmod[ix - 1]);
|
||||
cmod[ix] = c[ix] * m;
|
||||
u[ix] = (0.0 - a[ix] * u[ix - 1]) * m;
|
||||
u[ix] = (0. - a[ix] * u[ix - 1]) * m;
|
||||
x[ix] = (x[ix] - a[ix] * x[ix - 1]) * m;
|
||||
}
|
||||
|
||||
// Handle `len_points - 1`.
|
||||
let m = 1.0 / (b[len_points - 1] - alpha * beta / gamma - beta * cmod[len_points - 2]);
|
||||
let m = 1. / (b[len_points - 1] - alpha * beta / gamma - beta * cmod[len_points - 2]);
|
||||
u[len_points - 1] = (alpha - a[len_points - 1] * u[len_points - 2]) * m;
|
||||
x[len_points - 1] = (x[len_points - 1] - a[len_points - 1] * x[len_points - 2]) * m;
|
||||
|
||||
@@ -113,7 +113,7 @@ pub fn solve_spline_first_handle_closed(points: &[DVec2]) -> Vec<DVec2> {
|
||||
x[ix] = x[ix] - cmod[ix] * x[ix + 1];
|
||||
}
|
||||
|
||||
let fact = (x[0] + x[len_points - 1] * beta / gamma) / (1.0 + u[0] + u[len_points - 1] * beta / gamma);
|
||||
let fact = (x[0] + x[len_points - 1] * beta / gamma) / (1. + u[0] + u[len_points - 1] * beta / gamma);
|
||||
|
||||
for ix in 0..(len_points) {
|
||||
x[ix] -= fact * u[ix];
|
||||
|
||||
@@ -360,9 +360,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_bounding_box_cache_fingerprint_generation() {
|
||||
// Test that fingerprints have MSB set and use only 7 bits for data
|
||||
let rotation1 = 0.0;
|
||||
let rotation2 = PI / 3.0;
|
||||
let rotation3 = PI / 2.0;
|
||||
let rotation1 = 0.;
|
||||
let rotation2 = PI / 3.;
|
||||
let rotation3 = PI / 2.;
|
||||
|
||||
let fp1 = BoundingBoxCache::rotation_fingerprint(rotation1);
|
||||
let fp2 = BoundingBoxCache::rotation_fingerprint(rotation2);
|
||||
@@ -387,11 +387,11 @@ mod tests {
|
||||
let mut cache = BoundingBoxCache::default();
|
||||
|
||||
// Create a simple rectangle subpath for testing
|
||||
let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::new(100.0, 50.0));
|
||||
let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::new(100., 50.));
|
||||
|
||||
let rotation = PI / 4.0;
|
||||
let scale = DVec2::new(2.0, 2.0);
|
||||
let translation = DVec2::new(10.0, 20.0);
|
||||
let rotation = PI / 4.;
|
||||
let scale = DVec2::new(2., 2.);
|
||||
let translation = DVec2::new(10., 20.);
|
||||
let fingerprint = BoundingBoxCache::rotation_fingerprint(rotation);
|
||||
|
||||
// Cache should be empty initially
|
||||
@@ -410,12 +410,12 @@ mod tests {
|
||||
#[test]
|
||||
fn test_bounding_box_cache_ring_buffer_behavior() {
|
||||
let mut cache = BoundingBoxCache::default();
|
||||
let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::new(10.0, 10.0));
|
||||
let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::new(10., 10.));
|
||||
let scale = DVec2::ONE;
|
||||
let translation = DVec2::ZERO;
|
||||
|
||||
// Fill cache beyond capacity to test ring buffer behavior
|
||||
let rotations: Vec<f64> = (0..10).map(|i| i as f64 * PI / 8.0).collect();
|
||||
let rotations: Vec<f64> = (0..10).map(|i| i as f64 * PI / 8.).collect();
|
||||
|
||||
for rotation in &rotations {
|
||||
let fingerprint = BoundingBoxCache::rotation_fingerprint(*rotation);
|
||||
@@ -435,12 +435,12 @@ mod tests {
|
||||
#[test]
|
||||
fn test_click_target_bounding_box_caching() {
|
||||
// Create a click target with a simple rectangle
|
||||
let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::new(100.0, 50.0));
|
||||
let click_target = ClickTarget::new_with_subpath(subpath, 1.0);
|
||||
let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::new(100., 50.));
|
||||
let click_target = ClickTarget::new_with_subpath(subpath, 1.);
|
||||
|
||||
let rotation = PI / 6.0;
|
||||
let rotation = PI / 6.;
|
||||
let scale = DVec2::new(1.5, 1.5);
|
||||
let translation = DVec2::new(20.0, 30.0);
|
||||
let translation = DVec2::new(20., 30.);
|
||||
let transform = DAffine2::from_scale_angle_translation(scale, rotation, translation);
|
||||
|
||||
// Helper function to count present values in cache
|
||||
@@ -463,7 +463,7 @@ mod tests {
|
||||
assert_eq!(count_present_values(), 1); // Should still be 1, not 2
|
||||
|
||||
// Different scale/translation but same rotation should use cached rotation
|
||||
let transform2 = DAffine2::from_scale_angle_translation(DVec2::new(2.0, 2.0), rotation, DVec2::new(50.0, 60.0));
|
||||
let transform2 = DAffine2::from_scale_angle_translation(DVec2::new(2., 2.), rotation, DVec2::new(50., 60.));
|
||||
let result3 = click_target.bounding_box_with_transform(transform2);
|
||||
assert!(result3.is_some());
|
||||
assert_ne!(result1, result3); // Different due to different scale/translation
|
||||
@@ -472,11 +472,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_click_target_skew_bypass_cache() {
|
||||
let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::new(100.0, 50.0));
|
||||
let click_target = ClickTarget::new_with_subpath(subpath.clone(), 1.0);
|
||||
let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::new(100., 50.));
|
||||
let click_target = ClickTarget::new_with_subpath(subpath.clone(), 1.);
|
||||
|
||||
// Create a transform with skew (non-uniform scaling in different directions)
|
||||
let skew_transform = DAffine2::from_cols_array(&[2.0, 0.5, 0.0, 1.0, 10.0, 20.0]);
|
||||
let skew_transform = DAffine2::from_cols_array(&[2., 0.5, 0., 1., 10., 20.]);
|
||||
assert!(skew_transform.has_skew());
|
||||
|
||||
// Should bypass cache and compute directly
|
||||
@@ -488,12 +488,12 @@ mod tests {
|
||||
#[test]
|
||||
fn test_cache_fingerprint_collision_handling() {
|
||||
let mut cache = BoundingBoxCache::default();
|
||||
let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::new(10.0, 10.0));
|
||||
let subpath = Subpath::new_rectangle(DVec2::ZERO, DVec2::new(10., 10.));
|
||||
let scale = DVec2::ONE;
|
||||
let translation = DVec2::ZERO;
|
||||
|
||||
// Find two rotations that produce the same fingerprint (collision)
|
||||
let rotation1 = 0.0;
|
||||
let rotation1 = 0.;
|
||||
let rotation2 = 0.25;
|
||||
let fp1 = BoundingBoxCache::rotation_fingerprint(rotation1);
|
||||
let fp2 = BoundingBoxCache::rotation_fingerprint(rotation2);
|
||||
|
||||
@@ -291,11 +291,11 @@ pub trait Tangent {
|
||||
fn tangent_at(&self, t: f64) -> DVec2;
|
||||
|
||||
fn tangent_at_start(&self) -> DVec2 {
|
||||
self.tangent_at(0.0)
|
||||
self.tangent_at(0.)
|
||||
}
|
||||
|
||||
fn tangent_at_end(&self) -> DVec2 {
|
||||
self.tangent_at(1.0)
|
||||
self.tangent_at(1.)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -190,14 +190,14 @@ impl BackgroundCompositor {
|
||||
}
|
||||
|
||||
pub fn composite(&self, context: &crate::WgpuContext, foreground: &wgpu::Texture, output: &wgpu::Texture, backgrounds: &[rendering::Background], document_to_screen: Affine2, zoom: f32) {
|
||||
if zoom <= 0.0 {
|
||||
if zoom <= 0. {
|
||||
return;
|
||||
}
|
||||
|
||||
let device = &context.device;
|
||||
let queue = &context.queue;
|
||||
|
||||
let checker_size_doc = 8.0 / zoom;
|
||||
let checker_size_doc = 8. / zoom;
|
||||
let screen_to_document = document_to_screen.inverse();
|
||||
let viewport_size = output.size();
|
||||
let viewport_size = Vec2::new(viewport_size.width as f32, viewport_size.height as f32);
|
||||
|
||||
@@ -46,7 +46,7 @@ pub async fn pixel_preview<'a: 'n>(
|
||||
let upstream_resolution = upstream_size.as_uvec2().max(UVec2::ONE);
|
||||
|
||||
let upstream_footprint = Footprint {
|
||||
transform: DAffine2::from_scale(DVec2::splat(1.0 / physical_scale)) * DAffine2::from_translation(-upstream_min),
|
||||
transform: DAffine2::from_scale(DVec2::splat(1. / physical_scale)) * DAffine2::from_translation(-upstream_min),
|
||||
resolution: upstream_resolution,
|
||||
quality: footprint.quality,
|
||||
};
|
||||
|
||||
@@ -90,8 +90,8 @@ impl CacheKey {
|
||||
thumbnail,
|
||||
aligned_strokes,
|
||||
override_paint_order,
|
||||
animation_time_ms: (animation_time * 1000.0).round() as i64,
|
||||
real_time_ms: (real_time * 1000.0).round() as i64,
|
||||
animation_time_ms: (animation_time * 1000.).round() as i64,
|
||||
real_time_ms: (real_time * 1000.).round() as i64,
|
||||
pointer: pointer_bytes,
|
||||
}
|
||||
}
|
||||
@@ -369,8 +369,8 @@ pub async fn render_output_cache<'a: 'n>(
|
||||
render_params.thumbnail,
|
||||
render_params.aligned_strokes,
|
||||
render_params.override_paint_order,
|
||||
ctx.try_animation_time().unwrap_or(0.0),
|
||||
ctx.try_real_time().unwrap_or(0.0),
|
||||
ctx.try_animation_time().unwrap_or(0.),
|
||||
ctx.try_real_time().unwrap_or(0.),
|
||||
ctx.try_pointer_position(),
|
||||
);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use glam::{Vec2, Vec4};
|
||||
use spirv_std::spirv;
|
||||
|
||||
/// webgpu NDC is like OpenGL: (-1.0 .. 1.0, -1.0 .. 1.0, 0.0 .. 1.0)
|
||||
/// WebGPU NDC is like OpenGL: (-1..1, -1..1, 0..1)
|
||||
/// https://www.w3.org/TR/webgpu/#coordinate-systems
|
||||
///
|
||||
/// So to make a fullscreen triangle around a box at (-1..1):
|
||||
|
||||
Reference in New Issue
Block a user