Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
msanders committed Mar 14, 2023
1 parent 6ab6885 commit c788d81
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
4 changes: 2 additions & 2 deletions examples/screengrab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ fn main() {
.parent()
.unwrap()
.join("screenshot_cropped.png");
let _ = bmp.image
bmp.image
.save(&bmp_path)
.expect("Unable to save screenshot");
let _ = portion
portion
.image
.save(&portion_path)
.expect("Unable to save cropped screenshot");
Expand Down
2 changes: 1 addition & 1 deletion examples/sine_mouse_wave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn sine_mouse_wave() -> Result<(), autopilot::mouse::MouseError> {
let y = (scoped_height * ((TWO_PI * x as f64) / screen_size.width).sin() + scoped_height)
.round();
let duration: u64 = rand::thread_rng().gen_range(1, 3);
autopilot::mouse::move_to(autopilot::geometry::Point::new(x as f64, y as f64))?;
autopilot::mouse::move_to(autopilot::geometry::Point::new(x as f64, y))?;
std::thread::sleep(std::time::Duration::from_millis(duration));
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/alert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fn system_alert(
let message_programs = ["gmessage", "gxmessage", "kmessage", "xmessage"];
for program in &message_programs {
match std::process::Command::new(program)
.args(&args)
.args(args)
.spawn()
.and_then(std::process::Child::wait_with_output)
{
Expand Down
33 changes: 16 additions & 17 deletions src/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,7 @@ fn system_capture_screen_portion(rect: Rect) -> ImageResult<Bitmap> {
let mut img = DynamicImage::new_rgb8(rect.size.width as u32, rect.size.height as u32);
for x in 0..rect.size.width as usize {
for y in 0..rect.size.height as usize {
let offset: usize =
bytewidth as usize * y as usize + bytes_per_pixel as usize * x as usize;
let offset: usize = bytewidth * y + bytes_per_pixel * x;
let (b, g, r) = (buffer[offset], buffer[offset + 1], buffer[offset + 2]);
img.put_pixel(x as u32, y as u32, Rgba([r, g, b, 255]));
}
Expand Down Expand Up @@ -631,7 +630,7 @@ fn macos_load_cgimage(image: &CGImage) -> ImageResult<Bitmap> {
size: CGSize::new(width as CGFloat, height as CGFloat),
};

context.draw_image(rect, &image);
context.draw_image(rect, image);

let buffer: &[u8] = context.data();
let mut dynimage = DynamicImage::new_rgb8(width as u32, height as u32);
Expand Down Expand Up @@ -659,11 +658,11 @@ mod tests {
impl Arbitrary for Bitmap {
fn arbitrary<G: Gen>(g: &mut G) -> Bitmap {
let xs = Vec::<u8>::arbitrary(g);
let scale: f64 = [1.0, 2.0].choose(g).unwrap().clone();
let scale: f64 = *[1.0, 2.0].choose(g).unwrap();
let width: f64 = (xs.len() as f64 / 4.0).floor().sqrt();
let image = RgbaImage::from_raw(width as u32, width as u32, xs).unwrap();
let dynimage = DynamicImage::ImageRgba8(image);
return Bitmap::new(dynimage, Some(scale));
Bitmap::new(dynimage, Some(scale))
}
}

Expand Down Expand Up @@ -715,9 +714,9 @@ mod tests {
)).unwrap();
let pt_a = haystack.find_bitmap(&needle, None, None, None);
let pt_b = haystack.find_bitmap(&needle, None, None, Some(offset_pt));
return TestResult::from_bool(pt_a.is_some() &&
TestResult::from_bool(pt_a.is_some() &&
pt_b.is_some() &&
pt_b.unwrap() == offset_pt);
pt_b.unwrap() == offset_pt)
}
}

Expand All @@ -731,7 +730,7 @@ mod tests {
inverted.invert();
let needle = Bitmap::new(inverted, None);
let pt = haystack.find_bitmap(&needle, None, None, None);
return TestResult::from_bool(pt.is_none());
TestResult::from_bool(pt.is_none())
}
}

Expand All @@ -741,23 +740,23 @@ mod tests {
return TestResult::discard();
}
let mut haystack_img = DynamicImage::new_rgba8(
tile.image.width() as u32 * 2 as u32 + 1,
tile.image.height() as u32 * 2 as u32 + 1
tile.image.width() * 2_u32 + 1,
tile.image.height() * 2_u32 + 1
);
for x in 0..tile.image.width() as u32 * 2 as u32 {
for y in 0..tile.image.height() as u32 * 2 as u32 {
let tile_x = x % tile.image.width() as u32;
let tile_y = y % tile.image.height() as u32;
for x in 0..tile.image.width() * 2_u32 {
for y in 0..tile.image.height() * 2_u32 {
let tile_x = x % tile.image.width();
let tile_y = y % tile.image.height();
haystack_img.put_pixel(
x as u32,
y as u32,
x,
y,
tile.image.get_pixel(tile_x, tile_y)
);
}
}

let haystack = Bitmap::new(haystack_img, Some(tile.scale));
return TestResult::from_bool(haystack.count_of_bitmap(&tile, None, None, None) >= 4);
TestResult::from_bool(haystack.count_of_bitmap(&tile, None, None, None) >= 4)
}
}
}
4 changes: 2 additions & 2 deletions src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl From<Point> for CGPoint {
#[cfg(target_os = "macos")]
impl From<CGPoint> for Point {
fn from(point: CGPoint) -> Point {
Point::new(point.x as f64, point.y as f64)
Point::new(point.x, point.y)
}
}

Expand All @@ -42,7 +42,7 @@ impl From<Size> for CGSize {
#[cfg(target_os = "macos")]
impl From<CGSize> for Size {
fn from(size: CGSize) -> Size {
Size::new(size.width as f64, size.height as f64)
Size::new(size.width, size.height)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn find_bitmap() {
let needle_path = asset_path().join(format!("needle{}.png", idx + 1));
let needle = Bitmap::new(image::open(needle_path).unwrap(), None);
let pt = haystack.find_bitmap(&needle, None, None, None);
assert_eq!(pt.is_some(), true);
assert!(pt.is_some());
}
}

Expand Down

0 comments on commit c788d81

Please sign in to comment.