Struct sark_grids::geometry::GridRect
source · pub struct GridRect {
pub center: IVec2,
/* private fields */
}
Expand description
A rectangle of points on a grid.
Fields§
§center: IVec2
Implementations§
source§impl GridRect
impl GridRect
pub fn new(center: impl GridPoint, size: impl GridPoint) -> GridRect
pub fn width(&self) -> usize
pub fn height(&self) -> usize
sourcepub fn from_points(a: impl GridPoint, b: impl GridPoint) -> GridRect
pub fn from_points(a: impl GridPoint, b: impl GridPoint) -> GridRect
Create a grid rect from a min and max position.
sourcepub fn from_bl(pos: impl GridPoint, size: impl GridPoint) -> GridRect
pub fn from_bl(pos: impl GridPoint, size: impl GridPoint) -> GridRect
Create a rect with the bottom left corner at the given position.
sourcepub fn min_i(&self) -> IVec2
pub fn min_i(&self) -> IVec2
Retrieve the bottom-left-most point of the rect as a grid position
pub fn min_max_i(&self) -> [IVec2; 2]
pub fn size(&self) -> IVec2
sourcepub fn pivot_point(&self, pivot: Pivot) -> IVec2
pub fn pivot_point(&self, pivot: Pivot) -> IVec2
Retrieve the position of a given corner of the rect
sourcepub fn resized(&self, amount: impl GridPoint) -> GridRect
pub fn resized(&self, amount: impl GridPoint) -> GridRect
Return a rect with the same center but resized by the given amount on each axis
sourcepub fn translated(&self, xy: impl GridPoint) -> GridRect
pub fn translated(&self, xy: impl GridPoint) -> GridRect
Returns a rect with it’s position adjusted by the given amount
sourcepub fn contains_rect(&self, rect: GridRect) -> bool
pub fn contains_rect(&self, rect: GridRect) -> bool
Returns true if the given rect is entirely contained within this one.
sourcepub fn envelope_point(&mut self, point: impl GridPoint)
pub fn envelope_point(&mut self, point: impl GridPoint)
Adjusts a single corner of the rect to contain the given point if it isn’t already.
pub fn envelope_rect(&mut self, rect: GridRect)
sourcepub fn corners(&self) -> Corners
pub fn corners(&self) -> Corners
Returns the 4 corners of the rect, which can be accessed by index or name.
Order is BottomLeft, TopLeft, TopRight, BottomRight
sourcepub fn iter_border(&self) -> BorderIterator
pub fn iter_border(&self) -> BorderIterator
Returns an iterator that visits the position of every border tile in the rect.