LineUtil.Intersect.js 679 B

123456789101112131415
  1. L.Util.extend(L.LineUtil, {
  2. // Checks to see if two line segments intersect. Does not handle degenerate cases.
  3. // http://compgeom.cs.uiuc.edu/~jeffe/teaching/373/notes/x06-sweepline.pdf
  4. segmentsIntersect: function (/*Point*/ p, /*Point*/ p1, /*Point*/ p2, /*Point*/ p3) {
  5. return this._checkCounterclockwise(p, p2, p3) !==
  6. this._checkCounterclockwise(p1, p2, p3) &&
  7. this._checkCounterclockwise(p, p1, p2) !==
  8. this._checkCounterclockwise(p, p1, p3);
  9. },
  10. // check to see if points are in counterclockwise order
  11. _checkCounterclockwise: function (/*Point*/ p, /*Point*/ p1, /*Point*/ p2) {
  12. return (p2.y - p.y) * (p1.x - p.x) > (p1.y - p.y) * (p2.x - p.x);
  13. }
  14. });