Skip to main content

BBox

Struct BBox 

Source
pub struct BBox {
    pub min_x: f64,
    pub min_y: f64,
    pub max_x: f64,
    pub max_y: f64,
}
Expand description

An axis-aligned bounding box, stored as its minimum corner plus its extent.

The min / max form (rather than x / y / width / height) keeps the empty-box case representable: a box that has not been extended yet is min > max on every axis, which is the standard sentinel for “no geometry yet”.

Fields§

§min_x: f64

The smallest x reached by the geometry.

§min_y: f64

The smallest y reached by the geometry.

§max_x: f64

The largest x reached by the geometry.

§max_y: f64

The largest y reached by the geometry.

Implementations§

Source§

impl BBox

Inherent implementation of BBox.

Source

pub fn empty() -> Self

Returns an empty bounding box.

The empty box has min greater than max on both axes, which makes BBox::extend_point work without a special case for the first vertex.

Source

pub fn from_min_size(min_x: f64, min_y: f64, width: f64, height: f64) -> Self

Returns a bounding box from its minimum corner and its extent.

§Arguments
  • f64 - A 64-bit float (f64).
Source

pub fn from_corners(x0: f64, y0: f64, x1: f64, y1: f64) -> Self

Returns a bounding box from two opposite corners.

§Arguments
  • f64 - A 64-bit float (f64).
Source

pub fn is_empty(&self) -> bool

Returns true when the box contains no geometry.

§Returns
  • bool - A boolean.
Source

pub fn width(&self) -> f64

Returns the width of the box, or zero when it is empty.

§Returns
  • f64 - A 64-bit float.
Source

pub fn height(&self) -> f64

Returns the height of the box, or zero when it is empty.

§Returns
  • f64 - A 64-bit float.
Source

pub fn center_x(&self) -> f64

Returns the horizontal center of the box.

§Returns
  • f64 - A 64-bit float.
Source

pub fn center_y(&self) -> f64

Returns the vertical center of the box.

§Returns
  • f64 - A 64-bit float.
Source

pub fn extend_point(&mut self, x: f64, y: f64)

Grows the box so that it contains the given point.

§Arguments
  • f64 - A 64-bit float (f64).
Source

pub fn extend_box(&mut self, other: &BBox)

Grows the box so that it contains the given box.

§Arguments
  • &BBox - Shared reference to a BBox.
Source

pub fn contains(&self, x: f64, y: f64) -> bool

Returns true when the box fully contains the given point.

§Arguments
  • f64 - A 64-bit float (f64).
§Returns
  • bool - A boolean.
Source

pub fn intersects(&self, other: &BBox) -> bool

Returns true when the two boxes overlap.

§Arguments
  • &BBox - Shared reference to a BBox.
§Returns
  • bool - A boolean.
Source

pub fn intersection(&self, other: &BBox) -> Option<BBox>

Returns the overlap of the two boxes, or None when they do not overlap.

§Arguments
  • &BBox - Shared reference to a BBox.
§Returns
  • Option<BBox> - Some(...) on success, None otherwise.
Source

pub fn union(&self, other: &BBox) -> BBox

Returns the union of the two boxes.

§Arguments
  • &BBox - Shared reference to a BBox.
§Returns
  • BBox - A BBox value.
Source§

impl BBox

Source

pub fn get_min_x(&self) -> f64

Source

pub fn get_mut_min_x(&mut self) -> &mut f64

Source

pub fn set_min_x(&mut self, val: f64) -> &mut Self

Source

pub fn get_min_y(&self) -> f64

Source

pub fn get_mut_min_y(&mut self) -> &mut f64

Source

pub fn set_min_y(&mut self, val: f64) -> &mut Self

Source

pub fn get_max_x(&self) -> f64

Source

pub fn get_mut_max_x(&mut self) -> &mut f64

Source

pub fn set_max_x(&mut self, val: f64) -> &mut Self

Source

pub fn get_max_y(&self) -> f64

Source

pub fn get_mut_max_y(&mut self) -> &mut f64

Source

pub fn set_max_y(&mut self, val: f64) -> &mut Self

Trait Implementations§

Source§

impl Clone for BBox

Source§

fn clone(&self) -> Self

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 Copy for BBox

Source§

impl Debug for BBox

Source§

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

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

impl Default for BBox

Default construction for BBox.

Source§

fn default() -> Self

Constructs a default BBox value.

Source§

impl PartialEq for BBox

Source§

fn eq(&self, other: &Self) -> bool

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for BBox

Auto Trait Implementations§

§

impl Freeze 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§

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more