Something went wrong. Try again.
A charm-like tui library
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435//! An axis-aligned rectangle given as min/max corners (half-open bounds).//! Mirrors `image.Rectangle`.const Rectangle = @This();
min_x: usize = 0,min_y: usize = 0,max_x: usize = 0,max_y: usize = 0,
pub fn new(x: usize, y: usize, w: usize, h: usize) Rectangle { return .{ .min_x = x, .min_y = y, .max_x = x + w, .max_y = y + h };}
pub fn width(self: Rectangle) usize { return self.max_x - self.min_x;}
pub fn height(self: Rectangle) usize { return self.max_y - self.min_y;}
pub fn empty(self: Rectangle) bool { return self.max_x <= self.min_x or self.max_y <= self.min_y;}
pub fn overlaps(self: Rectangle, other: Rectangle) bool { return self.min_x < other.max_x and self.max_x > other.min_x and self.min_y < other.max_y and self.max_y > other.min_y;}
pub fn inside(self: Rectangle, other: Rectangle) bool { return self.min_x >= other.min_x and self.min_y >= other.min_y and self.max_x <= other.max_x and self.max_y <= other.max_y;}