pub struct BBox {
pub x0: f32,
pub y0: f32,
pub x1: f32,
pub y1: f32,
}Expand description
An axis-aligned box: origin top-left, x right, y down; x1 and y1 exclusive.
§Example
use adk_vision::BBox;
let a = BBox::new(0.0, 0.0, 10.0, 10.0);
let b = BBox::new(5.0, 0.0, 15.0, 10.0);
assert_eq!(a.area(), 100.0);
assert!((a.iou(&b) - 1.0 / 3.0).abs() < 1e-6);
assert_eq!(BBox::new(-5.0, 2.0, 50.0, 8.0).clamped(20, 20), BBox::new(0.0, 2.0, 20.0, 8.0));Fields§
§x0: f32Left edge.
y0: f32Top edge.
x1: f32Right edge, exclusive.
y1: f32Bottom edge, exclusive.
Implementations§
Source§impl BBox
impl BBox
Sourcepub fn new(x0: f32, y0: f32, x1: f32, y1: f32) -> Self
pub fn new(x0: f32, y0: f32, x1: f32, y1: f32) -> Self
A box from its edges; the edges are reordered so x0 <= x1 and y0 <= y1.
Sourcepub fn from_xywh(x: f32, y: f32, width: f32, height: f32) -> Self
pub fn from_xywh(x: f32, y: f32, width: f32, height: f32) -> Self
A box from its top-left corner and size.
Sourcepub fn intersection(&self, other: &Self) -> Option<Self>
pub fn intersection(&self, other: &Self) -> Option<Self>
The overlap of two boxes, if any.
Sourcepub fn clamped(&self, width: u32, height: u32) -> Self
pub fn clamped(&self, width: u32, height: u32) -> Self
The box clamped to an image of width × height.
Sourcepub fn is_within(&self, width: u32, height: u32) -> bool
pub fn is_within(&self, width: u32, height: u32) -> bool
true when the box lies within an image of width × height.
Trait Implementations§
impl Copy for BBox
Source§impl<'de> Deserialize<'de> for BBox
impl<'de> Deserialize<'de> for BBox
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for BBox
Auto Trait Implementations§
impl Forget for BBox
impl Freeze for BBox
impl Move for BBox
impl RefUnwindSafe for BBox
impl Send for BBox
impl Sync for BBox
impl Unpin for BBox
impl UnsafeUnpin for BBox
impl UnwindSafe for BBox
Blanket Implementations§
impl<T> Boilerplate for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for T
impl<T> Downcast for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
impl<T> MaybeSend for Twhere
T: Send,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Scalar for T
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.