Struct Rect

Source
pub struct Rect { /* private fields */ }
Expand description

Rectangle

Must have flat edges, to rotate first convert to Polygon using Rect::as_polygon()

Implementations§

Source§

impl Rect

Source

pub fn new<P1, P2>(top_left: P1, bottom_right: P2) -> Rect
where P1: Into<Coord>, P2: Into<Coord>,

Source

pub fn new_with_size<P>(start: P, width: usize, height: usize) -> Rect
where P: Into<Coord>,

Source§

impl Rect

Source

pub fn width(&self) -> usize

Source

pub fn height(&self) -> usize

Source

pub fn top_left(&self) -> Coord

Source

pub fn bottom_right(&self) -> Coord

Source

pub fn is_square(&self) -> bool

Source§

impl Rect

Source

pub fn as_inner_circle(&self) -> Circle

Create a circle around the center to the closest edge

Source

pub fn as_outer_circle(&self) -> Circle

Create a circle around the center to the farthest edge

Source

pub fn as_triangles(&self) -> (Triangle, Triangle)

Create two triangles (top left and bottom right right angles)

Source

pub fn as_polygon(&self) -> Polygon

Same shape but represented as four points/lines instead of two points

Source

pub fn as_outer_ellipse(&self) -> Ellipse

Source

pub fn as_lines(&self) -> [Line; 4]

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 ContainsShape for Rect

Source§

fn contains_circle(&self, circle: &Circle) -> bool

Returns true if self contains circle
Source§

fn contains_rect(&self, rect: &Rect) -> bool
where Self: Sized + Shape,

Returns true if self contains rect
Source§

fn contains_line(&self, line: &Line) -> bool
where Self: Sized + Shape,

Returns true if self contains line
Source§

fn contains_triangle(&self, triangle: &Triangle) -> bool
where Self: Sized + Shape,

Returns true if self contains triangle
Source§

fn contains_ellipse(&self, ellipse: &Ellipse) -> bool
where Self: Sized + Shape,

Returns true if self contains ellipse
Source§

fn contains_polygon(&self, polygon: &Polygon) -> bool
where Self: Sized + Shape,

Returns true if self contains polygon
Source§

impl CreateDrawable<Rect> for Drawable<Rect>

Source§

fn from_obj(shape: Rect, draw_type: DrawType) -> Drawable<Rect>

Source§

impl Debug for Rect

Source§

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

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

impl<'de> Deserialize<'de> for Rect

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Rect, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Hash for Rect

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl IntersectsContains for Rect

Source§

fn contains_shape(&self, other: &(dyn Shape + 'static)) -> Option<bool>

Returns Read more
Source§

fn intersects_shape(&self, other: &(dyn Shape + 'static)) -> Option<bool>

Returns Read more
Source§

impl IntersectsShape for Rect

Source§

fn intersects_rect(&self, rect: &Rect) -> bool

Returns true if rect intersects self
Source§

fn intersects_circle(&self, circle: &Circle) -> bool

Returns true if circle intersects self
Source§

fn intersects_line(&self, line: &Line) -> bool

Returns true if line intersects self
Source§

fn intersects_triangle(&self, triangle: &Triangle) -> bool

Returns true if triangle intersects self
Source§

fn intersects_ellipse(&self, ellipse: &Ellipse) -> bool

Returns true if ellipse intersects self
Source§

fn intersects_polygon(&self, polygon: &Polygon) -> bool

Returns true if polygon intersects self
Source§

impl PartialEq for Rect

Source§

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

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Shape for Rect

Source§

fn from_points(points: &[Coord]) -> Rect
where Rect: Sized,

create this shape from a list of points (corners of a shape or tips of a line)
Source§

fn rebuild(&self, points: &[Coord]) -> Rect
where Rect: Sized,

Used internally
Source§

fn contains(&self, point: Coord) -> bool

Returns true if the shape contains point
Source§

fn points(&self) -> Vec<Coord>

Points(corners/ends) the shape is made of
Source§

fn rotate_around(&self, degrees: isize, point: Coord) -> Rect
where Rect: Sized,

Rotate shape around a point
Source§

fn center(&self) -> Coord

Center of shape
Source§

fn left(&self) -> isize

x of the left most point
Source§

fn right(&self) -> isize

x of the right most point
Source§

fn top(&self) -> isize

y of the top most point
Source§

fn bottom(&self) -> isize

y of the bottom most point
Source§

fn outline_pixels(&self) -> Vec<Coord>

The coords for drawing the shape outline, the points may be in any order This should be cached rather than called per frame
Source§

fn filled_pixels(&self) -> Vec<Coord>

The coords for drawing the filled shape, the points may be in any order This should be cached rather than called per frame
Source§

fn to_shape_box(&self) -> ShapeBox

Convert to ShapeBox, used to store shapes with type (for bulk drawing, etc)
Source§

fn translate_by(&self, delta: Coord) -> Self
where Self: Sized,

change every point by +delta
Source§

fn move_to(&self, point: Coord) -> Self
where Self: Sized,

moves the shapes first point to point (and changes every other point to match their original distance and angle) Read more
Source§

fn move_center_to(&self, point: Coord) -> Self
where Self: Sized,

Moves the shapes center to point (and changes every other point to match their original distance and angle) Read more
Source§

fn rotate(&self, degrees: isize) -> Self
where Self: Sized,

Rotate shape around it’s center
Source§

fn top_left(&self) -> Coord

Source§

fn top_right(&self) -> Coord

Source§

fn bottom_left(&self) -> Coord

Source§

fn bottom_right(&self) -> Coord

Source§

fn scale(&self, factor: f32) -> Self
where Self: Sized,

Scale the shape by factor (around the center, so the change will be uniform)
Source§

fn scale_around(&self, factor: f32, point: Coord) -> Self
where Self: Sized,

Scale the shape by factor around point
Source§

impl Eq 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> AnyToAny for T
where T: 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,