Bounds

Struct Bounds 

Source
pub struct Bounds { /* private fields */ }
Expand description

Rectangle bounds for defining sub-regions of images.

Implementations§

Source§

impl Bounds

Source

pub fn width(&self) -> Pt

Source

pub fn height(&self) -> Pt

Source§

impl Bounds

Source

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

Creates new bounds with the specified dimensions.

Examples found in repository?
examples/subimage_example.rs (line 22)
10        fn initialize(_context: &mut Context) -> Self {
11            const TREE_PNG: &[u8] = include_bytes!("../assets/happy-tree.png");
12            let decoded = image::load_from_memory(TREE_PNG).expect("failed to decode happy-tree.png");
13            let rgba = decoded.to_rgba8();
14            let (w, h) = (rgba.width(), rgba.height());
15            let tree = Image::new_from_rgba8(Pt::from(w), Pt::from(h), rgba.as_raw())
16                .expect("failed to create happy-tree image");
17
18            let crop_w = (w / 2).max(1);
19            let crop_h = (h / 2).max(1);
20            let tree_sub = Image::sub_image(
21                tree,
22                Bounds::new(Pt::from(0.0), Pt::from(0.0), Pt::from(crop_w), Pt::from(crop_h)),
23            )
24                .expect("failed to create sub image");
25
26            Self { tree, tree_sub }
27        }
More examples
Hide additional examples
examples/demo.rs (line 33)
12        fn initialize(_context: &mut Context) -> Self {
13            const TREE_PNG: &[u8] = include_bytes!("../assets/happy-tree.png");
14            let decoded = image::load_from_memory(TREE_PNG).expect("failed to decode happy-tree.png");
15            let rgba = decoded.to_rgba8();
16            let (w, h) = (rgba.width(), rgba.height());
17            let tree = Image::new_from_rgba8(Pt::from(w), Pt::from(h), rgba.as_raw())
18                .expect("failed to create happy-tree image");
19
20            let mut rgba = vec![0u8; 20 * 20 * 4];
21            for y in 0..20u32 {
22                for x in 0..20u32 {
23                    let i = ((y * 20 + x) * 4) as usize;
24                    let on = ((x / 5 + y / 5) % 2) == 0;
25                    rgba[i] = if on { 255 } else { 30 };
26                    rgba[i + 1] = if on { 80 } else { 200 };
27                    rgba[i + 2] = if on { 80 } else { 255 };
28                    rgba[i + 3] = 255;
29                }
30            }
31            let image =
32                Image::new_from_rgba8(Pt::from(20.0), Pt::from(20.0), &rgba).expect("failed to create test image");
33            let image_sub = Image::sub_image(image, Bounds::new(Pt::from(5.0), Pt::from(5.0), Pt::from(10.0), Pt::from(10.0)))
34                .expect("failed to create sub image");
35            let image_clone = Image::new_from_image(image).expect("failed to create image from image");
36
37            Self {
38                tree,
39                image,
40                image_sub,
41                image_clone,
42            }
43        }

Trait Implementations§

Source§

impl Clone for Bounds

Source§

fn clone(&self) -> Bounds

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Bounds

Source§

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

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

impl Hash for Bounds

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 Bounds

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Bounds

Source§

impl Eq for Bounds

Source§

impl StructuralPartialEq for Bounds

Auto Trait Implementations§

§

impl Freeze for Bounds

§

impl RefUnwindSafe for Bounds

§

impl Send for Bounds

§

impl Sync for Bounds

§

impl Unpin for Bounds

§

impl UnwindSafe for Bounds

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

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,