#[repr(C)]
pub struct Rect<T: Number> { /* private fields */ }

Implementations

Returns a rectangle that is size of one and has an origin on 0

Casts the rectangle to another primitive unit, panicking if the unit cannot be represented.

Same as Self::cast but returns None if the cast failed.

Checks if self intersects other. In other words it check if any of these rectangles touch each other. This is very useful in cull testing.

Arguments
  • other: The other rectangle to check intersection with.

returns: bool

Examples
use mathie::Rect;
let rect = Rect::one();
assert!(rect.intersects_rect(Rect::new([0.0, 0.0], [1.0, 1.0])));
assert!(rect.intersects_rect(Rect::new([0.4, 0.4], [0.2, 0.2])));
assert!(rect.intersects_rect(Rect::new([1.0, 1.0], [1.0, 1.0])));
assert!(rect.intersects_rect(Rect::new([0.0, 0.5], [0.5, 1.0])));
assert!(!rect.intersects_rect(Rect::new([1.1, 1.1], [1.0, 1.0])));
assert!(!rect.intersects_rect(Rect::new([-0.1, -0.1], [0.09, 0.09])));

Checks if self contains other, in other words, it checks if self fully contains other.

Arguments
  • other: The other rectangle to check if it is inside self.

returns: bool

Examples
use mathie::Rect;
let rect = Rect::one();
assert!(rect.contains_rect(Rect::new([0.0, 0.0], [1.0, 1.0])));
assert!(rect.contains_rect(Rect::new([0.4, 0.4], [0.2, 0.2])));
assert!(!rect.contains_rect(Rect::new([1.0, 1.0], [1.0, 1.0])));
assert!(!rect.contains_rect(Rect::new([0.0, 0.5], [0.5, 1.0])));
assert!(!rect.contains_rect(Rect::new([1.1, 1.1], [1.0, 1.0])));
assert!(!rect.contains_rect(Rect::new([-0.1, -0.1], [0.09, 0.09])));

Checks if this position is inside this rectangle

Examples
use mathie::{Rect, Vec2};
let rect = Rect::one();
assert!(rect.contains_pos(Vec2::new(0.5, 0.5)));
assert!(rect.contains_pos(Vec2::new(0.0, 0.0)));
assert!(rect.contains_pos(Vec2::new(1.0, 1.0)));
assert!(rect.contains_pos(Vec2::new(0.0, 1.0)));
assert!(rect.contains_pos(Vec2::new(1.0, 0.0)));
assert!(!rect.contains_pos(Vec2::new(0.0, -0.1)));
assert!(!rect.contains_pos(Vec2::new(-0.1, 0.0)));

Checks if the rectangle has a negative area

Examples
use mathie::{Rect, Vec2};
assert!(!Rect::new([0.0, 0.0], [1.0, 1.0]).is_negative());
assert!(!Rect::new([0.0, 0.0], [0.0, 0.0]).is_negative());
assert!(Rect::new([0.0, 0.0], [-1.0, -1.0]).is_negative());

Checks if the rectangle area is zero, negative or NaN.

Examples
use mathie::{Rect, Vec2};
assert!(!Rect::new([0.0, 0.0], [1.0, 1.0]).is_empty());
assert!(Rect::new([0.0, 0.0], [0.0, 0.0]).is_empty());
assert!(Rect::new([0.0, 0.0], [-1.0, -1.0]).is_empty());

Makes the rectangle smaller in the x and y directions keeping its center.

Examples
use mathie::{Rect, Vec2};
let rect = Rect::one();
assert_eq!(rect.shrink(Vec2::one()), Rect::new([0.5, 0.5], [0.0, 0.0]));
assert_eq!(rect.shrink(Vec2::one() / 2.0), Rect::new([0.25, 0.25], [0.5, 0.5]));

Makes the rectangle bigger in the x and y directions keeping its center.

Examples
use mathie::{Rect, Vec2};
let rect = Rect::one();
assert_eq!(rect.expand(Vec2::one()), Rect::new([-0.5, -0.5], [2.0, 2.0]));
assert_eq!(rect.expand(Vec2::one() / 2.0), Rect::new([-0.25, -0.25], [1.5, 1.5]));

Gets the top left corner

Gets the top right corner

Gets the bottom right corner

Gets the bottom left corner

Gets the top Y coordinate

Gets the left X coordinate

Gets the bottom Y coordinate

Gets the right X coordinate

Gets the coordinates to the center of the rectangle

Gets the coordinates to the top of the rectangle while being centered on the x axis

Gets the coordinates to the bottom of the rectangle while being centered on the x axis

Gets the coordinates to the left of the rectangle while being centered on the y axis

Gets the coordinates to the right of the rectangle while being centered on the y axis

Gets the origin of the rectangle. (top-left)

Gets the size of the rectangle

Returns the intersection between two rectangles.

Trait Implementations

The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
Performs the += operation. Read more
Performs the += operation. Read more
Performs the += operation. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
Performs the /= operation. Read more
Performs the /= operation. Read more
Performs the /= operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
Performs the *= operation. Read more
Performs the *= operation. Read more
Performs the *= operation. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
The resulting type after applying the % operator.
Performs the % operation. Read more
The resulting type after applying the % operator.
Performs the % operation. Read more
The resulting type after applying the % operator.
Performs the % operation. Read more
Performs the %= operation. Read more
Performs the %= operation. Read more
Performs the %= operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
Performs the -= operation. Read more
Performs the -= operation. Read more
Performs the -= operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.