From 1e8b4c876ecf80748d33e9300ccfe97a79139d1d Mon Sep 17 00:00:00 2001 From: Thomas Churchman Date: Wed, 3 Dec 2025 13:08:25 +0100 Subject: [PATCH] Implement `Aabb2D::from_xywh` This may be desirable as the generic abstraction; also note there already is an `fn area(Aabb2D T::Acc` (if we land this, `area` could become a method on `Aabb2D`)) The `const`-ness could be gained back with https://github.com/rust-lang/rfcs/pull/3762 at some (hopefully not-too-distant) future Rust version. --- understory_index/src/types.rs | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/understory_index/src/types.rs b/understory_index/src/types.rs index d595dbb..12dd2f0 100644 --- a/understory_index/src/types.rs +++ b/understory_index/src/types.rs @@ -61,41 +61,15 @@ impl Aabb2D { } } -impl Aabb2D { +impl Aabb2D { /// Create an AABB from origin and size in f32. #[inline] - pub const fn from_xywh(x: f32, y: f32, w: f32, h: f32) -> Self { + pub fn from_xywh(x: T, y: T, w: T, h: T) -> Self { Self { min_x: x, min_y: y, - max_x: x + w, - max_y: y + h, - } - } -} - -impl Aabb2D { - /// Create an AABB from origin and size in f64. - #[inline] - pub const fn from_xywh(x: f64, y: f64, w: f64, h: f64) -> Self { - Self { - min_x: x, - min_y: y, - max_x: x + w, - max_y: y + h, - } - } -} - -impl Aabb2D { - /// Create an AABB from origin and size in i64. - #[inline] - pub const fn from_xywh(x: i64, y: i64, w: i64, h: i64) -> Self { - Self { - min_x: x, - min_y: y, - max_x: x + w, - max_y: y + h, + max_x: T::add(x, w), + max_y: T::add(y, h), } } }