From 2e0adf90c42e5ba59aefceafbafd328be9715b7f Mon Sep 17 00:00:00 2001 From: Pavel Aslanov Date: Fri, 21 Feb 2025 15:20:47 +0000 Subject: [PATCH] [rust-edition] 2024 --- Cargo.toml | 4 ++-- benches/color_bench.rs | 2 +- benches/rasterize_bench.rs | 2 +- benches/scene_bench.rs | 4 ++-- examples/hatchet.rs | 10 ++++++++-- examples/prebench.rs | 2 +- examples/rasterize.rs | 2 +- examples/scene.rs | 2 +- src/color.rs | 6 +++--- src/curve.rs | 17 ++++++++++++----- src/ellipse.rs | 2 +- src/geometry.rs | 20 +++++++++++--------- src/grad.rs | 4 ++-- src/lib.rs | 6 +++--- src/path.rs | 8 ++++---- src/rasterize.rs | 6 +++--- src/scene.rs | 6 +++--- src/utils.rs | 4 ++-- 18 files changed, 61 insertions(+), 46 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6e28402..a982598 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "rasterize" -version = "0.6.1" +version = "0.6.2" authors = ["Pavel Aslanov "] description = "Simple and small 2D rendering library" -edition = "2021" +edition = "2024" include = [ "**/*.rs", "src/svg-colors.txt", diff --git a/benches/color_bench.rs b/benches/color_bench.rs index ed1873a..d7afe2c 100644 --- a/benches/color_bench.rs +++ b/benches/color_bench.rs @@ -1,4 +1,4 @@ -use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput}; +use criterion::{Criterion, Throughput, black_box, criterion_group, criterion_main}; use rasterize::{ linear_to_srgb, simd::{f32x4, l2s}, diff --git a/benches/rasterize_bench.rs b/benches/rasterize_bench.rs index c989db0..77558db 100644 --- a/benches/rasterize_bench.rs +++ b/benches/rasterize_bench.rs @@ -1,6 +1,6 @@ #![deny(warnings)] -use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; +use criterion::{BenchmarkId, Criterion, Throughput, black_box, criterion_group, criterion_main}; use rasterize::*; use std::{ fs::File, diff --git a/benches/scene_bench.rs b/benches/scene_bench.rs index b4df6d9..643ddd7 100644 --- a/benches/scene_bench.rs +++ b/benches/scene_bench.rs @@ -1,6 +1,6 @@ #![deny(warnings)] -use criterion::{criterion_group, criterion_main, Criterion, Throughput}; -use rasterize::{BBox, FillRule, LinColor, Path, Point, Scalar, Scene, Size, Transform, RGBA}; +use criterion::{Criterion, Throughput, criterion_group, criterion_main}; +use rasterize::{BBox, FillRule, LinColor, Path, Point, RGBA, Scalar, Scene, Size, Transform}; use std::sync::Arc; fn many_cirles_benchmark(c: &mut Criterion) { diff --git a/examples/hatchet.rs b/examples/hatchet.rs index 6564f0c..16b3c6c 100644 --- a/examples/hatchet.rs +++ b/examples/hatchet.rs @@ -356,8 +356,14 @@ fn generate_font( glyphs: impl IntoIterator, ) -> Result<(), std::io::Error> { writeln!(out, "")?; - writeln!(out, "")?; - writeln!(out, " ")?; + writeln!( + out, + "" + )?; + writeln!( + out, + " " + )?; writeln!(out, "")?; writeln!(out, " ")?; writeln!(out, " ; diff --git a/examples/rasterize.rs b/examples/rasterize.rs index 4b80385..0c266ed 100644 --- a/examples/rasterize.rs +++ b/examples/rasterize.rs @@ -8,7 +8,7 @@ use std::{ io::{BufWriter, Read}, sync::Arc, }; -use tracing_subscriber::{fmt::format::FmtSpan, EnvFilter}; +use tracing_subscriber::{EnvFilter, fmt::format::FmtSpan}; type Error = Box; diff --git a/examples/scene.rs b/examples/scene.rs index 279b5c7..018b988 100644 --- a/examples/scene.rs +++ b/examples/scene.rs @@ -6,7 +6,7 @@ use std::{ io::{BufReader, BufWriter}, }; use tracing::debug_span; -use tracing_subscriber::{fmt::format::FmtSpan, EnvFilter}; +use tracing_subscriber::{EnvFilter, fmt::format::FmtSpan}; type Error = Box; diff --git a/src/color.rs b/src/color.rs index 33250d7..68e20c3 100644 --- a/src/color.rs +++ b/src/color.rs @@ -1,7 +1,7 @@ -use crate::{simd::f32x4, Paint, Point, Scalar, Transform, Units}; +use crate::{Paint, Point, Scalar, Transform, Units, simd::f32x4}; use bytemuck::{Pod, Zeroable}; #[cfg(feature = "serde")] -use serde::{de::DeserializeSeed, Deserialize, Deserializer, Serialize}; +use serde::{Deserialize, Deserializer, Serialize, de::DeserializeSeed}; use std::{ collections::HashMap, fmt, @@ -115,7 +115,7 @@ impl RGBA { }; let mut hex = bytes .chunks(2) - .map(|pair| Ok(digit(pair[0])? << 4 | digit(pair[1])?)); + .map(|pair| Ok((digit(pair[0])? << 4) | digit(pair[1])?)); RGBA::new( hex.next().unwrap_or(Ok(0))?, hex.next().unwrap_or(Ok(0))?, diff --git a/src/curve.rs b/src/curve.rs index dfb5f19..cc999e0 100644 --- a/src/curve.rs +++ b/src/curve.rs @@ -1,12 +1,12 @@ //! All the things you need to handle bezier curves use crate::{ + BBox, EPSILON, EllipArc, LineCap, LineJoin, Point, Scalar, StrokeStyle, SvgParserError, + SvgPathCmd, SvgPathParser, Transform, utils::{ - clamp, cubic_solve, integrate_quadrature, quadratic_solve, ArrayIter, M3x3, M4x4, - QUADRATURE_16, QUADRATURE_32, + ArrayIter, M3x3, M4x4, QUADRATURE_16, QUADRATURE_32, clamp, cubic_solve, + integrate_quadrature, quadratic_solve, }, - BBox, EllipArc, LineCap, LineJoin, Point, Scalar, StrokeStyle, SvgParserError, SvgPathCmd, - SvgPathParser, Transform, EPSILON, }; use std::{fmt, io::Cursor, str::FromStr}; @@ -834,7 +834,14 @@ impl Curve for Cubic { fn roots(&self) -> CurveRoots { let mut result = CurveRoots::new(); // curve(t)_y = 0 - let Self([Point([_, y0]), Point([_, y1]), Point([_, y2]), Point([_, y3])]) = *self; + let Self( + [ + Point([_, y0]), + Point([_, y1]), + Point([_, y2]), + Point([_, y3]), + ], + ) = *self; let a = -y0 + 3.0 * y1 - 3.0 * y2 + y3; let b = 3.0 * y0 - 6.0 * y1 + 3.0 * y2; let c = -3.0 * y0 + 3.0 * y1; diff --git a/src/ellipse.rs b/src/ellipse.rs index ff10075..d592733 100644 --- a/src/ellipse.rs +++ b/src/ellipse.rs @@ -1,4 +1,4 @@ -use crate::{BBox, Cubic, Curve, CurveFlattenIter, Line, Point, Scalar, Transform, PI}; +use crate::{BBox, Cubic, Curve, CurveFlattenIter, Line, PI, Point, Scalar, Transform}; use std::fmt; /// Elliptical Arc diff --git a/src/geometry.rs b/src/geometry.rs index 228912e..8221e85 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -1,7 +1,7 @@ #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -use crate::{utils::clamp, Line, Size, SvgParserError}; +use crate::{Line, Size, SvgParserError, utils::clamp}; use std::{ fmt, ops::{Add, Div, Mul, Sub}, @@ -72,7 +72,7 @@ impl ScalarFormatter { pub fn round_significant(value: f64, precision: usize) -> f64 { if value.abs() < EPSILON { - return 0.0; + 0.0 } else { let shift = precision as i32 - value.abs().log10().ceil() as i32; let shift_factor = 10_f64.powi(shift); @@ -734,7 +734,7 @@ impl<'de> Deserialize<'de> for BBox { #[cfg(test)] mod tests { use super::*; - use crate::{assert_approx_eq, Curve}; + use crate::{Curve, assert_approx_eq}; type Error = Box; #[test] @@ -801,16 +801,18 @@ mod tests { assert!(tr2.apply(s2.min).is_close_to(Point::new(3.0, 10.0))); let tr3 = Transform::fit_bbox(s1, d, Align::Mid); - assert!(tr3 - .apply((s1.min + s1.max) / 2.0) - .is_close_to((d.min + d.max) / 2.0)); + assert!( + tr3.apply((s1.min + s1.max) / 2.0) + .is_close_to((d.min + d.max) / 2.0) + ); assert!(tr3.apply(s1.min).is_close_to(Point::new(5.5, 5.0))); assert!(tr3.apply(s1.max).is_close_to(Point::new(10.5, 15.0))); let tr4 = Transform::fit_bbox(s2, d, Align::Mid); - assert!(tr4 - .apply((s2.min + s2.max) / 2.0) - .is_close_to((d.min + d.max) / 2.0)); + assert!( + tr4.apply((s2.min + s2.max) / 2.0) + .is_close_to((d.min + d.max) / 2.0) + ); assert!(tr4.apply(s2.min).is_close_to(Point::new(3.0, 7.5))); assert!(tr4.apply(s2.max).is_close_to(Point::new(13.0, 12.5))); diff --git a/src/grad.rs b/src/grad.rs index a48eb58..5d995c9 100644 --- a/src/grad.rs +++ b/src/grad.rs @@ -1,6 +1,6 @@ -use crate::{utils::quadratic_solve, Color, LinColor, Paint, Point, Scalar, Transform, Units}; +use crate::{Color, LinColor, Paint, Point, Scalar, Transform, Units, utils::quadratic_solve}; #[cfg(feature = "serde")] -use serde::{de, Deserialize, Serialize}; +use serde::{Deserialize, Serialize, de}; use std::cmp::Ordering; /// Gradient spread logic for the parameter smaller than 0 and greater than 1 diff --git a/src/lib.rs b/src/lib.rs index 991006b..517fb72 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,20 +42,20 @@ pub use crate::rasterize::{ }; #[cfg(feature = "serde")] pub use color::RGBADeserializer; -pub use color::{linear_to_srgb, srgb_to_linear, Color, ColorError, LinColor, RGBA, SVG_COLORS}; +pub use color::{Color, ColorError, LinColor, RGBA, SVG_COLORS, linear_to_srgb, srgb_to_linear}; pub use curve::{ Cubic, Curve, CurveExtremities, CurveFlattenIter, CurveRoots, Line, Quad, Segment, }; pub use ellipse::EllipArc; pub use geometry::{ - Align, BBox, Point, Scalar, ScalarFormat, ScalarFormatter, Transform, EPSILON, EPSILON_SQRT, PI, + Align, BBox, EPSILON, EPSILON_SQRT, PI, Point, Scalar, ScalarFormat, ScalarFormatter, Transform, }; pub use grad::{GradLinear, GradRadial, GradSpread, GradStop, GradStops}; pub use image::{ Image, ImageIter, ImageMut, ImageMutIter, ImageMutRef, ImageOwned, ImageRef, Shape, }; pub use path::{ - FillRule, LineCap, LineJoin, Path, PathBuilder, StrokeStyle, SubPath, DEFAULT_FLATNESS, + DEFAULT_FLATNESS, FillRule, LineCap, LineJoin, Path, PathBuilder, StrokeStyle, SubPath, }; pub use scene::{Layer, Scene}; pub use svg::{SvgParserError, SvgPathCmd, SvgPathParser}; diff --git a/src/path.rs b/src/path.rs index 76f26a8..976b336 100644 --- a/src/path.rs +++ b/src/path.rs @@ -1,7 +1,7 @@ use crate::{ - curve::line_offset, rasterize::Rasterizer, utils::clamp, BBox, Cubic, Curve, EllipArc, - ImageMut, LinColor, Line, Paint, Point, Quad, Scalar, ScalarFormatter, Segment, Size, - SvgParserError, SvgPathParser, Transform, EPSILON, + BBox, Cubic, Curve, EPSILON, EllipArc, ImageMut, LinColor, Line, Paint, Point, Quad, Scalar, + ScalarFormatter, Segment, Size, SvgParserError, SvgPathParser, Transform, curve::line_offset, + rasterize::Rasterizer, utils::clamp, }; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -1092,7 +1092,7 @@ impl<'de> Deserialize<'de> for Path { #[cfg(test)] mod tests { use super::*; - use crate::{assert_approx_eq, PI}; + use crate::{PI, assert_approx_eq}; fn assert_path_eq(p0: &Path, p1: &Path) { assert_eq!(format!("{:#}", p0), format!("{:#}", p1)); diff --git a/src/rasterize.rs b/src/rasterize.rs index 620ebb0..8ef9203 100644 --- a/src/rasterize.rs +++ b/src/rasterize.rs @@ -26,8 +26,8 @@ //! - this method is slower //! - but requires less memory use crate::{ - Color, Curve, FillRule, ImageMut, ImageOwned, LinColor, Line, Path, Point, Scalar, Transform, - DEFAULT_FLATNESS, EPSILON, EPSILON_SQRT, + Color, Curve, DEFAULT_FLATNESS, EPSILON, EPSILON_SQRT, FillRule, ImageMut, ImageOwned, + LinColor, Line, Path, Point, Scalar, Transform, }; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -939,7 +939,7 @@ fn split_at_zero_x(line: Line) -> (Line, Option) { #[cfg(test)] mod tests { use super::*; - use crate::{assert_approx_eq, Image}; + use crate::{Image, assert_approx_eq}; type Error = Box; #[test] diff --git a/src/scene.rs b/src/scene.rs index d39c941..4f116c8 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -1,6 +1,6 @@ use crate::{ - utils::clamp, ArcPaint, BBox, Color, FillRule, Image, ImageMut, ImageOwned, LinColor, Paint, - Path, Rasterizer, Scalar, Shape, Size, StrokeStyle, Transform, Units, + ArcPaint, BBox, Color, FillRule, Image, ImageMut, ImageOwned, LinColor, Paint, Path, + Rasterizer, Scalar, Shape, Size, StrokeStyle, Transform, Units, utils::clamp, }; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -588,7 +588,7 @@ mod serde_paint { use crate::{GradLinear, GradRadial, LinColor}; use super::{Arc, ArcPaint}; - use serde::{de, ser, Deserialize, Deserializer, Serialize, Serializer}; + use serde::{Deserialize, Deserializer, Serialize, Serializer, de, ser}; use serde_json::Value; pub fn serialize(paint: &ArcPaint, serializer: S) -> Result diff --git a/src/utils.rs b/src/utils.rs index f52d0bc..9835a1c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,5 @@ //! Utility functions and types used across the library -use crate::{Scalar, EPSILON, PI}; +use crate::{EPSILON, PI, Scalar}; use std::{fmt, iter::FusedIterator, ops::Mul}; /// Restrict value to a certain interval @@ -400,7 +400,7 @@ pub(crate) fn is_default(val: &T) -> bool { /// by adding `#[serde(with = "serde_from_str")]` #[cfg(feature = "serde")] pub(crate) mod serde_from_str { - use serde::{de, Deserialize, Deserializer, Serializer}; + use serde::{Deserialize, Deserializer, Serializer, de}; use std::{borrow::Cow, fmt::Display, str::FromStr}; pub fn serialize(value: &T, serializer: S) -> Result