quadratic.js 886 B

123456789101112131415161718192021222324252627282930313233
  1. var _curve = require("../core/curve");
  2. var quadraticProjectPoint = _curve.quadraticProjectPoint;
  3. /**
  4. * 二次贝塞尔曲线描边包含判断
  5. * @param {number} x0
  6. * @param {number} y0
  7. * @param {number} x1
  8. * @param {number} y1
  9. * @param {number} x2
  10. * @param {number} y2
  11. * @param {number} lineWidth
  12. * @param {number} x
  13. * @param {number} y
  14. * @return {boolean}
  15. */
  16. function containStroke(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  17. if (lineWidth === 0) {
  18. return false;
  19. }
  20. var _l = lineWidth; // Quick reject
  21. if (y > y0 + _l && y > y1 + _l && y > y2 + _l || y < y0 - _l && y < y1 - _l && y < y2 - _l || x > x0 + _l && x > x1 + _l && x > x2 + _l || x < x0 - _l && x < x1 - _l && x < x2 - _l) {
  22. return false;
  23. }
  24. var d = quadraticProjectPoint(x0, y0, x1, y1, x2, y2, x, y, null);
  25. return d <= _l / 2;
  26. }
  27. exports.containStroke = containStroke;