Skip to main content

Region

Struct Region 

Source
pub struct Region {
    pub x: u32,
    pub y: u32,
    pub width: u32,
    pub height: u32,
}
Expand description

An axis-aligned rectangle of pixels, in image coordinates.

The origin is the top-left corner; x grows right and y grows down. A region with zero width or height is empty and legal to represent — it is what demand propagation produces when an op needs nothing from an input.

Edge accessors return u64 so that a region touching the far edge of the coordinate space cannot overflow during intersection math.

Fields§

§x: u32

Distance from the left edge of the image, in pixels.

§y: u32

Distance from the top edge of the image, in pixels.

§width: u32

Width in pixels; may be zero.

§height: u32

Height in pixels; may be zero.

Implementations§

Source§

impl Region

Source

pub const EMPTY: Self

The empty region at the origin.

Source

pub const fn new(x: u32, y: u32, width: u32, height: u32) -> Self

Construct a region from its origin and size.

Source

pub const fn from_size(width: u32, height: u32) -> Self

A region covering width × height pixels at the origin.

Source

pub const fn right(self) -> u64

The x coordinate one past the right edge.

Source

pub const fn bottom(self) -> u64

The y coordinate one past the bottom edge.

Source

pub const fn is_empty(self) -> bool

Whether the region contains no pixels.

Source

pub const fn pixel_count(self) -> u64

The number of pixels in the region.

Source

pub const fn contains(self, other: Self) -> bool

Whether other lies entirely within self.

An empty region is contained by any region, including another empty one.

Source

pub fn intersect(self, other: Self) -> Self

The overlap between two regions, or Region::EMPTY if they are disjoint.

Source

pub fn translate(self, dx: i64, dy: i64) -> Self

Move the region by a signed offset, clamping at the coordinate origin.

Trait Implementations§

Source§

impl Clone for Region

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 Region

Source§

impl Debug for Region

Source§

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

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

impl Display for Region

Source§

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

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

impl Eq for Region

Source§

impl Hash for Region

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Region

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 Region

Auto Trait Implementations§

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.