Trait vector2math::rectangle::Rectangle[][src]

pub trait Rectangle: Copy {
    type Vector: Vector2;
    fn new(top_left: Self::Vector, size: Self::Vector) -> Self;
fn top_left(self) -> Self::Vector;
fn size(self) -> Self::Vector; fn square(top_left: Self::Vector, side_length: Scalar<Self>) -> Self { ... }
fn centered(center: Self::Vector, size: Self::Vector) -> Self { ... }
fn square_centered(center: Self::Vector, side_length: Scalar<Self>) -> Self { ... }
fn map_into<R>(self) -> R
    where
        R: Rectangle,
        Scalar<R>: From<Scalar<Self>>
, { ... }
fn map_rect(self) -> [Scalar<Self>; 4] { ... }
fn map_with<R, F>(self, f: F) -> R
    where
        R: Rectangle,
        F: FnMut(Scalar<Self>) -> <<R as Rectangle>::Vector as Vector2>::Scalar
, { ... }
fn abs_size(self) -> Self::Vector { ... }
fn top_right(self) -> Self::Vector { ... }
fn bottom_left(self) -> Self::Vector { ... }
fn bottom_right(self) -> Self::Vector { ... }
fn abs_top_left(self) -> Self::Vector { ... }
fn abs_top_right(self) -> Self::Vector { ... }
fn abs_bottom_left(self) -> Self::Vector { ... }
fn abs_bottom_right(self) -> Self::Vector { ... }
fn top(self) -> Scalar<Self> { ... }
fn bottom(self) -> Scalar<Self> { ... }
fn left(self) -> Scalar<Self> { ... }
fn right(self) -> Scalar<Self> { ... }
fn abs_top(self) -> Scalar<Self> { ... }
fn abs_bottom(self) -> Scalar<Self> { ... }
fn abs_left(self) -> Scalar<Self> { ... }
fn abs_right(self) -> Scalar<Self> { ... }
fn width(self) -> Scalar<Self> { ... }
fn height(self) -> Scalar<Self> { ... }
fn abs_width(self) -> Scalar<Self> { ... }
fn abs_height(self) -> Scalar<Self> { ... }
fn center(self) -> Self::Vector { ... }
fn with_size(self, size: Self::Vector) -> Self { ... }
fn with_top(self, top: Scalar<Self>) -> Self { ... }
fn with_bottom(self, bottom: Scalar<Self>) -> Self { ... }
fn with_left(self, left: Scalar<Self>) -> Self { ... }
fn with_right(self, right: Scalar<Self>) -> Self { ... }
fn perimeter(self) -> Scalar<Self> { ... }
fn area(self) -> Scalar<Self> { ... }
fn translated(self, offset: Self::Vector) -> Self { ... }
fn scaled(self, scale: Scalar<Self>) -> Self { ... }
fn scaled2(self, scale: Self::Vector) -> Self { ... }
fn corners(self) -> [Self::Vector; 4] { ... }
fn contains(self, point: Self::Vector) -> bool { ... }
fn contains_all<I>(self, points: I) -> bool
    where
        I: IntoIterator<Item = Self::Vector>
, { ... }
fn contains_any<I>(self, points: I) -> bool
    where
        I: IntoIterator<Item = Self::Vector>
, { ... }
fn bounding<I>(points: I) -> Option<Self>
    where
        I: IntoIterator<Item = Self::Vector>
, { ... }
fn inner_margin(self, margin: Scalar<Self>) -> Self { ... }
fn inner_margins(
        self,
        [left, right, top, bottom]: [Scalar<Self>; 4]
    ) -> Self { ... }
fn outer_margin(self, margin: Scalar<Self>) -> Self { ... }
fn outer_margins(
        self,
        [left, right, top, bottom]: [Scalar<Self>; 4]
    ) -> Self { ... } }

Trait for manipulating axis-aligned rectangles

Because the primary expected use for this crate is in 2D graphics and alignment implementations, a coordinate system where the positive Y direction is “down” is assumed.

Note

Methods of the form abs_* account for the case where the size is negative. If the size is not negative, they are identical to their non-abs_* counterparts.

use vector2math::*;

let pos_size = [1, 2, 3, 4];
assert_eq!(pos_size.right(), pos_size.abs_right());

let neg_size = [1, 2, -3, -4];
assert_ne!(neg_size.right(), neg_size.abs_right());

let points = vec![
    [-1, 0],
    [1, 5],
    [3, 2],
];
let bounding_rect: [i32; 4] = Rectangle::bounding(points).unwrap();
assert_eq!(
    bounding_rect,
    [-1, 0, 4, 5]
);

Associated Types

type Vector: Vector2[src]

The vector type

Loading content...

Required methods

fn new(top_left: Self::Vector, size: Self::Vector) -> Self[src]

Create a new rectangle from a top-left corner position and a size

fn top_left(self) -> Self::Vector[src]

Get the top-left corner position

fn size(self) -> Self::Vector[src]

Get the size

Loading content...

Provided methods

fn square(top_left: Self::Vector, side_length: Scalar<Self>) -> Self[src]

Create a new square from a top-left corner position and a side length

fn centered(center: Self::Vector, size: Self::Vector) -> Self[src]

