Skip to content

Instantly share code, notes, and snippets.

@seanblanton
Created December 8, 2017 18:12
Show Gist options
  • Save seanblanton/95a197c173ff901c5e6f1e248bedd292 to your computer and use it in GitHub Desktop.
Save seanblanton/95a197c173ff901c5e6f1e248bedd292 to your computer and use it in GitHub Desktop.
Check to see if a layer is overlapping another layer (+/- some threshold) or is completely inside it
Layer::isOverlapping = (targetLayer, offset = 0) ->
if @screenFrame.x + @width + offset >= targetLayer.screenFrame.x &&
@screenFrame.x - offset <= targetLayer.screenFrame.x + targetLayer.width &&
@screenFrame.y + @height + offset >= targetLayer.screenFrame.y &&
@screenFrame.y - offset <= targetLayer.screenFrame.y + targetLayer.height
true
else
false
Layer::isInside = (targetLayer, offset = 0) ->
if @screenFrame.x + offset >= targetLayer.screenFrame.x &&
@screenFrame.x - offset <= targetLayer.screenFrame.x + targetLayer.width - @width &&
@screenFrame.y + offset >= targetLayer.screenFrame.y &&
@screenFrame.y - offset <= targetLayer.screenFrame.y + targetLayer.height - @height
true
else
false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment