Struct Selection

Source
pub struct Selection(/* private fields */);
Expand description

A pixel selection within a view.

Implementations§

Source§

impl Selection

Source

pub fn new(x1: i32, y1: i32, x2: i32, y2: i32) -> Self

Create a new selection from a rectangle.

Source

pub fn from(r: Rect<i32>) -> Self

Create a new selection from a rectangle.

Source

pub fn bounds(&self) -> Rect<i32>

Return the selection bounds as a non-empty rectangle. This function will never return an empty rectangle.

Source

pub fn abs(&self) -> Selection

Return the absolute selection.

Source

pub fn translate(&mut self, x: i32, y: i32)

Translate the selection rectangle.

Source

pub fn resize(&mut self, x: i32, y: i32)

Resize the selection by a certain amount.

Methods from Deref<Target = Rect<i32>>§

Source

pub fn scale(&self, x: T, y: T) -> Rect<T>
where T: Mul<Output = T> + Copy,

Source

pub fn with_origin(&self, x: T, y: T) -> Rect<T>
where T: Add<Output = T> + Sub<Output = T> + Copy,

Return the rectangle with a different origin.

§Examples
use rgx::rect::Rect;

let r = Rect::new(1, 1, 4, 4);
assert_eq!(r.with_origin(0, 0), Rect::new(0, 0, 3, 3));
Source

pub fn with_size(&self, w: T, h: T) -> Rect<T>
where T: Add<Output = T> + Sub<Output = T> + Copy,

Return the rectangle with a different size.

§Examples
use rgx::rect::Rect;

let r = Rect::new(1, 1, 4, 4);
assert_eq!(r.with_size(9, 9), Rect::new(1, 1, 10, 10));
Source

pub fn expand(&self, x1: T, y1: T, x2: T, y2: T) -> Rect<T>
where T: Add<Output = T> + Sub<Output = T> + PartialOrd + Copy,

Return an expanded rectangle by a constant amount.

§Examples
use rgx::rect::Rect;

let r = Rect::new(0, 0, 3, 3);
assert_eq!(r.expand(1, 1, 1, 1), Rect::new(-1, -1, 4, 4));

let r = Rect::new(3, 3, 0, 0);
assert_eq!(r.expand(1, 1, 1, 1), Rect::new(4, 4, -1, -1));

let r = Rect::new(-1, 1, 1, -1);
assert_eq!(r.expand(4, 4, 4, 4), Rect::new(-5, 5, 5, -5));
Source

pub fn flip_y(&self) -> Rect<T>
where T: Copy,

Return the rectangle flipped in the Y axis.

Source

pub fn flip_x(&self) -> Rect<T>
where T: Copy,

Return the rectangle flipped in the X axis.

Source

pub fn area(&self) -> T
where T: Copy + Sub<Output = T> + PartialOrd + Mul<Output = T>,

Return the area of a rectangle.

Source

pub fn is_empty(&self) -> bool
where T: PartialEq,

Source

pub fn is_zero(&self) -> bool
where T: Zero,

Source

pub fn width(&self) -> T
where T: Copy + PartialOrd + Sub<Output = T>,

Return the width of the rectangle.

§Examples
use rgx::rect::Rect;

let r = Rect::new(0, 0, 3, 3);
assert_eq!(r.width(), 3);
Source

pub fn height(&self) -> T
where T: Copy + PartialOrd + Sub<Output = T>,

Return the height of the rectangle.

§Examples
use rgx::rect::Rect;

let r = Rect::origin(-6, -6);
assert_eq!(r.height(), 6);
Source

pub fn min(&self) -> Point2<T>
where T: PartialOrd + Copy,

Return the minimum point of a rectangle.

§Examples
use rgx::rect::Rect;
use rgx::math::Point2;

let r = Rect::new(0, 0, 1, -1);
assert_eq!(r.min(), Point2::new(0, -1));
Source

pub fn max(&self) -> Point2<T>
where T: PartialOrd + Copy,

Return the maximum point of a rectangle.

§Examples
use rgx::rect::Rect;
use rgx::math::Point2;

let r = Rect::origin(-1, 1);
assert_eq!(r.max(), Point2::new(0, 1));
Source

pub fn center(&self) -> Point2<T>
where T: Div<Output = T> + Copy + Ord + From<i16> + PartialOrd + Zero + Neg<Output = T> + Sub<Output = T>,

Return the center of the rectangle.

§Examples
use rgx::rect::Rect;
use rgx::math::Point2;

let r = Rect::origin(8, 8);
assert_eq!(r.center(), Point2::new(4, 4));

let r = Rect::new(0, 0, -8, -8);
assert_eq!(r.center(), Point2::new(-4, -4));
Source

pub fn radius(&self) -> T
where T: Div<Output = T> + Copy + From<i16> + PartialOrd + Zero + Neg<Output = T> + Sub<Output = T>,

Source

pub fn contains(&self, p: Point2<T>) -> bool
where T: Copy + PartialOrd,

Check whether the given point is contained in the rectangle.

use rgx::rect::Rect;
use rgx::math::Point2;

let r = Rect::origin(6, 6);
assert!(r.contains(Point2::new(0, 0)));
assert!(r.contains(Point2::new(3, 3)));
assert!(!r.contains(Point2::new(6, 6)));

let r = Rect::new(0, 0, -6, -6);
assert!(r.contains(Point2::new(-3, -3)));
Source

pub fn intersects(&self, other: Rect<T>) -> bool
where T: PartialOrd,

Source

pub fn abs(&self) -> Rect<T>
where T: Ord + Copy,

Return the absolute rectangle.

§Examples
use rgx::rect::Rect;

let r = Rect::new(3, 3, 1, 1).abs();
assert_eq!(r, Rect::new(1, 1, 3, 3));

let r = Rect::new(-1, -1, 1, 1).abs();
assert_eq!(r, Rect::new(-1, -1, 1, 1));
Source

pub fn intersection(&self, other: Rect<T>) -> Rect<T>
where T: Ord + Copy,

Return the intersection between two rectangles.

§Examples
use rgx::rect::Rect;

let other = Rect::new(0, 0, 3, 3);

let r = Rect::new(1, 1, 6, 6);
assert_eq!(r.intersection(other), Rect::new(1, 1, 3, 3));

let r = Rect::new(1, 1, 2, 2);
assert_eq!(r.intersection(other), Rect::new(1, 1, 2, 2));

let r = Rect::new(-1, -1, 3, 3);
assert_eq!(r.intersection(other), Rect::new(0, 0, 3, 3));

let r = Rect::new(-1, -1, 4, 4);
assert_eq!(r.intersection(other), other);

let r = Rect::new(4, 4, 5, 5);
assert!(r.intersection(other).is_empty());

Trait Implementations§

Source§

impl Clone for Selection

Source§

fn clone(&self) -> Selection

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 Selection

Source§

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

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

impl Deref for Selection

Source§

type Target = Rect<i32>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Rect<i32>

Dereferences the value.
Source§

impl PartialEq for Selection

Source§

fn eq(&self, other: &Selection) -> 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 Selection

Source§

impl Eq for Selection

Source§

impl StructuralPartialEq for Selection

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SetParameter for T

Source§

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result
where T: Parameter<Self>,

Sets value as a parameter of self.
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.