arc.js 992 B

1234567891011121314151617181920212223242526272829303132333435
  1. import { normalizeRadian } from './util.js';
  2. var PI2 = Math.PI * 2;
  3. export function containStroke(cx, cy, r, startAngle, endAngle, anticlockwise, lineWidth, x, y) {
  4. if (lineWidth === 0) {
  5. return false;
  6. }
  7. var _l = lineWidth;
  8. x -= cx;
  9. y -= cy;
  10. var d = Math.sqrt(x * x + y * y);
  11. if ((d - _l > r) || (d + _l < r)) {
  12. return false;
  13. }
  14. if (Math.abs(startAngle - endAngle) % PI2 < 1e-4) {
  15. return true;
  16. }
  17. if (anticlockwise) {
  18. var tmp = startAngle;
  19. startAngle = normalizeRadian(endAngle);
  20. endAngle = normalizeRadian(tmp);
  21. }
  22. else {
  23. startAngle = normalizeRadian(startAngle);
  24. endAngle = normalizeRadian(endAngle);
  25. }
  26. if (startAngle > endAngle) {
  27. endAngle += PI2;
  28. }
  29. var angle = Math.atan2(y, x);
  30. if (angle < 0) {
  31. angle += PI2;
  32. }
  33. return (angle >= startAngle && angle <= endAngle)
  34. || (angle + PI2 >= startAngle && angle + PI2 <= endAngle);
  35. }