Ember

SquareSnap()

Dec 3rd, 2011
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ------------------------------------------------------------------- //
  2. // SquareSnap(xx,yy,x1,y1,x2,y2);                                      //
  3. // Desc: Snaps a point to the closest side of a square from the inside //
  4. // Note: Replace "xx" and "yy" with the X and Y points you are setting //
  5. // ------------------------------------------------------------------- //
  6.  
  7. //Variables
  8. var xDist,yDist;
  9. xDist = (argument0-argument2) - ((argument4-argument2)/2);
  10. yDist = (argument1-argument3) - ((argument5-argument3)/2);
  11.  
  12. //Checking
  13. if abs(xDist) >= abs(yDist)
  14.     if xDist >= 0 {xx = argument4; yy = argument1;} else {xx = argument2; yy = argument1;}
  15. else
  16.     if yDist >= 0 {yy = argument5; xx = argument0;} else {yy = argument3; xx = argument0;}
  17.  
Advertisement
Add Comment
Please, Sign In to add comment