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:
@@ -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