vito-Z80

intersectingRectangle (class Rectangle in LibGdx)

Sep 27th, 2018
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.78 KB | None | 0 0
  1. fun Rectangle.intersectingRectangle(r: Rectangle): Rectangle {
  2.  
  3.     if (!this.overlaps(r)) {
  4.         Rectangle.tmp.set(0f, 0f, 0f, 0f)
  5.         return Rectangle.tmp
  6.     }
  7.  
  8.     var w = 0f
  9.     var h = 0f
  10.     var x1 = 0f
  11.     var y1 = 0f
  12.  
  13.     if (r.x > x) {
  14.         x1 = r.x
  15.         w = if (x + width > r.x + r.width) r.width
  16.         else x + width - r.x
  17.     } else {
  18.         x1 = x
  19.         w = if (r.x + r.width > x + width) width
  20.         else r.x + r.width - x
  21.     }
  22.  
  23.     if (r.y > y) {
  24.         y1 = r.y
  25.         h = if (y + height > r.y + r.height) r.height
  26.         else y + height - r.y
  27.     } else {
  28.         y1 = y
  29.         h = if (r.y + r.height > y + height) height
  30.         else r.y + r.height - y
  31.     }
  32.  
  33.     Rectangle.tmp.set(x1, y1, w, h)
  34.     return Rectangle.tmp
  35. }
Advertisement
Add Comment
Please, Sign In to add comment