LineUtil.Intersect.js 785 B

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