News for hackers. Stuff that matters.
Re:Breaking down Amazon's mega dropdown by bazzargh on Wednesday March 06, 2013 @10:48AM (#5331713)
I'm guessing that the cross product magic was a hit test for a triangle. Here's an explanation:

http://www.blackpawn.com/texts/pointinpoly/default.html

Re:Breaking down Amazon's mega dropdown by jamesmiller5 on Wednesday March 06, 2013 @11:31AM (#5331979)
Here are a few different solutions to determine if a point is in a polygon with code examples. I think solution 3 might be applicable and faster.

Section: Determining if a point lies on the interior of a polygon http://paulbourke.net/geometry/polygonmesh/

Re:Breaking down Amazon's mega dropdown by bazzargh on Wednesday March 06, 2013 @12:45PM (#5332481)
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.

Re:Breaking down Amazon's mega dropdown by slig on Wednesday March 06, 2013 @11:07AM (#5331817)
Got it, thanks! Should've thought about googling "hit test triangle".