equal
deleted
inserted
replaced
245 size.width as u32, |
245 size.width as u32, |
246 size.height as u32, |
246 size.height as u32, |
247 ) |
247 ) |
248 } |
248 } |
249 |
249 |
|
250 pub fn at_origin(size: Size) -> Self { |
|
251 Rect::from_size(Point::zero(), size) |
|
252 } |
|
253 |
250 #[inline] |
254 #[inline] |
251 pub fn size(&self) -> Size { |
255 pub fn size(&self) -> Size { |
252 Size::new(self.width as usize, self.height as usize) |
256 Size::new(self.width as usize, self.height as usize) |
253 } |
257 } |
254 |
258 |
278 } |
282 } |
279 |
283 |
280 #[inline] |
284 #[inline] |
281 pub fn top_left(&self) -> Point { |
285 pub fn top_left(&self) -> Point { |
282 Point::new(self.x, self.y) |
286 Point::new(self.x, self.y) |
|
287 } |
|
288 |
|
289 #[inline] |
|
290 pub fn bottom_right(&self) -> Point { |
|
291 Point::new(self.right(), self.bottom()) |
|
292 } |
|
293 |
|
294 #[inline] |
|
295 pub fn center(&self) -> Point { |
|
296 (self.top_left() + self.bottom_right()) / 2 |
283 } |
297 } |
284 |
298 |
285 #[inline] |
299 #[inline] |
286 pub fn with_margin(&self, margin: i32) -> Self { |
300 pub fn with_margin(&self, margin: i32) -> Self { |
287 Rect::from_box( |
301 Rect::from_box( |
320 pub fn intersects(&self, other: &Rect) -> bool { |
334 pub fn intersects(&self, other: &Rect) -> bool { |
321 self.left() <= self.right() |
335 self.left() <= self.right() |
322 && self.right() >= other.left() |
336 && self.right() >= other.left() |
323 && self.top() <= other.bottom() |
337 && self.top() <= other.bottom() |
324 && self.bottom() >= other.top() |
338 && self.bottom() >= other.top() |
|
339 } |
|
340 |
|
341 #[inline] |
|
342 pub fn split_at(&self, point: Point) -> [Rect; 4] { |
|
343 assert!(self.contains_inside(point)); |
|
344 [ |
|
345 Rect::from_box(self.left(), point.x, self.top(), point.y), |
|
346 Rect::from_box(point.x, self.right(), self.top(), point.y), |
|
347 Rect::from_box(self.left(), point.x, point.y, self.bottom()), |
|
348 Rect::from_box(point.x, self.right(), point.y, self.bottom()) |
|
349 ] |
325 } |
350 } |
326 } |
351 } |
327 |
352 |
328 pub struct Polygon { |
353 pub struct Polygon { |
329 vertices: Vec<Point> |
354 vertices: Vec<Point> |