How to use point-in-svg-path - 2 common examples

To help you get started, we’ve selected a few point-in-svg-path examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openshift / console / frontend / packages / topology / src / behavior / useDndDrop.tsx View on Github external
// perform a fast bounds check
          const { left, right, top, bottom } = nodeRef.current.getBBox();
          if (x < left || x > right || y < top || y > bottom) {
            return false;
          }

          // Rounding the coordinates due to an issue with `point-in-svg-path` returning false
          // when the coordinates clearly are within the path.
          const point = Point.singleUse(Math.round(x), Math.round(y));
          // Translate to this element's coordinates.
          // Assumes the node is not within an svg element containing another transform.
          elementRef.current.translateFromAbsolute(point);

          if (nodeRef.current instanceof SVGPathElement) {
            const d = nodeRef.current.getAttribute('d');
            return pointInSvgPath(d, point.x, point.y);
          }
          if (nodeRef.current instanceof SVGCircleElement) {
            const { cx, cy, r } = nodeRef.current;
            return (
              Math.sqrt((point.x - cx.animVal.value) ** 2 + (point.y - cy.animVal.value) ** 2) <
              r.animVal.value
            );
          }
          if (nodeRef.current instanceof SVGEllipseElement) {
            const { cx, cy, rx, ry } = nodeRef.current;
            return (
              (point.x - cx.animVal.value) ** 2 / rx.animVal.value ** 2 +
                (point.y - cy.animVal.value) ** 2 / ry.animVal.value ** 2 <=
              1
            );
          }
github openshift / console / frontend / packages / dev-console / src / components / topology / shapes / DefaultGroup.tsx View on Github external
public isPointInGroup = (point: PointTuple): boolean => {
    const { containerPath } = this.state;
    return pointInSvgPath(containerPath, point[0], point[1]);
  };

point-in-svg-path

Checks if a point is in an svg path

ISC
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis

Popular point-in-svg-path functions