pub struct Rectangle {
pub left: f32,
pub top: f32,
pub right: f32,
pub bottom: f32,
}
Expand description
A rectangle
Fields§
§left: f32
§top: f32
§right: f32
§bottom: f32
Implementations§
Source§impl Rectangle
impl Rectangle
Sourcepub fn to_device_coordinates(self, viewport: Rectangle) -> Rectangle
pub fn to_device_coordinates(self, viewport: Rectangle) -> Rectangle
Convert a rectangle to device coordinates ([-1.0, 1.0]
) using a Viewport
.
(-1, -1) is the top left corner (0, 0), where (1, 1) is the bottom right
corner (viewport.width(), viewport.height()).
Sourcepub fn from_wh(w: f32, h: f32) -> Rectangle
pub fn from_wh(w: f32, h: f32) -> Rectangle
Construct a new rectangle with (0, 0) as (left, top), and w, h as (right, bottom)
Sourcepub fn from_xywh(x: f32, y: f32, w: f32, h: f32) -> Rectangle
pub fn from_xywh(x: f32, y: f32, w: f32, h: f32) -> Rectangle
Construct a new rectangle from a position and a size
Sourcepub fn point_inside(&self, x: f32, y: f32) -> bool
pub fn point_inside(&self, x: f32, y: f32) -> bool
Returns true
when the queried point is inside the rectangle
Sourcepub fn intersect(&self, other: &Rectangle) -> Option<Rectangle>
pub fn intersect(&self, other: &Rectangle) -> Option<Rectangle>
Returns the rectangle that is covered both by self
and other
.
None
is returned if the rectangles do not overlap.
Sourcepub fn pt(&self, x: f32, y: f32) -> [f32; 2]
pub fn pt(&self, x: f32, y: f32) -> [f32; 2]
Return a point within this rectangle. The point should be in [0, 1] range.
Sourcepub fn grow(&self, w: f32, h: f32) -> Rectangle
pub fn grow(&self, w: f32, h: f32) -> Rectangle
Increase the size of the rectangle on the right and bottom side.
Sourcepub fn inset(&self, x: f32, y: f32) -> Option<Rectangle>
pub fn inset(&self, x: f32, y: f32) -> Option<Rectangle>
Decrease the size of the rectangle on all sides
Sourcepub fn size(&self) -> Rectangle
pub fn size(&self) -> Rectangle
Return a rectangle with the same size, but positioned at the origin
Sourcepub fn after_margin(self, margin: Rectangle) -> Rectangle
pub fn after_margin(self, margin: Rectangle) -> Rectangle
Apply a margin to the rectangle
Sourcepub fn after_padding(self, padding: Rectangle) -> Rectangle
pub fn after_padding(self, padding: Rectangle) -> Rectangle
Apply padding to the rectangle