Skip to content

Commit 1e8b4c8

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 21d2dec commit 1e8b4c8

File tree

1 file changed

+4
-30
lines changed

1 file changed

+4
-30
lines changed

understory_index/src/types.rs

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -61,41 +61,15 @@ impl<T: Copy + PartialOrd> Aabb2D<T> {
6161
}
6262
}
6363

64-
impl Aabb2D<f32> {
64+
impl<T: Scalar> Aabb2D<T> {
6565
/// Create an AABB from origin and size in f32.
6666
#[inline]
67-
pub const fn from_xywh(x: f32, y: f32, w: f32, h: f32) -> Self {
67+
pub fn from_xywh(x: T, y: T, w: T, h: T) -> Self {
6868
Self {
6969
min_x: x,
7070
min_y: y,
71-
max_x: x + w,
72-
max_y: y + h,
73-
}
74-
}
75-
}
76-
77-
impl Aabb2D<f64> {
78-
/// Create an AABB from origin and size in f64.
79-
#[inline]
80-
pub const fn from_xywh(x: f64, y: f64, w: f64, h: f64) -> Self {
81-
Self {
82-
min_x: x,
83-
min_y: y,
84-
max_x: x + w,
85-
max_y: y + h,
86-
}
87-
}
88-
}
89-
90-
impl Aabb2D<i64> {
91-
/// Create an AABB from origin and size in i64.
92-
#[inline]
93-
pub const fn from_xywh(x: i64, y: i64, w: i64, h: i64) -> Self {
94-
Self {
95-
min_x: x,
96-
min_y: y,
97-
max_x: x + w,
98-
max_y: y + h,
71+
max_x: T::add(x, w),
72+
max_y: T::add(y, h),
9973
}
10074
}
10175
}

0 commit comments

Comments
 (0)