From ef1a27234d328f96a3908abc107e1cb5038826e3 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 26 Dec 2024 16:38:06 -0800 Subject: [PATCH] utils/geometry: Deprecate `::from_loc_and_size` in favor of a `::new` This new function is the same as `from_loc_and_size`, except it takes concrete types as arguments instead of `impl Into`. This matches `euclid::Rect`'s API, but it also seems a little better to have strong typing without implicit conversion like this. In a few cases it's not obvious that the argument is variable of tuple type, so there is an implied assertion that the coordinate space is right. The use of `#[deprecated]` makes this not entirely urgent for compositors, but uses of this should be updated to `::new`, or other functions like `from_size`. --- anvil/src/drawing.rs | 20 ++-- anvil/src/render.rs | 2 +- anvil/src/shell/grabs.rs | 8 +- anvil/src/shell/mod.rs | 4 +- anvil/src/shell/x11.rs | 10 +- benches/geometry.rs | 4 +- examples/buffer_test.rs | 6 +- smallvil/src/handlers/xdg_shell.rs | 2 +- src/backend/drm/compositor/mod.rs | 2 +- src/backend/renderer/damage/shaper.rs | 20 ++-- src/backend/renderer/element/memory.rs | 2 +- src/backend/renderer/element/solid.rs | 2 +- src/backend/renderer/element/surface.rs | 4 +- src/backend/renderer/element/texture.rs | 2 +- src/backend/renderer/gles/mod.rs | 32 +++--- src/backend/renderer/mod.rs | 2 +- src/backend/renderer/multigpu/mod.rs | 3 +- src/backend/renderer/utils/wayland.rs | 2 +- src/backend/winit/mod.rs | 4 +- src/desktop/space/mod.rs | 2 +- src/desktop/space/wayland/mod.rs | 2 +- src/desktop/wayland/utils.rs | 4 +- src/utils/geometry.rs | 108 ++++++++++-------- src/wayland/compositor/handlers.rs | 12 +- src/wayland/compositor/mod.rs | 2 +- .../input_method/input_method_handle.rs | 2 +- .../input_method_popup_surface.rs | 2 +- src/wayland/shell/xdg/handlers/positioner.rs | 2 +- src/wayland/shell/xdg/handlers/surface.rs | 2 +- src/wayland/viewporter/mod.rs | 2 +- src/xwayland/xwm/mod.rs | 12 +- 31 files changed, 143 insertions(+), 140 deletions(-) diff --git a/anvil/src/drawing.rs b/anvil/src/drawing.rs index d14fdd63a273..1de3d2850945 100644 --- a/anvil/src/drawing.rs +++ b/anvil/src/drawing.rs @@ -211,7 +211,7 @@ where for digit in value_str.chars().map(|d| d.to_digit(10).unwrap()) { let digit_location = dst.loc.to_f64() + offset; let digit_size = Size::::from((22, 35)).to_f64().to_physical(scale); - let dst = Rectangle::from_loc_and_size( + let dst = Rectangle::new( digit_location.to_i32_round(), ((digit_size.to_point() + digit_location).to_i32_round() - digit_location.to_i32_round()) .to_size(), @@ -227,15 +227,15 @@ where .collect::>(); let texture_src: Rectangle = match digit { 9 => Rectangle::from_size((22, 35).into()), - 6 => Rectangle::from_loc_and_size((22, 0), (22, 35)), - 3 => Rectangle::from_loc_and_size((44, 0), (22, 35)), - 1 => Rectangle::from_loc_and_size((66, 0), (22, 35)), - 8 => Rectangle::from_loc_and_size((0, 35), (22, 35)), - 0 => Rectangle::from_loc_and_size((22, 35), (22, 35)), - 2 => Rectangle::from_loc_and_size((44, 35), (22, 35)), - 7 => Rectangle::from_loc_and_size((0, 70), (22, 35)), - 4 => Rectangle::from_loc_and_size((22, 70), (22, 35)), - 5 => Rectangle::from_loc_and_size((44, 70), (22, 35)), + 6 => Rectangle::new((22, 0), (22, 35)), + 3 => Rectangle::new((44, 0), (22, 35)), + 1 => Rectangle::new((66, 0), (22, 35)), + 8 => Rectangle::new((0, 35), (22, 35)), + 0 => Rectangle::new((22, 35), (22, 35)), + 2 => Rectangle::new((44, 35), (22, 35)), + 7 => Rectangle::new((0, 70), (22, 35)), + 4 => Rectangle::new((22, 70), (22, 35)), + 5 => Rectangle::new((44, 70), (22, 35)), _ => unreachable!(), }; diff --git a/anvil/src/render.rs b/anvil/src/render.rs index 6346799a71be..d86dd1ace837 100644 --- a/anvil/src/render.rs +++ b/anvil/src/render.rs @@ -122,7 +122,7 @@ where preview_padding + (preview_padding + preview_size.w) * column as i32, preview_padding + (preview_padding + preview_size.h) * row as i32, )); - let constrain = Rectangle::from_loc_and_size(preview_location, preview_size); + let constrain = Rectangle::new(preview_location, preview_size); constrain_space_element( renderer, window, diff --git a/anvil/src/shell/grabs.rs b/anvil/src/shell/grabs.rs index e776ce19998d..8cdb57da9254 100644 --- a/anvil/src/shell/grabs.rs +++ b/anvil/src/shell/grabs.rs @@ -420,7 +420,7 @@ impl PointerGrab> for PointerResiz #[cfg(feature = "xwayland")] WindowSurface::X11(x11) => { let location = data.space.element_location(&self.window).unwrap(); - x11.configure(Rectangle::from_loc_and_size(location, self.last_window_size)) + x11.configure(Rectangle::new(location, self.last_window_size)) .unwrap(); } } @@ -505,7 +505,7 @@ impl PointerGrab> for PointerResiz data.space.map_element(self.window.clone(), location, true); } - x11.configure(Rectangle::from_loc_and_size(location, self.last_window_size)) + x11.configure(Rectangle::new(location, self.last_window_size)) .unwrap(); let Some(surface) = self.window.wl_surface() else { @@ -718,7 +718,7 @@ impl TouchGrab> for TouchResizeSur data.space.map_element(self.window.clone(), location, true); } - x11.configure(Rectangle::from_loc_and_size(location, self.last_window_size)) + x11.configure(Rectangle::new(location, self.last_window_size)) .unwrap(); let Some(surface) = self.window.wl_surface() else { @@ -817,7 +817,7 @@ impl TouchGrab> for TouchResizeSur #[cfg(feature = "xwayland")] WindowSurface::X11(x11) => { let location = data.space.element_location(&self.window).unwrap(); - x11.configure(Rectangle::from_loc_and_size(location, self.last_window_size)) + x11.configure(Rectangle::new(location, self.last_window_size)) .unwrap(); } } diff --git a/anvil/src/shell/mod.rs b/anvil/src/shell/mod.rs index 6f0f1a45107b..541383ff2376 100644 --- a/anvil/src/shell/mod.rs +++ b/anvil/src/shell/mod.rs @@ -411,7 +411,7 @@ fn place_new_window( let geo = space.output_geometry(&o)?; let map = layer_map_for_output(&o); let zone = map.non_exclusive_zone(); - Some(Rectangle::from_loc_and_size(geo.loc + zone.loc, zone.size)) + Some(Rectangle::new(geo.loc + zone.loc, zone.size)) }) .unwrap_or_else(|| Rectangle::from_size((800, 800).into())); @@ -455,7 +455,7 @@ pub fn fixup_positions(space: &mut Space, pointer_location: Point let geo = space.output_geometry(o)?; let map = layer_map_for_output(o); let zone = map.non_exclusive_zone(); - Some(Rectangle::from_loc_and_size(geo.loc + zone.loc, zone.size)) + Some(Rectangle::new(geo.loc + zone.loc, zone.size)) }) .collect::>(); for window in space.elements() { diff --git a/anvil/src/shell/x11.rs b/anvil/src/shell/x11.rs index 4b126817e391..316ac541bc62 100644 --- a/anvil/src/shell/x11.rs +++ b/anvil/src/shell/x11.rs @@ -367,10 +367,7 @@ impl AnvilState { .and_then(|data| data.restore()) { window - .configure(Rectangle::from_loc_and_size( - initial_window_location, - old_geo.size, - )) + .configure(Rectangle::new(initial_window_location, old_geo.size)) .unwrap(); } } @@ -413,10 +410,7 @@ impl AnvilState { .and_then(|data| data.restore()) { window - .configure(Rectangle::from_loc_and_size( - initial_window_location, - old_geo.size, - )) + .configure(Rectangle::new(initial_window_location, old_geo.size)) .unwrap(); } } diff --git a/benches/geometry.rs b/benches/geometry.rs index 9aa34f493937..5e121dab3ef5 100644 --- a/benches/geometry.rs +++ b/benches/geometry.rs @@ -20,7 +20,7 @@ fn criterion_benchmark(c: &mut Criterion) { let mut rand = rand::thread_rng(); let x = rand.gen_range(0..max_x); let y = rand.gen_range(0..max_y); - let test_element = Rectangle::from_loc_and_size((x, y), element_size); + let test_element = Rectangle::new((x, y).into(), element_size); let x_min = (test_element.loc.x - element_size.w) + 1; let x_max = (test_element.loc.x + element_size.w) - 1; @@ -35,7 +35,7 @@ fn criterion_benchmark(c: &mut Criterion) { .map(|_| { let x = rand.gen_range(x_min..=x_max); let y = rand.gen_range(y_min..=y_max); - Rectangle::from_loc_and_size((x, y), element_size) + Rectangle::new((x, y).into(), element_size) }) .collect::>(); diff --git a/examples/buffer_test.rs b/examples/buffer_test.rs index 511b28284f6e..eb42c57a875a 100644 --- a/examples/buffer_test.rs +++ b/examples/buffer_test.rs @@ -297,19 +297,19 @@ where frame .clear( Color32F::new(0.0, 1.0, 0.0, 1.0), - &[Rectangle::from_loc_and_size((w / 2, 0), (w / 2, h / 2))], + &[Rectangle::new((w / 2, 0).into(), (w / 2, h / 2).into())], ) .expect("Render error"); frame .clear( Color32F::new(0.0, 0.0, 1.0, 1.0), - &[Rectangle::from_loc_and_size((0, h / 2), (w / 2, h / 2))], + &[Rectangle::new((0, h / 2).into(), (w / 2, h / 2).into())], ) .expect("Render error"); frame .clear( Color32F::new(1.0, 1.0, 0.0, 1.0), - &[Rectangle::from_loc_and_size((w / 2, h / 2), (w / 2, h / 2))], + &[Rectangle::new((w / 2, h / 2).into(), (w / 2, h / 2).into())], ) .expect("Render error"); frame diff --git a/smallvil/src/handlers/xdg_shell.rs b/smallvil/src/handlers/xdg_shell.rs index 2819749daa17..64fd622305a0 100644 --- a/smallvil/src/handlers/xdg_shell.rs +++ b/smallvil/src/handlers/xdg_shell.rs @@ -111,7 +111,7 @@ impl XdgShellHandler for Smallvil { start_data, window, edges.into(), - Rectangle::from_loc_and_size(initial_window_location, initial_window_size), + Rectangle::new(initial_window_location, initial_window_size), ); pointer.set_grab(self, grab, serial, Focus::Clear); diff --git a/src/backend/drm/compositor/mod.rs b/src/backend/drm/compositor/mod.rs index 1e5ba18a818a..dccc8128ceca 100644 --- a/src/backend/drm/compositor/mod.rs +++ b/src/backend/drm/compositor/mod.rs @@ -3533,7 +3533,7 @@ where }; let src = Rectangle::from_size(cursor_buffer_size).to_f64(); - let dst = Rectangle::from_loc_and_size(cursor_plane_location, cursor_plane_size); + let dst = Rectangle::new(cursor_plane_location, cursor_plane_size); let config = PlaneConfig { properties: PlaneProperties { diff --git a/src/backend/renderer/damage/shaper.rs b/src/backend/renderer/damage/shaper.rs index 7cb73936eb58..c83ed03c626e 100644 --- a/src/backend/renderer/damage/shaper.rs +++ b/src/backend/renderer/damage/shaper.rs @@ -78,7 +78,7 @@ impl DamageShaper { let bbox_w = x_max - x_min; let bbox_h = y_max - y_min; - let damage_bbox = Rectangle::::from_loc_and_size((x_min, y_min), (bbox_w, bbox_h)); + let damage_bbox = Rectangle::::new((x_min, y_min).into(), (bbox_w, bbox_h).into()); // Damage the current bounding box when there's a damage rect covering near all the area. if max_damage_area as f32 / (damage_bbox.size.w * damage_bbox.size.h) as f32 @@ -200,7 +200,7 @@ impl DamageShaper { for y in (bbox.loc.y..bbox.loc.y + bbox.size.h).step_by(tile_size.h as usize) { // NOTE the in_damage is constrained to the `bbox`, so it can't go outside // the tile, even though some tiles could go outside the `bbox`. - let bbox = Rectangle::::from_loc_and_size((x, y), tile_size); + let bbox = Rectangle::::new((x, y).into(), tile_size); let mut tile = Tile { bbox, damage: None, @@ -327,12 +327,12 @@ mod tests { #[test] fn tile_shaping() { let mut damage = vec![ - Rectangle::::from_loc_and_size((98, 406), (36, 48)), - Rectangle::::from_loc_and_size((158, 502), (828, 168)), - Rectangle::::from_loc_and_size((122, 694), (744, 528)), - Rectangle::::from_loc_and_size((194, 1318), (420, 72)), - Rectangle::::from_loc_and_size((146, 1414), (312, 48)), - Rectangle::::from_loc_and_size((32, 406), (108, 1152)), + Rectangle::::new((98, 406).into(), (36, 48).into()), + Rectangle::::new((158, 502).into(), (828, 168).into()), + Rectangle::::new((122, 694).into(), (744, 528).into()), + Rectangle::::new((194, 1318).into(), (420, 72).into()), + Rectangle::::new((146, 1414).into(), (312, 48).into()), + Rectangle::::new((32, 406).into(), (108, 1152).into()), ]; let mut shaper = shaper(); @@ -383,7 +383,7 @@ mod tests { for x in 0..w { for y in 0..h { - let rect = Rectangle::::from_loc_and_size((x, y), (1, 1)); + let rect = Rectangle::::new((x, y).into(), (1, 1).into()); damage.push(rect); } } @@ -398,7 +398,7 @@ mod tests { let w1 = 216; let h1 = 144; let overlap1 = Rectangle::::from_size((w1, h1).into()); - let overlap2 = Rectangle::::from_loc_and_size((w1, h1), (w - w1, h - h1)); + let overlap2 = Rectangle::::new((w1, h1).into(), (w - w1, h - h1).into()); damage.push(overlap1); damage.push(overlap2); diff --git a/src/backend/renderer/element/memory.rs b/src/backend/renderer/element/memory.rs index 6944fe19e7dc..85a48ba2d4c0 100644 --- a/src/backend/renderer/element/memory.rs +++ b/src/backend/renderer/element/memory.rs @@ -660,7 +660,7 @@ impl Element for MemoryRenderBufferRenderElement { } fn geometry(&self, scale: Scale) -> Rectangle { - Rectangle::from_loc_and_size(self.location.to_i32_round(), self.physical_size(scale)) + Rectangle::new(self.location.to_i32_round(), self.physical_size(scale)) } fn damage_since(&self, scale: Scale, commit: Option) -> DamageSet { diff --git a/src/backend/renderer/element/solid.rs b/src/backend/renderer/element/solid.rs index 62d29c23519c..95b06b887e91 100644 --- a/src/backend/renderer/element/solid.rs +++ b/src/backend/renderer/element/solid.rs @@ -251,7 +251,7 @@ impl SolidColorRenderElement { alpha: f32, kind: Kind, ) -> Self { - let geo = Rectangle::from_loc_and_size(location, buffer.size.to_physical_precise_round(scale)); + let geo = Rectangle::new(location.into(), buffer.size.to_physical_precise_round(scale)); let color = buffer.color * alpha; Self::new(buffer.id.clone(), geo, buffer.commit, color, kind) } diff --git a/src/backend/renderer/element/surface.rs b/src/backend/renderer/element/surface.rs index e1e782e94d9e..8955e463d9f7 100644 --- a/src/backend/renderer/element/surface.rs +++ b/src/backend/renderer/element/surface.rs @@ -449,7 +449,7 @@ impl Element for WaylandSurfaceRenderElement { } fn geometry(&self, scale: Scale) -> Rectangle { - Rectangle::from_loc_and_size(self.location.to_i32_round(), self.size(scale)) + Rectangle::new(self.location.to_i32_round(), self.size(scale)) } fn src(&self) -> Rectangle { @@ -511,7 +511,7 @@ impl Element for WaylandSurfaceRenderElement { let size = ((r.size.to_f64().to_physical(scale).to_point() + self.location).to_i32_round() - self.location.to_i32_round()) .to_size(); - Rectangle::from_loc_and_size(loc, size) + Rectangle::new(loc, size) }) .collect::>() } diff --git a/src/backend/renderer/element/texture.rs b/src/backend/renderer/element/texture.rs index f17ba9428bed..d10c4c611a2b 100644 --- a/src/backend/renderer/element/texture.rs +++ b/src/backend/renderer/element/texture.rs @@ -818,7 +818,7 @@ where } fn geometry(&self, scale: Scale) -> Rectangle { - Rectangle::from_loc_and_size(self.location.to_i32_round(), self.physical_size(scale)) + Rectangle::new(self.location.to_i32_round(), self.physical_size(scale)) } fn transform(&self) -> Transform { diff --git a/src/backend/renderer/gles/mod.rs b/src/backend/renderer/gles/mod.rs index ad557b88ea39..8bb3cd5d28d5 100644 --- a/src/backend/renderer/gles/mod.rs +++ b/src/backend/renderer/gles/mod.rs @@ -2356,7 +2356,7 @@ impl GlesFrame<'_> { .size .clamp((0, 0), (dest_size.to_point() - rect_constrained_loc).to_size()); - let rect = Rectangle::from_loc_and_size(rect_constrained_loc, rect_clamped_size); + let rect = Rectangle::new(rect_constrained_loc, rect_clamped_size); [ (dest.loc.x + rect.loc.x) as f32, (dest.loc.y + rect.loc.y) as f32, @@ -2373,7 +2373,7 @@ impl GlesFrame<'_> { .size .clamp((0, 0), (dest_size.to_point() - rect_constrained_loc).to_size()); - let rect = Rectangle::from_loc_and_size(rect_constrained_loc, rect_clamped_size); + let rect = Rectangle::new(rect_constrained_loc, rect_clamped_size); // Add the 4 f32s per damage rectangle for each of the 6 vertices. (0..6).flat_map(move |_| { [ @@ -2492,7 +2492,7 @@ impl GlesFrame<'_> { .size .clamp((0, 0), (dest_size.to_point() - rect_constrained_loc).to_size()); - let rect = Rectangle::from_loc_and_size(rect_constrained_loc, rect_clamped_size); + let rect = Rectangle::new(rect_constrained_loc, rect_clamped_size); [ rect.loc.x as f32, rect.loc.y as f32, @@ -2775,7 +2775,7 @@ impl GlesFrame<'_> { .size .clamp((0, 0), (dest_size.to_point() - rect_constrained_loc).to_size()); - let rect = Rectangle::from_loc_and_size(rect_constrained_loc, rect_clamped_size); + let rect = Rectangle::new(rect_constrained_loc, rect_clamped_size); [ rect.loc.x as f32, rect.loc.y as f32, @@ -2792,7 +2792,7 @@ impl GlesFrame<'_> { .size .clamp((0, 0), (dest_size.to_point() - rect_constrained_loc).to_size()); - let rect = Rectangle::from_loc_and_size(rect_constrained_loc, rect_clamped_size); + let rect = Rectangle::new(rect_constrained_loc, rect_clamped_size); // Add the 4 f32s per damage rectangle for each of the 6 vertices. (0..6).flat_map(move |_| { [ @@ -2992,7 +2992,7 @@ mod tests { #[test] fn texture_normal_double_size() { let src: Rectangle = Rectangle::from_size((1000f64, 500f64).into()); - let dest: Rectangle = Rectangle::from_loc_and_size((442, 144), (500, 250)); + let dest: Rectangle = Rectangle::new((442, 144).into(), (500, 250).into()); let texture_size: Size = Size::from((1000, 500)); let transform = Transform::Normal; @@ -3011,8 +3011,8 @@ mod tests { #[test] fn texture_scaler_crop() { - let src: Rectangle = Rectangle::from_loc_and_size((42.5f64, 50.5f64), (110f64, 154f64)); - let dest: Rectangle = Rectangle::from_loc_and_size((813, 214), (55, 77)); + let src: Rectangle = Rectangle::new((42.5f64, 50.5f64).into(), (110f64, 154f64).into()); + let dest: Rectangle = Rectangle::new((813, 214).into(), (55, 77).into()); let texture_size: Size = Size::from((842, 674)); let transform = Transform::Normal; @@ -3044,7 +3044,7 @@ mod tests { #[test] fn texture_normal() { let src: Rectangle = Rectangle::from_size((500f64, 250f64).into()); - let dest: Rectangle = Rectangle::from_loc_and_size((442, 144), (500, 250)); + let dest: Rectangle = Rectangle::new((442, 144).into(), (500, 250).into()); let texture_size: Size = Size::from((500, 250)); let transform = Transform::Normal; @@ -3064,7 +3064,7 @@ mod tests { #[test] fn texture_flipped() { let src: Rectangle = Rectangle::from_size((500f64, 250f64).into()); - let dest: Rectangle = Rectangle::from_loc_and_size((442, 144), (500, 250)); + let dest: Rectangle = Rectangle::new((442, 144).into(), (500, 250).into()); let texture_size: Size = Size::from((500, 250)); let transform = Transform::Flipped; @@ -3084,7 +3084,7 @@ mod tests { #[test] fn texture_90() { let src: Rectangle = Rectangle::from_size((250f64, 500f64).into()); - let dest: Rectangle = Rectangle::from_loc_and_size((442, 144), (500, 250)); + let dest: Rectangle = Rectangle::new((442, 144).into(), (500, 250).into()); let texture_size: Size = Size::from((250, 500)); let transform = Transform::_90; @@ -3104,7 +3104,7 @@ mod tests { #[test] fn texture_180() { let src: Rectangle = Rectangle::from_size((500f64, 250f64).into()); - let dest: Rectangle = Rectangle::from_loc_and_size((442, 144), (500, 250)); + let dest: Rectangle = Rectangle::new((442, 144).into(), (500, 250).into()); let texture_size: Size = Size::from((500, 250)); let transform = Transform::_180; @@ -3124,7 +3124,7 @@ mod tests { #[test] fn texture_270() { let src: Rectangle = Rectangle::from_size((250f64, 500f64).into()); - let dest: Rectangle = Rectangle::from_loc_and_size((442, 144), (500, 250)); + let dest: Rectangle = Rectangle::new((442, 144).into(), (500, 250).into()); let texture_size: Size = Size::from((250, 500)); let transform = Transform::_270; @@ -3144,7 +3144,7 @@ mod tests { #[test] fn texture_flipped_90() { let src: Rectangle = Rectangle::from_size((250f64, 500f64).into()); - let dest: Rectangle = Rectangle::from_loc_and_size((442, 144), (500, 250)); + let dest: Rectangle = Rectangle::new((442, 144).into(), (500, 250).into()); let texture_size: Size = Size::from((250, 500)); let transform = Transform::Flipped90; @@ -3164,7 +3164,7 @@ mod tests { #[test] fn texture_flipped_180() { let src: Rectangle = Rectangle::from_size((500f64, 250f64).into()); - let dest: Rectangle = Rectangle::from_loc_and_size((442, 144), (500, 250)); + let dest: Rectangle = Rectangle::new((442, 144).into(), (500, 250).into()); let texture_size: Size = Size::from((500, 250)); let transform = Transform::Flipped180; @@ -3184,7 +3184,7 @@ mod tests { #[test] fn texture_flipped_270() { let src: Rectangle = Rectangle::from_size((250f64, 500f64).into()); - let dest: Rectangle = Rectangle::from_loc_and_size((442, 144), (500, 250)); + let dest: Rectangle = Rectangle::new((442, 144).into(), (500, 250).into()); let texture_size: Size = Size::from((250, 500)); let transform = Transform::Flipped270; diff --git a/src/backend/renderer/mod.rs b/src/backend/renderer/mod.rs index 8cc9fcb0377c..7318acd506c7 100644 --- a/src/backend/renderer/mod.rs +++ b/src/backend/renderer/mod.rs @@ -207,7 +207,7 @@ pub trait Frame { self.render_texture_from_to( texture, Rectangle::from_size(texture.size()).to_f64(), - Rectangle::from_loc_and_size( + Rectangle::new( pos, texture .size() diff --git a/src/backend/renderer/multigpu/mod.rs b/src/backend/renderer/multigpu/mod.rs index 621839a19a54..035ce3b24acc 100644 --- a/src/backend/renderer/multigpu/mod.rs +++ b/src/backend/renderer/multigpu/mod.rs @@ -1339,8 +1339,7 @@ where let dst = damage_rect .to_logical(1, Transform::Normal, &buffer_size) .to_physical(1); - let src = Rectangle::from_loc_and_size(damage_rect.loc - rect.loc, damage_rect.size) - .to_f64(); + let src = Rectangle::new(damage_rect.loc - rect.loc, damage_rect.size).to_f64(); let damage = &[Rectangle::from_size(dst.size)]; frame .clear(Color32F::TRANSPARENT, &[dst]) diff --git a/src/backend/renderer/utils/wayland.rs b/src/backend/renderer/utils/wayland.rs index 35a6cee43465..e72e221facec 100644 --- a/src/backend/renderer/utils/wayland.rs +++ b/src/backend/renderer/utils/wayland.rs @@ -226,7 +226,7 @@ impl RendererSurfaceState { .size .clamp((0, 0), (dest_size.to_point() - rect_constrained_loc).to_size()); - let rect = Rectangle::from_loc_and_size(rect_constrained_loc, rect_clamped_size); + let rect = Rectangle::new(rect_constrained_loc, rect_clamped_size); (kind, rect) }) diff --git a/src/backend/winit/mod.rs b/src/backend/winit/mod.rs index 15808e4dea09..9458eb39629d 100644 --- a/src/backend/winit/mod.rs +++ b/src/backend/winit/mod.rs @@ -339,8 +339,8 @@ where let damage = damage .iter() .map(|rect| { - Rectangle::from_loc_and_size( - (rect.loc.x, bind_size.h - rect.loc.y - rect.size.h), + Rectangle::new( + (rect.loc.x, bind_size.h - rect.loc.y - rect.size.h).into(), rect.size, ) }) diff --git a/src/desktop/space/mod.rs b/src/desktop/space/mod.rs index 23512b48e352..7a47c0ac4b1e 100644 --- a/src/desktop/space/mod.rs +++ b/src/desktop/space/mod.rs @@ -293,7 +293,7 @@ impl Space { let transform: Transform = o.current_transform(); let location = output_location(self.id, o); o.current_mode().map(|mode| { - Rectangle::from_loc_and_size( + Rectangle::new( location, transform .transform_size(mode.size) diff --git a/src/desktop/space/wayland/mod.rs b/src/desktop/space/wayland/mod.rs index 354a58099cfe..ce76ec00f5d4 100644 --- a/src/desktop/space/wayland/mod.rs +++ b/src/desktop/space/wayland/mod.rs @@ -62,7 +62,7 @@ pub fn output_update(output: &Output, output_overlap: Option>, { let location = location.into(); - let mut bounding_box = Rectangle::from_loc_and_size(location, (0, 0)); + let mut bounding_box = Rectangle::new(location, (0, 0).into()); with_surface_tree_downward( surface, location, @@ -74,7 +74,7 @@ where if let Some(surface_view) = data.and_then(|d| d.lock().unwrap().surface_view) { loc += surface_view.offset; // Update the bounding box. - bounding_box = bounding_box.merge(Rectangle::from_loc_and_size(loc, surface_view.dst)); + bounding_box = bounding_box.merge(Rectangle::new(loc, surface_view.dst)); TraversalAction::DoChildren(loc) } else { diff --git a/src/utils/geometry.rs b/src/utils/geometry.rs index d650e0561d8e..88a536fc03bd 100644 --- a/src/utils/geometry.rs +++ b/src/utils/geometry.rs @@ -1116,6 +1116,7 @@ impl Rectangle { impl Rectangle { /// Create a new [`Rectangle`] from the coordinates of its top-left corner and its dimensions + #[deprecated(note = "use new or from_size")] #[inline] pub fn from_loc_and_size(loc: impl Into>, size: impl Into>) -> Self { Rectangle { @@ -1124,6 +1125,12 @@ impl Rectangle { } } + /// Create a new [`Rectangle`] from the coordinates of its top-left corner and its dimensions + #[inline] + pub fn new(loc: Point, size: Size) -> Self { + Rectangle { loc, size } + } + /// Create a new [`Rectangle`] from the coordinates of its top-left corner and its bottom-right corner #[inline] pub fn from_extemities( @@ -1290,32 +1297,35 @@ impl Rectangle { continue; } - let top_rect = Rectangle::from_loc_and_size( + let top_rect = Rectangle::new( item.loc, - (item.size.w, intersection.loc.y.saturating_sub(item.loc.y)), + (item.size.w, intersection.loc.y.saturating_sub(item.loc.y)).into(), ); - let left_rect: Rectangle = Rectangle::from_loc_and_size( - (item.loc.x, intersection.loc.y), - (intersection.loc.x.saturating_sub(item.loc.x), intersection.size.h), + let left_rect: Rectangle = Rectangle::new( + (item.loc.x, intersection.loc.y).into(), + (intersection.loc.x.saturating_sub(item.loc.x), intersection.size.h).into(), ); - let right_rect: Rectangle = Rectangle::from_loc_and_size( + let right_rect: Rectangle = Rectangle::new( ( intersection.loc.x.saturating_add(intersection.size.w), intersection.loc.y, - ), + ) + .into(), ( (item.loc.x.saturating_add(item.size.w)) .saturating_sub(intersection.loc.x.saturating_add(intersection.size.w)), intersection.size.h, - ), + ) + .into(), ); - let bottom_rect: Rectangle = Rectangle::from_loc_and_size( - (item.loc.x, intersection.loc.y.saturating_add(intersection.size.h)), + let bottom_rect: Rectangle = Rectangle::new( + (item.loc.x, intersection.loc.y.saturating_add(intersection.size.h)).into(), ( item.size.w, (item.loc.y.saturating_add(item.size.h)) .saturating_sub(intersection.loc.y.saturating_add(intersection.size.h)), - ), + ) + .into(), ); if !top_rect.is_empty() { @@ -1632,7 +1642,7 @@ impl Transform { Transform::Flipped270 => (rect.loc.y, rect.loc.x).into(), }; - Rectangle::from_loc_and_size(loc, size) + Rectangle::new(loc, size) } /// Returns true if the transformation would flip contents @@ -1699,7 +1709,7 @@ mod tests { #[test] fn transform_rect_ident() { - let rect = Rectangle::::from_loc_and_size((10, 20), (30, 40)); + let rect = Rectangle::::new((10, 20).into(), (30, 40).into()); let size = Size::from((70, 90)); let transform = Transform::Normal; @@ -1708,112 +1718,112 @@ mod tests { #[test] fn transform_rect_90() { - let rect = Rectangle::::from_loc_and_size((10, 20), (30, 40)); + let rect = Rectangle::::new((10, 20).into(), (30, 40).into()); let size = Size::from((70, 90)); let transform = Transform::_90; assert_eq!( - Rectangle::from_loc_and_size((30, 10), (40, 30)), + Rectangle::new((30, 10).into(), (40, 30).into()), transform.transform_rect_in(rect, &size) ) } #[test] fn transform_rect_180() { - let rect = Rectangle::::from_loc_and_size((10, 20), (30, 40)); + let rect = Rectangle::::new((10, 20).into(), (30, 40).into()); let size = Size::from((70, 90)); let transform = Transform::_180; assert_eq!( - Rectangle::from_loc_and_size((30, 30), (30, 40)), + Rectangle::new((30, 30).into(), (30, 40).into()), transform.transform_rect_in(rect, &size) ) } #[test] fn transform_rect_270() { - let rect = Rectangle::::from_loc_and_size((10, 20), (30, 40)); + let rect = Rectangle::::new((10, 20).into(), (30, 40).into()); let size = Size::from((70, 90)); let transform = Transform::_270; assert_eq!( - Rectangle::from_loc_and_size((20, 30), (40, 30)), + Rectangle::new((20, 30).into(), (40, 30).into()), transform.transform_rect_in(rect, &size) ) } #[test] fn transform_rect_f() { - let rect = Rectangle::::from_loc_and_size((10, 20), (30, 40)); + let rect = Rectangle::::new((10, 20).into(), (30, 40).into()); let size = Size::from((70, 90)); let transform = Transform::Flipped; assert_eq!( - Rectangle::from_loc_and_size((30, 20), (30, 40)), + Rectangle::new((30, 20).into(), (30, 40).into()), transform.transform_rect_in(rect, &size) ) } #[test] fn transform_rect_f90() { - let rect = Rectangle::::from_loc_and_size((10, 20), (30, 40)); + let rect = Rectangle::::new((10, 20).into(), (30, 40).into()); let size = Size::from((70, 80)); let transform = Transform::Flipped90; assert_eq!( - Rectangle::from_loc_and_size((20, 30), (40, 30)), + Rectangle::new((20, 30).into(), (40, 30).into()), transform.transform_rect_in(rect, &size) ) } #[test] fn transform_rect_f180() { - let rect = Rectangle::::from_loc_and_size((10, 20), (30, 40)); + let rect = Rectangle::::new((10, 20).into(), (30, 40).into()); let size = Size::from((70, 90)); let transform = Transform::Flipped180; assert_eq!( - Rectangle::from_loc_and_size((10, 30), (30, 40)), + Rectangle::new((10, 30).into(), (30, 40).into()), transform.transform_rect_in(rect, &size) ) } #[test] fn transform_rect_f270() { - let rect = Rectangle::::from_loc_and_size((10, 20), (30, 40)); + let rect = Rectangle::::new((10, 20).into(), (30, 40).into()); let size = Size::from((70, 90)); let transform = Transform::Flipped270; assert_eq!( - Rectangle::from_loc_and_size((20, 10), (40, 30)), + Rectangle::new((20, 10).into(), (40, 30).into()), transform.transform_rect_in(rect, &size) ) } #[test] fn rectangle_contains_rect_itself() { - let rect = Rectangle::::from_loc_and_size((10, 20), (30, 40)); + let rect = Rectangle::::new((10, 20).into(), (30, 40).into()); assert!(rect.contains_rect(rect)); } #[test] fn rectangle_contains_rect_outside() { - let first = Rectangle::::from_loc_and_size((10, 20), (30, 40)); - let second = Rectangle::::from_loc_and_size((41, 61), (30, 40)); + let first = Rectangle::::new((10, 20).into(), (30, 40).into()); + let second = Rectangle::::new((41, 61).into(), (30, 40).into()); assert!(!first.contains_rect(second)); } #[test] fn rectangle_contains_rect_extends() { - let first = Rectangle::::from_loc_and_size((10, 20), (30, 40)); - let second = Rectangle::::from_loc_and_size((10, 20), (30, 45)); + let first = Rectangle::::new((10, 20).into(), (30, 40).into()); + let second = Rectangle::::new((10, 20).into(), (30, 45).into()); assert!(!first.contains_rect(second)); } #[test] fn rectangle_subtract_full() { let outer = Rectangle::::from_size((100, 100).into()); - let inner = Rectangle::::from_loc_and_size((-10, -10), (1000, 1000)); + let inner = Rectangle::::new((-10, -10).into(), (1000, 1000).into()); let rects = outer.subtract_rect(inner); assert_eq!(rects, vec![]) @@ -1822,7 +1832,7 @@ mod tests { #[test] fn rectangle_subtract_center_hole() { let outer = Rectangle::::from_size((100, 100).into()); - let inner = Rectangle::::from_loc_and_size((10, 10), (80, 80)); + let inner = Rectangle::::new((10, 10).into(), (80, 80).into()); let rects = outer.subtract_rect(inner); assert_eq!( @@ -1831,11 +1841,11 @@ mod tests { // Top rect Rectangle::::from_size((100, 10).into()), // Left rect - Rectangle::::from_loc_and_size((0, 10), (10, 80)), + Rectangle::::new((0, 10).into(), (10, 80).into()), // Right rect - Rectangle::::from_loc_and_size((90, 10), (10, 80)), + Rectangle::::new((90, 10).into(), (10, 80).into()), // Bottom rect - Rectangle::::from_loc_and_size((0, 90), (100, 10)), + Rectangle::::new((0, 90).into(), (100, 10).into()), ] ) } @@ -1843,14 +1853,14 @@ mod tests { #[test] fn rectangle_subtract_full_top() { let outer = Rectangle::::from_size((100, 100).into()); - let inner = Rectangle::::from_loc_and_size((0, -20), (100, 100)); + let inner = Rectangle::::new((0, -20).into(), (100, 100).into()); let rects = outer.subtract_rect(inner); assert_eq!( rects, vec![ // Bottom rect - Rectangle::::from_loc_and_size((0, 80), (100, 20)), + Rectangle::::new((0, 80).into(), (100, 20).into()), ] ) } @@ -1858,7 +1868,7 @@ mod tests { #[test] fn rectangle_subtract_full_bottom() { let outer = Rectangle::::from_size((100, 100).into()); - let inner = Rectangle::::from_loc_and_size((0, 20), (100, 100)); + let inner = Rectangle::::new((0, 20).into(), (100, 100).into()); let rects = outer.subtract_rect(inner); assert_eq!( @@ -1873,14 +1883,14 @@ mod tests { #[test] fn rectangle_subtract_full_left() { let outer = Rectangle::::from_size((100, 100).into()); - let inner = Rectangle::::from_loc_and_size((-20, 0), (100, 100)); + let inner = Rectangle::::new((-20, 0).into(), (100, 100).into()); let rects = outer.subtract_rect(inner); assert_eq!( rects, vec![ // Right rect - Rectangle::::from_loc_and_size((80, 0), (20, 100)), + Rectangle::::new((80, 0).into(), (20, 100).into()), ] ) } @@ -1888,7 +1898,7 @@ mod tests { #[test] fn rectangle_subtract_full_right() { let outer = Rectangle::::from_size((100, 100).into()); - let inner = Rectangle::::from_loc_and_size((20, 0), (100, 100)); + let inner = Rectangle::::new((20, 0).into(), (100, 100).into()); let rects = outer.subtract_rect(inner); assert_eq!( @@ -1902,42 +1912,42 @@ mod tests { #[test] fn rectangle_overlaps_or_touches_top() { - let top = Rectangle::::from_loc_and_size((0, -24), (800, 24)); + let top = Rectangle::::new((0, -24).into(), (800, 24).into()); let main = Rectangle::::from_size((800, 600).into()); assert!(main.overlaps_or_touches(top)); } #[test] fn rectangle_overlaps_or_touches_left() { - let left = Rectangle::::from_loc_and_size((-4, -24), (4, 624)); + let left = Rectangle::::new((-4, -24).into(), (4, 624).into()); let main = Rectangle::::from_size((800, 600).into()); assert!(main.overlaps_or_touches(left)); } #[test] fn rectangle_overlaps_or_touches_right() { - let right = Rectangle::::from_loc_and_size((800, -24), (4, 624)); + let right = Rectangle::::new((800, -24).into(), (4, 624).into()); let main = Rectangle::::from_size((800, 600).into()); assert!(main.overlaps_or_touches(right)); } #[test] fn rectangle_no_overlap_top() { - let top = Rectangle::::from_loc_and_size((0, -24), (800, 24)); + let top = Rectangle::::new((0, -24).into(), (800, 24).into()); let main = Rectangle::::from_size((800, 600).into()); assert!(!main.overlaps(top)); } #[test] fn rectangle_no_overlap_left() { - let left = Rectangle::::from_loc_and_size((-4, -24), (4, 624)); + let left = Rectangle::::new((-4, -24).into(), (4, 624).into()); let main = Rectangle::::from_size((800, 600).into()); assert!(!main.overlaps(left)); } #[test] fn rectangle_no_overlap_right() { - let right = Rectangle::::from_loc_and_size((800, -24), (4, 624)); + let right = Rectangle::::new((800, -24).into(), (4, 624).into()); let main = Rectangle::::from_size((800, 600).into()); assert!(!main.overlaps(right)); } diff --git a/src/wayland/compositor/handlers.rs b/src/wayland/compositor/handlers.rs index 36a5b1e9975e..dbbb3e909ced 100644 --- a/src/wayland/compositor/handlers.rs +++ b/src/wayland/compositor/handlers.rs @@ -219,7 +219,7 @@ where .pending() .damage .push(Damage::Surface( - Rectangle::::from_loc_and_size((x, y), (width, height)) + Rectangle::::new((x, y).into(), (width, height).into()) .to_logical(client_scale), )); }); @@ -307,9 +307,9 @@ where .get::() .pending() .damage - .push(Damage::Buffer(Rectangle::from_loc_and_size( - (x, y), - (width, height), + .push(Damage::Buffer(Rectangle::new( + (x, y).into(), + (width, height).into(), ))) }); } @@ -388,11 +388,11 @@ where match request { wl_region::Request::Add { x, y, width, height } => guard.rects.push(( RectangleKind::Add, - Rectangle::::from_loc_and_size((x, y), (width, height)).to_logical(client_scale), + Rectangle::::new((x, y).into(), (width, height).into()).to_logical(client_scale), )), wl_region::Request::Subtract { x, y, width, height } => guard.rects.push(( RectangleKind::Subtract, - Rectangle::::from_loc_and_size((x, y), (width, height)).to_logical(client_scale), + Rectangle::::new((x, y).into(), (width, height).into()).to_logical(client_scale), )), wl_region::Request::Destroy => { // all is handled by our destructor diff --git a/src/wayland/compositor/mod.rs b/src/wayland/compositor/mod.rs index 739e832b79fb..18bd7e60264e 100644 --- a/src/wayland/compositor/mod.rs +++ b/src/wayland/compositor/mod.rs @@ -793,7 +793,7 @@ mod tests { rects: vec![ (RectangleKind::Add, Rectangle::from_size((10, 10).into())), (RectangleKind::Subtract, Rectangle::from_size((5, 5).into())), - (RectangleKind::Add, Rectangle::from_loc_and_size((2, 2), (2, 2))), + (RectangleKind::Add, Rectangle::new((2, 2).into(), (2, 2).into())), ], }; diff --git a/src/wayland/input_method/input_method_handle.rs b/src/wayland/input_method/input_method_handle.rs index 4c635b59ffae..b33949c70160 100644 --- a/src/wayland/input_method/input_method_handle.rs +++ b/src/wayland/input_method/input_method_handle.rs @@ -109,7 +109,7 @@ impl InputMethodHandle { height: i32, ) { let mut inner = self.inner.lock().unwrap(); - inner.popup_handle.rectangle = Rectangle::from_loc_and_size((x, y), (width, height)); + inner.popup_handle.rectangle = Rectangle::new((x, y).into(), (width, height).into()); let mut popup_surface = match inner.popup_handle.surface.clone() { Some(popup_surface) => popup_surface, diff --git a/src/wayland/input_method/input_method_popup_surface.rs b/src/wayland/input_method/input_method_popup_surface.rs index 3045559e27ed..d81d8492fc5f 100644 --- a/src/wayland/input_method/input_method_popup_surface.rs +++ b/src/wayland/input_method/input_method_popup_surface.rs @@ -101,7 +101,7 @@ impl PopupSurface { /// /// [`location`]: Self::location pub fn set_text_input_rectangle(&mut self, x: i32, y: i32, width: i32, height: i32) { - *self.rectangle.lock().unwrap() = Rectangle::from_loc_and_size((x, y), (width, height)); + *self.rectangle.lock().unwrap() = Rectangle::new((x, y).into(), (width, height).into()); *self.location.lock().unwrap() = (x, y).into(); self.surface_role.text_input_rectangle(x, y, width, height); } diff --git a/src/wayland/shell/xdg/handlers/positioner.rs b/src/wayland/shell/xdg/handlers/positioner.rs index c5698fcdb7d1..606b00e4500f 100644 --- a/src/wayland/shell/xdg/handlers/positioner.rs +++ b/src/wayland/shell/xdg/handlers/positioner.rs @@ -52,7 +52,7 @@ where "Invalid size for positioner's anchor rectangle.", ); } else { - state.anchor_rect = Rectangle::from_loc_and_size((x, y), (width, height)); + state.anchor_rect = Rectangle::new((x, y).into(), (width, height).into()); } } xdg_positioner::Request::SetAnchor { anchor } => { diff --git a/src/wayland/shell/xdg/handlers/surface.rs b/src/wayland/shell/xdg/handlers/surface.rs index 07b4725b0924..3ae3a79e954b 100644 --- a/src/wayland/shell/xdg/handlers/surface.rs +++ b/src/wayland/shell/xdg/handlers/surface.rs @@ -255,7 +255,7 @@ where compositor::with_states(surface, |states| { states.cached_state.get::().pending().geometry = - Some(Rectangle::from_loc_and_size((x, y), (width, height))); + Some(Rectangle::new((x, y).into(), (width, height).into())); }); } xdg_surface::Request::AckConfigure { serial } => { diff --git a/src/wayland/viewporter/mod.rs b/src/wayland/viewporter/mod.rs index 65bae14bd329..ed9a2570a345 100644 --- a/src/wayland/viewporter/mod.rs +++ b/src/wayland/viewporter/mod.rs @@ -251,7 +251,7 @@ where let src = if is_unset { None } else { - let src = Rectangle::from_loc_and_size((x, y), (width, height)); + let src = Rectangle::new((x, y).into(), (width, height).into()); trace!(surface = ?surface, src = ?src, "setting surface viewport src"); Some(src) }; diff --git a/src/xwayland/xwm/mod.rs b/src/xwayland/xwm/mod.rs index 0549aa17d514..52fd2c686bb0 100644 --- a/src/xwayland/xwm/mod.rs +++ b/src/xwayland/xwm/mod.rs @@ -1352,9 +1352,9 @@ where } let geo = conn.get_geometry(n.window)?.reply()?; - let geometry = Rectangle::::from_loc_and_size( - (geo.x as i32, geo.y as i32), - (geo.width as i32, geo.height as i32), + let geometry = Rectangle::::new( + (geo.x as i32, geo.y as i32).into(), + (geo.width as i32, geo.height as i32).into(), ) .to_logical(xwm.client_scale.load(Ordering::Acquire) as i32); @@ -1526,9 +1526,9 @@ where trace!(window = ?n, "configured X11 Window"); let client_scale = xwm.client_scale.load(Ordering::Acquire); - let geometry = Rectangle::::from_loc_and_size( - (n.x as i32, n.y as i32), - (n.width as i32, n.height as i32), + let geometry = Rectangle::::new( + (n.x as i32, n.y as i32).into(), + (n.width as i32, n.height as i32).into(), ) .to_logical(client_scale as i32);