Skip to content

Instantly share code, notes, and snippets.

@net8floz
Created January 26, 2018 22:14
Show Gist options
  • Save net8floz/1af98cfc25d0bd4a5f5729b0298dffb5 to your computer and use it in GitHub Desktop.
Save net8floz/1af98cfc25d0bd4a5f5729b0298dffb5 to your computer and use it in GitHub Desktop.
Compare distances while avoiding square roots!
///@function point_distance_squared(x1, y1, x2, y2)
///@desc Compare distances while avoiding square roots! If you must compare
/// the result with a non squared value... simply square it!
/// if(point_distance_squared() > max * max){
///
/// }
///@param x1
///@param y1
///@param x2
///@param y2
var _x1 = argument0,
_y1 = argument1,
_x2 = argument2,
_y2 = argument3,
_dx = (_x2 - _x1),
_dy = (_y2 - _y1);
return _dx * _dx + _dy * _dy;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment