[go: up one dir, main page]

[]Struct piet_common::kurbo::Rect

pub struct Rect {
    pub x0: f64,
    pub y0: f64,
    pub x1: f64,
    pub y1: f64,
}

A rectangle.

Fields

x0: f64

The minimum x coordinate (left edge).

y0: f64

The minimum y coordinate (top edge in y-down spaces).

x1: f64

The maximum x coordinate (right edge).

y1: f64

The maximum y coordinate (bottom edge in y-down spaces).

Methods

impl Rect

pub fn new(x0: f64, y0: f64, x1: f64, y1: f64) -> Rect

A new rectangle from minimum and maximum coordinates.

pub fn from_points(p0: Point, p1: Point) -> Rect

A new rectangle from two points.

The result will have non-negative width and height.

pub fn from_origin_size(origin: Point, size: Size) -> Rect

A new rectangle from origin and size.

The result will have non-negative width and height.

pub fn with_origin(self, origin: Point) -> Rect

Create a new Rect with the same size as self and a new origin.

pub fn with_size(self, size: Size) -> Rect

Create a new Rect with the same origin as self and a new size.

pub fn width(&self) -> f64

The width of the rectangle.

Note: nothing forbids negative width.

pub fn height(&self) -> f64

The height of the rectangle.

Note: nothing forbids negative height.

pub fn origin(&self) -> Point

The origin of the vector.

This is the top left corner in a y-down space and with non-negative width and height.

pub fn size(&self) -> Size

The size of the rectangle, as a vector.

pub fn area(&self) -> f64

The area of the rectangle.

pub fn center(&self) -> Point

The center point of the rectangle.

pub fn abs(&self) -> Rect

Take absolute value of width and height.

The resulting rect has the same extents as the original, but is guaranteed to have non-negative width and height.

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

The smallest rectangle enclosing two rectangles.

Results are valid only if width and height are non-negative.

pub fn union_pt(&self, pt: Point) -> Rect

Compute the union with one point.

This method includes the perimeter of zero-area rectangles. Thus, a succession of union_pt operations on a series of points yields their enclosing rectangle.

Results are valid only if width and height are non-negative.

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

The intersection of two rectangles.

The result is zero-area if either input has negative width or height. The result always has non-negative width and height.

pub fn inflate(&self, width: f64, height: f64) -> Rect

Expand a rectangle by a constant amount in both directions.

The logic simply applies the amount in each direction. If rectangle area or added dimensions are negative, this could give odd results.

Trait Implementations

impl Add<Vec2> for Rect

type Output = Rect

The resulting type after applying the + operator.

impl Sub<Vec2> for Rect

type Output = Rect

The resulting type after applying the - operator.

impl Debug for Rect

impl Default for Rect

impl Shape for Rect

type BezPathIter = RectPathIter

The iterator resulting from to_bez_path.

fn winding(&self, pt: Point) -> i32

Note: this function is carefully designed so that if the plane is tiled with rectangles, the winding number will be nonzero for exactly one of them.

fn into_bez_path(self, tolerance: f64) -> BezPath

fn as_line(&self) -> Option<Line>

If the shape is a line, make it available.

fn as_circle(&self) -> Option<Circle>

If the shape is a circle, make it available.

fn as_path_slice(&self) -> Option<&[PathEl]>

If the shape is stored as a slice of path elements, make that available. Read more

impl Clone for Rect

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Copy for Rect

impl From<((f64, f64), (f64, f64))> for Rect

impl From<(Point, Point)> for Rect

impl From<(Point, Size)> for Rect

Auto Trait Implementations

impl Send for Rect

impl Sync for Rect

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> RoundFrom<T> for T[src]

impl<T, U> RoundInto<U> for T where
    U: RoundFrom<T>, 
[src]