Create a new rectangle from a center position and a size

fn square_centered(center: Self::Vector, side_length: Scalar<Self>) -> Self[src]

Create a new square from a top-left corner position and a side length

fn map_into<R>(self) -> R where
    R: Rectangle,
    Scalar<R>: From<Scalar<Self>>, 
[src]

Map this rectangle to a rectangle of another type

fn map_rect(self) -> [Scalar<Self>; 4][src]

Map this rectangle to a [Scalar<Self>; 4]

This is an alias for Rectangle::map_into::<[Scalar<Self>; 4]>() that is more concise

fn map_with<R, F>(self, f: F) -> R where
    R: Rectangle,
    F: FnMut(Scalar<Self>) -> <<R as Rectangle>::Vector as Vector2>::Scalar
[src]

Map this rectangle to a rectangle of another type using a function

fn abs_size(self) -> Self::Vector[src]

Get the absolute size

fn top_right(self) -> Self::Vector[src]

Get the top-right corner position

fn bottom_left(self) -> Self::Vector[src]

Get the bottom-left corner position

fn bottom_right(self) -> Self::Vector[src]

Get the bottom-right corner position

fn abs_top_left(self) -> Self::Vector[src]

Get the absolute top-left corner position

fn abs_top_right(self) -> Self::Vector[src]

Get the absolute top-right corner position

fn abs_bottom_left(self) -> Self::Vector[src]

Get the absolute bottom-left corner position

fn abs_bottom_right(self) -> Self::Vector[src]

Get the absolute bottom-right corner position

fn top(self) -> Scalar<Self>[src]

Get the top y

fn bottom(self) -> Scalar<Self>[src]

Get the bottom y

fn left(self) -> Scalar<Self>[src]

Get the left x

fn right(self) -> Scalar<Self>[src]

Get the right x

fn abs_top(self) -> Scalar<Self>[src]

Get the absolute top y

fn abs_bottom(self) -> Scalar<Self>[src]

Get the absolute bottom y

fn abs_left(self) -> Scalar<Self>[src]

Get the absolute left x

fn abs_right(self) -> Scalar<Self>[src]

Get the absolute right x

fn width(self) -> Scalar<Self>[src]

Get the width

fn height(self) -> Scalar<Self>[src]

Get the height

fn abs_width(self) -> Scalar<Self>[src]

Get the absolute width

fn abs_height(self) -> Scalar<Self>[src]

Get the absolute height

fn center(self) -> Self::Vector[src]

Get the position of the center

fn with_size(self, size: Self::Vector) -> Self[src]

Transform the rectangle into one with a different size

fn with_top(self, top: Scalar<Self>) -> Self[src]

Get the rectangle that is this one with a different top bound

fn with_bottom(self, bottom: Scalar<Self>) -> Self[src]

Get the rectangle that is this one with a different bottom bound

fn with_left(self, left: Scalar<Self>) -> Self[src]

Get the rectangle that is this one with a different left bound

fn with_right(self, right: Scalar<Self>) -> Self[src]

Get the rectangle that is this one with a different right bound

fn perimeter(self) -> Scalar<Self>[src]

Get the perimeter

fn area(self) -> Scalar<Self>[src]

Get the area

fn translated(self, offset: Self::Vector) -> Self[src]

Get the rectangle that is this one translated by some vector

fn scaled(self, scale: Scalar<Self>) -> Self[src]

Get the rectangle that is this one with a scalar-scaled size

fn scaled2(self, scale: Self::Vector) -> Self[src]

Get the rectangle that is this one with a vector-scaled size

fn corners(self) -> [Self::Vector; 4][src]

Get an array the rectangle’s four corners, clockwise from top-left

fn contains(self, point: Self::Vector) -> bool[src]

Check that the rectangle contains the given point. Includes edges.

fn contains_all<I>(self, points: I) -> bool where
    I: IntoIterator<Item = Self::Vector>, 
[src]

Check that the rectangle contains all points

fn contains_any<I>(self, points: I) -> bool where
    I: IntoIterator<Item = Self::Vector>, 
[src]

Check that the rectangle contains any point

fn bounding<I>(points: I) -> Option<Self> where
    I: IntoIterator<Item = Self::Vector>, 
[src]

Get the smallest rectangle that contains all the points

Returns None if the iterator is empty

fn inner_margin(self, margin: Scalar<Self>) -> Self[src]

Get the rectangle that is inside this one with the given margin on all sides

fn inner_margins(self, [left, right, top, bottom]: [Scalar<Self>; 4]) -> Self[src]

Get the rectangle that is inside this one with the given margins

Margins should be ordered [left, right, top, bottom]

fn outer_margin(self, margin: Scalar<Self>) -> Self[src]

Get the rectangle that is outside this one with the given margin on all sides

fn outer_margins(self, [left, right, top, bottom]: [Scalar<Self>; 4]) -> Self[src]

Get the rectangle that is outside this one with the given margins

Margins should be ordered [left, right, top, bottom]

Loading content...

Implementors

impl<P> Rectangle for P where
    P: Pair + Copy,
    P::Item: Vector2
[src]

type Vector = P::Item

Loading content...