windingLine.js 405 B

123456789101112131415
  1. export default function windingLine(x0, y0, x1, y1, x, y) {
  2. if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
  3. return 0;
  4. }
  5. if (y1 === y0) {
  6. return 0;
  7. }
  8. var t = (y - y0) / (y1 - y0);
  9. var dir = y1 < y0 ? 1 : -1;
  10. if (t === 1 || t === 0) {
  11. dir = y1 < y0 ? 0.5 : -0.5;
  12. }
  13. var x_ = t * (x1 - x0) + x0;
  14. return x_ === x ? Infinity : x_ > x ? dir : 0;
  15. }