2 ms·
Yup, that looks right, but it can be made even simpler in this case because one of the segments is always vertical. var prevOffset = prev.x-lowerRight.x; l
by bazzargh 14y ago
Yup, that looks right, but it can be made even simpler in this case because one of the segments is always vertical.
var prevOffset = prev.x-lowerRight.x;
loc.x < lowerRight.x
&& (loc.y-prev.y)*-prevOffset-(loc.x-prev.x)*(upperRight.y-prev.y) <0
&& (loc.y-lowerRight.y)*prevOffset-(loc.x-lowerRight.x)*(prev.y-lowerRight.y) < 0
This is in fact equivalent to what's in jQuery.menu-aim.js, eg upperSlope < prevUpperSlope => upperSlope - prevUpperSlope < 0, then inline slope() and multiply through by the denominators.
I'd prefer the code above though, as there's no icky division by zero.