Skip to content

Commit

Permalink
fix blur offset
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Gabriel committed May 15, 2024
1 parent 9abe971 commit 1dd08bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
10 changes: 9 additions & 1 deletion src/math.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{
f32::consts::PI,
fmt::Display,
ops::{Add, AddAssign, Sub, SubAssign},
ops::{Add, AddAssign, Mul, Sub, SubAssign},
};

#[derive(Default, Debug, Copy, Clone, PartialEq)]
Expand Down Expand Up @@ -90,6 +90,14 @@ impl SubAssign for Vec2D {
}
}

impl Mul<f32> for Vec2D {
type Output = Vec2D;

fn mul(self, rhs: f32) -> Self::Output {
Vec2D::new(self.x * rhs, self.y * rhs)
}
}

impl Display for Vec2D {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "({},{})", self.x, self.y)
Expand Down
13 changes: 6 additions & 7 deletions src/tools/blur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ impl Blur {
) -> Result<ImageId> {
let img = canvas.screenshot()?;

// TODO: review that calculation!
let scaled_width = canvas.width() as f32 / canvas.transform().average_scale();
let dpi = img.width() as f32 / scaled_width;
let transformed_pos = canvas.transform().transform_point(pos.x, pos.y);
let transformed_size = size * canvas.transform().average_scale();

let (buf, width, height) = img
.sub_image(
(pos.x * dpi) as usize,
(pos.y * dpi) as usize,
(size.x * dpi) as usize,
(size.y * dpi) as usize,
transformed_pos.0 as usize,
transformed_pos.1 as usize,
transformed_size.x as usize,
transformed_size.y as usize,
)
.to_contiguous_buf();
let sub = Img::new(buf.into_owned(), width, height);
Expand Down

0 comments on commit 1dd08bb

Please sign in to comment.