Skip to content

Commit

Permalink
Cargo clippy recommendations & spelling fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dralley authored and jrmuizel committed Apr 5, 2020
1 parent aa74dfa commit 0c810a0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/dash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ pub fn dash_path(path: &Path, dash_array: &[f32], mut dash_offset: f32) -> Path
}
}

// We still have an intial segment that we need to emit
if initial_segment.len() > 0 {
// We still have an initial segment that we need to emit
if !initial_segment.is_empty() {
dashed.move_to(initial_segment[0].x, initial_segment[0].y);
for i in 1..initial_segment.len() {
dashed.line_to(initial_segment[i].x, initial_segment[i].y);
Expand Down
4 changes: 2 additions & 2 deletions src/draw_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ impl DrawTarget {
}
// if we get here, we need to force dst to be monotonic, even though
// we couldn't compute a unit_divide value (probably underflow).
let b = if abs(a - b) < abs(b - c) { a } else { c };
let b = if (a - b).abs() < (b - c).abs() { a } else { c };
curve[1].y = b;
}
self.rasterizer.add_edge(curve[0], curve[2], true, curve[1]);
Expand Down Expand Up @@ -1051,7 +1051,7 @@ impl DrawTarget {
pub fn write_png<P: AsRef<std::path::Path>>(&self, path: P) -> Result<(), png::EncodingError> {
let file = File::create(path)?;

let ref mut w = BufWriter::new(file);
let w = &mut BufWriter::new(file);

let mut encoder = png::Encoder::new(w, self.width as u32, self.height as u32);
encoder.set_color(png::ColorType::RGBA);
Expand Down
15 changes: 5 additions & 10 deletions src/geom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ pub fn intrect<T: Copy>(x1: T, y1: T, x2: T, y2: T) -> euclid::default::Box2D<T>
euclid::default::Box2D::new(euclid::point2(x1, y1), euclid::point2(x2, y2))
}

pub fn abs(a: f32) -> f32 {
if a < 0. {
return -a;
}
return a;
}

// we can do this
pub fn valid_unit_divide(mut numer: f32, mut denom: f32, ratio: &mut f32) -> bool {
if numer < 0. {
Expand All @@ -38,7 +31,8 @@ pub fn valid_unit_divide(mut numer: f32, mut denom: f32, ratio: &mut f32) -> boo
return false;
}
*ratio = r;
return true;

true
}

pub fn is_not_monotonic(a: f32, b: f32, c: f32) -> bool {
Expand All @@ -47,12 +41,13 @@ pub fn is_not_monotonic(a: f32, b: f32, c: f32) -> bool {
if ab < 0. {
bc = -bc;
}
return ab == 0. || bc < 0.;

ab == 0. || bc < 0.
}

fn interp(a: f32, b: f32, t: f32) -> f32 {
debug_assert!(t >= 0. && t <= 1.);
return a + (b - a) * t;
a + (b - a) * t
}

// Skia does a weird thing where it treats arrays of points as castable to array of floats.
Expand Down
20 changes: 7 additions & 13 deletions src/rasterizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,10 @@ impl Rasterizer {
}
}

fn abs(mut value: i32) -> i32 {
if value < 0 {
value = -value;
}
return value;
}

// A cheap version of the "Alpha max plus beta min" algorithm (⍺=1, β=0.5)
fn cheap_distance(mut dx: i32, mut dy: i32) -> i32 {
dx = abs(dx);
dy = abs(dy);
dx = dx.abs();
dy = dy.abs();
// return max + min/2
if dx > dy {
dx + (dy >> 1)
Expand All @@ -229,7 +222,7 @@ fn diff_to_shift(dx: i32, dy: i32) -> i32 {
dist = (dist + (1 << 4)) >> 5;

// each subdivision (shift value) cuts this dist (error) by 1/4
return (32 - ((dist as u32).leading_zeros()) as i32) >> 1;
(32 - ((dist as u32).leading_zeros()) as i32) >> 1
}

// this metric is taken from skia
Expand All @@ -238,7 +231,8 @@ fn compute_curve_steps(e: &Edge) -> i32 {
let dy = (e.control_y << 1) - e.y1 - e.y2;
let shift = diff_to_shift(dx << 4, dy << 4);
assert!(shift >= 0);
return shift;

shift
}

const SAMPLE_SIZE: f32 = (1 << SAMPLE_SHIFT) as f32;
Expand Down Expand Up @@ -381,9 +375,9 @@ impl Rasterizer {
}
}

// add to the begining of the edge start list
// add to the beginning of the edge start list
// if edges are added from left to right
// the'll be in this list from right to left
// they'll be in this list from right to left
// this works out later during insertion
e.next = self.edge_starts[cury as usize];
self.edge_starts[cury as usize] = Some(NonNull::from(e));
Expand Down
2 changes: 1 addition & 1 deletion src/stroke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn bevel(
* This function has a period of 4. e.g. swap(swap(swap(swap(x) == x */
fn swap(a: Vector) -> Vector {
/* one of these needs to be negative. We choose a.x so that we rotate to the right instead of negating */
return Vector::new(a.y, -a.x);
Vector::new(a.y, -a.x)
}

fn unperp(a: Vector) -> Vector {
Expand Down

0 comments on commit 0c810a0

Please sign in to comment.