Skip to content

Commit 98b6e86

Browse files
committed
Implement Aabb2D<T: Scalar>::from_xywh
This may be desirable as the generic abstraction; also note there already is an `fn area(Aabb2D<T: Scalar) -> T::Acc` (if we land this, `area` could become a method on `Aabb2D<T: Scalar>`)) The `const`-ness could be gained back with rust-lang/rfcs#3762 at some (hopefully not-too-distant) future Rust version.
1 parent 4db3eb6 commit 98b6e86

File tree

1 file changed

+4
-28
lines changed

1 file changed

+4
-28
lines changed

understory_index/src/types.rs

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,38 +57,14 @@ impl<T: Copy + PartialOrd> Aabb2D<T> {
5757
}
5858
}
5959

60-
impl Aabb2D<f32> {
60+
impl<T: Scalar> Aabb2D<T> {
6161
/// Create an AABB from origin and size in f32.
62-
pub const fn from_xywh(x: f32, y: f32, w: f32, h: f32) -> Self {
62+
pub fn from_xywh(x: T, y: T, w: T, h: T) -> Self {
6363
Self {
6464
min_x: x,
6565
min_y: y,
66-
max_x: x + w,
67-
max_y: y + h,
68-
}
69-
}
70-
}
71-
72-
impl Aabb2D<f64> {
73-
/// Create an AABB from origin and size in f64.
74-
pub const fn from_xywh(x: f64, y: f64, w: f64, h: f64) -> Self {
75-
Self {
76-
min_x: x,
77-
min_y: y,
78-
max_x: x + w,
79-
max_y: y + h,
80-
}
81-
}
82-
}
83-
84-
impl Aabb2D<i64> {
85-
/// Create an AABB from origin and size in i64.
86-
pub const fn from_xywh(x: i64, y: i64, w: i64, h: i64) -> Self {
87-
Self {
88-
min_x: x,
89-
min_y: y,
90-
max_x: x + w,
91-
max_y: y + h,
66+
max_x: T::add(x, w),
67+
max_y: T::add(y, h),
9268
}
9369
}
9470
}

0 commit comments

Comments
 (0)