cubic.js 952 B

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