Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. function closestEdge(x,y,w,h) {
  2. var topEdgeDist = distMetric(x,y,w/2,0);
  3. var bottomEdgeDist = distMetric(x,y,w/2,h);
  4. var leftEdgeDist = distMetric(x,y,0,h/2);
  5. var rightEdgeDist = distMetric(x,y,w,h/2);
  6. var min = Math.min(topEdgeDist,bottomEdgeDist,leftEdgeDist,rightEdgeDist);
  7. switch (min) {
  8. case leftEdgeDist:
  9. return "left";
  10. case rightEdgeDist:
  11. return "right";
  12. case topEdgeDist:
  13. return "top";
  14. case bottomEdgeDist:
  15. return "bottom";
  16. }
  17. }
  18.  
  19. function distMetric(x,y,x2,y2) {
  20. var xDiff = x - x2;
  21. var yDiff = y - y2;
  22. return (xDiff * xDiff) + (yDiff * yDiff);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement