Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun Rectangle.intersectingRectangle(r: Rectangle): Rectangle {
- if (!this.overlaps(r)) {
- Rectangle.tmp.set(0f, 0f, 0f, 0f)
- return Rectangle.tmp
- }
- var w = 0f
- var h = 0f
- var x1 = 0f
- var y1 = 0f
- if (r.x > x) {
- x1 = r.x
- w = if (x + width > r.x + r.width) r.width
- else x + width - r.x
- } else {
- x1 = x
- w = if (r.x + r.width > x + width) width
- else r.x + r.width - x
- }
- if (r.y > y) {
- y1 = r.y
- h = if (y + height > r.y + r.height) r.height
- else y + height - r.y
- } else {
- y1 = y
- h = if (r.y + r.height > y + height) height
- else r.y + r.height - y
- }
- Rectangle.tmp.set(x1, y1, w, h)
- return Rectangle.tmp
- }
Advertisement
Add Comment
Please, Sign In to add comment