tophat2d / tophat

:tophat: a 2d game library for Umka
https://tophat2d.dev
BSD 3-Clause "New" or "Revised" License
68 stars 5 forks source link

Add `rectIntersection` to rect.um/coll.um #194

Closed skejeton closed 1 week ago

skejeton commented 1 week ago

returns intersection rect between two rects.

fn rectIntersection*(a, b: rect::Rect): rect::Rect {
  x := max(a.x, b.x)
  y := max(a.y, b.y)
  return {x, y, min(a.x + a.w, b.x + b.w) - x, min(a.y + a.h, b.y + b.h) - y}
}

image

marekmaskarinec commented 1 week ago

Make a PR

skejeton commented 1 week ago

I'm saving this for after we're done with the API update.