Skip to main content

BBoxXYXY

Struct BBoxXYXY 

Source
pub struct BBoxXYXY<TSpace> {
    pub min: Coord<TSpace>,
    pub max: Coord<TSpace>,
}
Expand description

An axis-aligned bounding box in XYXY format (xmin, ymin, xmax, ymax).

The TSpace parameter should be either Pixel or Normalized, ensuring type safety across coordinate spaces.

Note: This type does NOT enforce that min < max in the constructor, allowing “malformed” boxes to exist in the IR. This is intentional - validation should catch and report these issues rather than preventing them from being represented.

Fields§

§min: Coord<TSpace>§max: Coord<TSpace>

Implementations§

Source§

impl<TSpace> BBoxXYXY<TSpace>

Source

pub fn new(min: Coord<TSpace>, max: Coord<TSpace>) -> Self

Creates a new bounding box from min and max coordinates.

Source

pub fn from_xyxy(xmin: f64, ymin: f64, xmax: f64, ymax: f64) -> Self

Creates a new bounding box from explicit coordinates.

Source

pub fn xmin(&self) -> f64

Returns the minimum x coordinate.

Source

pub fn ymin(&self) -> f64

Returns the minimum y coordinate.

Source

pub fn xmax(&self) -> f64

Returns the maximum x coordinate.

Source

pub fn ymax(&self) -> f64

Returns the maximum y coordinate.

Source

pub fn width(&self) -> f64

Returns the width of the bounding box.

May be negative if the box is malformed (xmax < xmin).

Source

pub fn height(&self) -> f64

Returns the height of the bounding box.

May be negative if the box is malformed (ymax < ymin).

Source

pub fn area(&self) -> f64

Returns the area of the bounding box.

May be negative if the box is malformed.

Source

pub fn is_finite(&self) -> bool

Returns true if all coordinates are finite (not NaN or infinite).

Source

pub fn is_ordered(&self) -> bool

Returns true if the box is properly ordered (min <= max for both axes).

Source

pub fn iou(&self, other: &Self) -> f64

Computes intersection-over-union (IoU) with another box.

Returns 0.0 for non-finite or unordered boxes.

Source§

impl<TSpace> BBoxXYXY<TSpace>

Conversion utilities for different bbox formats.

Source

pub fn from_xywh(x: f64, y: f64, width: f64, height: f64) -> Self

Converts from XYWH format (x, y, width, height) where (x, y) is the top-left corner.

This is the format used by COCO annotations.

Source

pub fn to_xywh(&self) -> (f64, f64, f64, f64)

Converts to XYWH format (x, y, width, height).

Source

pub fn from_cxcywh(cx: f64, cy: f64, w: f64, h: f64) -> Self

Creates from center-based XYWH format (center_x, center_y, width, height).

This is the format used by YOLO annotations.

Source

pub fn to_cxcywh(&self) -> (f64, f64, f64, f64)

Converts to center-based XYWH format (center_x, center_y, width, height).

Source§

impl BBoxXYXY<Pixel>

Source

pub fn to_normalized( &self, image_width: f64, image_height: f64, ) -> BBoxXYXY<Normalized>

Converts pixel coordinates to normalized coordinates.

§Arguments
  • image_width - The width of the image in pixels
  • image_height - The height of the image in pixels
Source§

impl BBoxXYXY<Normalized>

Source

pub fn to_pixel(&self, image_width: f64, image_height: f64) -> BBoxXYXY<Pixel>

Converts normalized coordinates to pixel coordinates.

§Arguments
  • image_width - The width of the image in pixels
  • image_height - The height of the image in pixels

Trait Implementations§

Source§

impl<TSpace: Clone> Clone for BBoxXYXY<TSpace>

Source§

fn clone(&self) -> BBoxXYXY<TSpace>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<TSpace: Copy> Copy for BBoxXYXY<TSpace>

Source§

impl<TSpace> Debug for BBoxXYXY<TSpace>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<TSpace> Default for BBoxXYXY<TSpace>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, TSpace> Deserialize<'de> for BBoxXYXY<TSpace>

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<TSpace: PartialEq> PartialEq for BBoxXYXY<TSpace>

Source§

fn eq(&self, other: &BBoxXYXY<TSpace>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<TSpace> Serialize for BBoxXYXY<TSpace>

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl<TSpace: PartialEq> StructuralPartialEq for BBoxXYXY<TSpace>

Auto Trait Implementations§

§

impl<TSpace> Freeze for BBoxXYXY<TSpace>

§

impl<TSpace> RefUnwindSafe for BBoxXYXY<TSpace>
where TSpace: RefUnwindSafe,

§

impl<TSpace> Send for BBoxXYXY<TSpace>
where TSpace: Send,

§

impl<TSpace> Sync for BBoxXYXY<TSpace>
where TSpace: Sync,

§

impl<TSpace> Unpin for BBoxXYXY<TSpace>
where TSpace: Unpin,

§

impl<TSpace> UnsafeUnpin for BBoxXYXY<TSpace>

§

impl<TSpace> UnwindSafe for BBoxXYXY<TSpace>
where TSpace: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.