Struct rekee::hexagon::Rect

source ·
pub struct Rect {
    pub left: f32,
    pub top: f32,
    pub width: f32,
    pub height: f32,
}
Expand description

Rectangle area within a grid of rectangular pixels. It consists of the four values: top, left, width, and height. Both axes of the grid are aligned like the coordinate system of a web page: x runs from left to right, y runs from top to bottom.

§Examples

let rect = Rect::new(1.0, 2.0, 4.0, 3.0);
assert_eq!(rect.left, 1.0);
assert_eq!(rect.top, 2.0);
assert_eq!(rect.right(), 5.0);
assert_eq!(rect.bottom(), 5.0);

Fields§

§left: f32§top: f32§width: f32§height: f32

Implementations§

source§

impl Rect

source

pub fn new(left: f32, top: f32, width: f32, height: f32) -> Self

Creates a new rectangle from the left, top, width and height values. Values for width or height are allowed to be negative, the rectangle will be normalized in that case.

§Examples
let rect = Rect::new(1.0, 2.0, 3.0, -4.0);
assert_eq!(rect.left, 1.0);
assert_eq!(rect.top, -2.0);
assert_eq!(rect.right(), 4.0);
assert_eq!(rect.bottom(), 2.0);
source

pub fn right(&self) -> f32

Right position of the rectangle.

source

pub fn bottom(&self) -> f32

Bottom position of the rectangle.

source

pub fn center(&self) -> Point

Center point of the rectangle.

§Examples
let rect = Rect::new(0.0, 1.0, 3.0, 4.0);
assert_eq!(rect.center(), Point(1.5, 3.0));
source

pub fn top_left(&self) -> Point

Top-left corner of the rectangle.

§Examples
let rect = Rect::new(0.0, 1.0, 3.0, 4.0);
assert_eq!(rect.top_left(), Point(0.0, 1.0));
assert_eq!(rect.left, 0.0);
assert_eq!(rect.top, 1.0);
source

pub fn bottom_right(&self) -> Point

Bottom-right corner of the rectangle.

§Examples
let rect = Rect::new(0.0, 1.0, 3.0, 4.0);
assert_eq!(rect.bottom_right(), Point(3.0, 5.0));
assert_eq!(rect.right(), 3.0);
assert_eq!(rect.bottom(), 5.0);
source

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

Calculates the union of two rectangles, the smallest rectangle that fully contains both source rectangles.

§Examples
let a = Rect::new(1.0, 2.0, 3.0, 4.0);
let b = Rect::new(-3.0, -4.0, 2.0, 1.0);
let rect = a.union(&b);
assert_eq!(rect.left, -3.0);
assert_eq!(rect.top, -4.0);
assert_eq!(rect.width, 7.0);
assert_eq!(rect.height, 10.0);
source

pub fn with_padding(&self, value: f32) -> Self

Creates a new rectangle from the existing one by adding a padding border on all four sides.

§Examples
let a = Rect::new(1.0, 2.0, 3.0, 4.0);
let rect = a.with_padding(0.5);
assert_eq!(rect.left, 0.5);
assert_eq!(rect.top, 1.5);
assert_eq!(rect.width, 4.0);
assert_eq!(rect.height, 5.0);

Trait Implementations§

source§

impl Clone for Rect

source§

fn clone(&self) -> Rect

Returns a copy 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 Rect

source§

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

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

impl Default for Rect

source§

fn default() -> Rect

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

impl PartialEq for Rect

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for Rect

source§

impl StructuralPartialEq for Rect

Auto Trait Implementations§

§

impl Freeze for Rect

§

impl RefUnwindSafe for Rect

§

impl Send for Rect

§

impl Sync for Rect

§

impl Unpin for Rect

§

impl UnwindSafe for Rect

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> 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,

§

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>,

§

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>,

§

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

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