Skip to content

Commit f61302f

Browse files
committed
[clippy] fixes
1 parent cbf6042 commit f61302f

File tree

10 files changed

+34
-36
lines changed

10 files changed

+34
-36
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rasterize"
3-
version = "0.4.1"
3+
version = "0.4.2"
44
authors = ["Pavel Aslanov <asl.pavel@gmail.com>"]
55
description = "Simple and small 2D rendering library"
66
edition = "2021"

examples/eps.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Basic PostScript rasterizer
2+
#![allow(dead_code)]
23
use rasterize::*;
34
use std::{
45
cell::{self, RefCell},
@@ -684,9 +685,9 @@ fn create_global_dict() -> PSDict {
684685
Ok(())
685686
}
686687
val => {
687-
let val = val?;
688+
val?;
688689
state.push(false);
689-
Ok(val)
690+
Ok(())
690691
}
691692
}
692693
});

examples/hatchet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl PartialEq for Intersection {
6262
impl Eq for Intersection {}
6363

6464
// Intersect path specified by segments with `y = 0` when `tr` transformation is applied.
65-
fn intersect(segments: &Vec<Vec<Segment>>, tr: Transform, y_low: bool) -> Vec<Intersection> {
65+
fn intersect(segments: &[Vec<Segment>], tr: Transform, y_low: bool) -> Vec<Intersection> {
6666
let mut ints = Vec::new();
6767
for (subpath_index, subpath) in segments.iter().enumerate() {
6868
for (segment_index, segment) in subpath.iter().enumerate() {
@@ -100,7 +100,7 @@ fn intersect(segments: &Vec<Vec<Segment>>, tr: Transform, y_low: bool) -> Vec<In
100100
let mut output: Vec<Intersection> = Vec::with_capacity(ints.len());
101101
for mut int in ints {
102102
// remove duplicate intersections
103-
if output.len() > 0 {
103+
if !output.is_empty() {
104104
let int_prev = output[output.len() - 1];
105105
if (int.x_coord - int_prev.x_coord).abs() < EPSILON {
106106
if int.winding_delta + int_prev.winding_delta == 0 {

src/color.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl<'de> Deserialize<'de> for RGBA {
254254
}
255255

256256
#[cfg(feature = "serde")]
257-
impl<'de, 'a> DeserializeSeed<'de> for RGBADeserializer<'a> {
257+
impl<'de> DeserializeSeed<'de> for RGBADeserializer<'_> {
258258
type Value = RGBA;
259259

260260
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>

src/geometry.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111
/// Scalar type
1212
pub type Scalar = f64;
1313
/// Epsilon value
14-
pub const EPSILON: f64 = std::f64::EPSILON;
14+
pub const EPSILON: f64 = f64::EPSILON;
1515
/// Square root of the epsilon value
1616
pub const EPSILON_SQRT: f64 = 1.490_116_119_384_765_6e-8;
1717
/// Mathematical pi constant
@@ -623,9 +623,7 @@ impl FromStr for BBox {
623623
type Err = SvgParserError;
624624

625625
fn from_str(string: &str) -> Result<Self, Self::Err> {
626-
let mut values = string
627-
.split(|c| matches!(c, ' ' | ','))
628-
.map(|s| s.trim().parse().ok());
626+
let mut values = string.split([' ', ',']).map(|s| s.trim().parse().ok());
629627
let minx: Scalar = values.next().flatten().ok_or(SvgParserError::InvalidBBox)?;
630628
let miny: Scalar = values.next().flatten().ok_or(SvgParserError::InvalidBBox)?;
631629
let width: Scalar = values.next().flatten().ok_or(SvgParserError::InvalidBBox)?;

src/image.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ pub struct ImageIter<'a, P> {
222222
data: &'a [P],
223223
}
224224

225-
impl<'a, P> ImageIter<'a, P> {
225+
impl<P> ImageIter<'_, P> {
226226
/// Get current (row, column) of the pixel
227227
pub fn position(&self) -> (usize, usize) {
228228
self.shape.nth(self.index).unwrap_or((self.shape.height, 0))
@@ -308,7 +308,7 @@ pub struct ImageMutIter<'a, P> {
308308
data: &'a mut [P],
309309
}
310310

311-
impl<'a, P> ImageMutIter<'a, P> {
311+
impl<P> ImageMutIter<'_, P> {
312312
/// Current (row, col) position of the iterator
313313
pub fn position(&self) -> (usize, usize) {
314314
self.shape.nth(self.index).unwrap_or((self.shape.height, 0))
@@ -427,7 +427,7 @@ pub struct ImageRef<'a, P> {
427427
data: &'a [P],
428428
}
429429

430-
impl<'a, P> fmt::Debug for ImageRef<'a, P> {
430+
impl<P> fmt::Debug for ImageRef<'_, P> {
431431
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
432432
f.debug_struct("ImageRef")
433433
.field("shape", &self.shape)
@@ -442,7 +442,7 @@ impl<'a, P> ImageRef<'a, P> {
442442
}
443443
}
444444

445-
impl<'a, P> Image for ImageRef<'a, P> {
445+
impl<P> Image for ImageRef<'_, P> {
446446
type Pixel = P;
447447

448448
fn shape(&self) -> Shape {
@@ -460,7 +460,7 @@ pub struct ImageMutRef<'a, C> {
460460
data: &'a mut [C],
461461
}
462462

463-
impl<'a, C> fmt::Debug for ImageMutRef<'a, C> {
463+
impl<C> fmt::Debug for ImageMutRef<'_, C> {
464464
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
465465
f.debug_struct("ImageMutRef")
466466
.field("shape", &self.shape)
@@ -475,7 +475,7 @@ impl<'a, P> ImageMutRef<'a, P> {
475475
}
476476
}
477477

478-
impl<'a, P> Image for ImageMutRef<'a, P> {
478+
impl<P> Image for ImageMutRef<'_, P> {
479479
type Pixel = P;
480480

481481
fn shape(&self) -> Shape {
@@ -487,13 +487,13 @@ impl<'a, P> Image for ImageMutRef<'a, P> {
487487
}
488488
}
489489

490-
impl<'a, P> ImageMut for ImageMutRef<'a, P> {
490+
impl<P> ImageMut for ImageMutRef<'_, P> {
491491
fn data_mut(&mut self) -> &mut [Self::Pixel] {
492492
self.data
493493
}
494494
}
495495

496-
impl<'a, I> Image for &'a I
496+
impl<I> Image for &I
497497
where
498498
I: Image + ?Sized,
499499
{
@@ -508,7 +508,7 @@ where
508508
}
509509
}
510510

511-
impl<'a, I> Image for &'a mut I
511+
impl<I> Image for &mut I
512512
where
513513
I: Image + ?Sized,
514514
{
@@ -523,7 +523,7 @@ where
523523
}
524524
}
525525

526-
impl<'a, I> ImageMut for &'a mut I
526+
impl<I> ImageMut for &mut I
527527
where
528528
I: ImageMut + ?Sized,
529529
{

src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
//! ## Overview
1111
//! **Main types are:**
1212
//! - [`Path`] - Represents the same concept as an [SVG path](https://www.w3.org/TR/SVG11/paths.html),
13-
//! the easiest way to construct it is with [`Path::builder`] or it can be parsed from SVG path with [`str::parse`].
14-
//! Path can be stroked with [`Path::stroke`] to generated new path that represents an outline.
13+
//! the easiest way to construct it is with [`Path::builder`] or it can be parsed from SVG path with [`str::parse`].
14+
//! Path can be stroked with [`Path::stroke`] to generated new path that represents an outline.
1515
//! - [`Scene`] - Represents an image that has not been rendered yet, multiple scenes
16-
//! can be composed to construct more complex scene. This is probably the simplest
17-
//! way to render something useful. See `examples/simple.rs` for a simple example.
18-
//! It can also be (de)serialized see `data/firefox.scene` for an example.
16+
//! can be composed to construct more complex scene. This is probably the simplest
17+
//! way to render something useful. See `examples/simple.rs` for a simple example.
18+
//! It can also be (de)serialized see `data/firefox.scene` for an example.
1919
//! - [`Paint`] - Color/Gradient that can be used to fill a path.
2020
//! - [`Image`] - 2D matrix that can hold and image and used as a target for rendering.
21-
//! Image can also be written into a file with [`Image::write_bmp`] or to PNG with
22-
//! `Image::write_png` if `png` feature is enabled.
21+
//! Image can also be written into a file with [`Image::write_bmp`] or to PNG with
22+
//! `Image::write_png` if `png` feature is enabled.
2323
#![deny(warnings)]
2424
#![allow(clippy::excessive_precision)]
2525

src/path.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::{
99
fmt,
1010
io::{Cursor, Read, Write},
1111
str::FromStr,
12-
usize,
1312
};
1413

1514
/// Default flatness used during rasterization.
@@ -257,7 +256,7 @@ impl fmt::Display for Path {
257256
fmt: &'a mut fmt::Formatter<'b>,
258257
}
259258

260-
impl<'a, 'b> std::io::Write for FormatterWrite<'a, 'b> {
259+
impl std::io::Write for FormatterWrite<'_, '_> {
261260
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
262261
self.fmt
263262
.write_str(
@@ -551,7 +550,7 @@ pub struct PathVerboseDebug<'a> {
551550
path: &'a Path,
552551
}
553552

554-
impl<'a> fmt::Debug for PathVerboseDebug<'a> {
553+
impl fmt::Debug for PathVerboseDebug<'_> {
555554
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
556555
if self.path.subpaths.is_empty() {
557556
write!(f, "Empty")?;
@@ -656,7 +655,7 @@ impl<'a> PathFlattenIter<'a> {
656655
}
657656
}
658657

659-
impl<'a> Iterator for PathFlattenIter<'a> {
658+
impl Iterator for PathFlattenIter<'_> {
660659
type Item = Line;
661660

662661
fn next(&mut self) -> Option<Self::Item> {

src/rasterize.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn fill_impl(
114114
}
115115
}
116116

117-
impl<'a, R: Rasterizer + ?Sized> Rasterizer for &'a R {
117+
impl<R: Rasterizer + ?Sized> Rasterizer for &R {
118118
fn mask(
119119
&self,
120120
path: &Path,
@@ -197,7 +197,7 @@ pub trait Paint: fmt::Debug {
197197
fn to_json(&self) -> Result<serde_json::Value, crate::SvgParserError>;
198198
}
199199

200-
impl<'a, P: Paint> Paint for &'a P {
200+
impl<P: Paint> Paint for &P {
201201
fn at(&self, point: Point) -> LinColor {
202202
(**self).at(point)
203203
}
@@ -1143,15 +1143,15 @@ mod tests {
11431143
let r1: Box<dyn Rasterizer> = Box::new(ActiveEdgeRasterizer::default());
11441144
for rasterizer in &[r0, r1] {
11451145
img.clear();
1146-
path.mask(&rasterizer, tr, FillRule::EvenOdd, &mut img);
1146+
path.mask(rasterizer, tr, FillRule::EvenOdd, &mut img);
11471147
assert_approx_eq!(img.get(y, x0).unwrap(), 0.0, 1e-6);
11481148
assert_approx_eq!(img.get(y, x1).unwrap(), 0.0, 1e-6);
11491149
assert_approx_eq!(img.get(y, x2).unwrap(), 0.0, 1e-6);
11501150
let area = img.iter().sum::<Scalar>();
11511151
assert_approx_eq!(area, 13130.0, 1.0);
11521152

11531153
img.clear();
1154-
path.mask(&rasterizer, tr, FillRule::NonZero, &mut img);
1154+
path.mask(rasterizer, tr, FillRule::NonZero, &mut img);
11551155
assert_approx_eq!(img.get(y, x0).unwrap(), 1.0, 1e-6);
11561156
assert_approx_eq!(img.get(y, x1).unwrap(), 1.0, 1e-6);
11571157
assert_approx_eq!(img.get(y, x2).unwrap(), 0.0, 1e-6);

src/scene.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ mod tests {
645645
use super::*;
646646
use crate::ActiveEdgeRasterizer;
647647
type Error = Box<dyn std::error::Error>;
648-
const SCENE: &'static str = r##"
648+
const SCENE: &str = r##"
649649
{
650650
"type": "transform",
651651
"tr": "translate(7, 7) rotate(45, 7, 7) scale(10)",

0 commit comments

Comments
 (0)