Skip to content

Commit

Permalink
fix rectangle snapping
Browse files Browse the repository at this point in the history
  • Loading branch information
edwloef committed Jan 30, 2025
1 parent f2c9b6b commit e10a687
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion core/src/rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,16 @@ impl Rectangle<f32> {
}

/// Snaps the [`Rectangle`] to __unsigned__ integer coordinates.
pub fn snap(self) -> Option<Rectangle<u32>> {
pub fn snap(mut self) -> Option<Rectangle<u32>> {
let fract_x = self.x.fract();
let fract_y = self.y.fract();

self.x -= fract_x;
self.y -= fract_y;

self.width += fract_x;
self.height += fract_y;

let width = self.width as u32;
let height = self.height as u32;

Expand Down

0 comments on commit e10a687

Please sign in to comment.