Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Last active September 28, 2021 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YonatanKra/6b3e85c685fc5e717c066bbe2bfcf7e0 to your computer and use it in GitHub Desktop.
Save YonatanKra/6b3e85c685fc5e717c066bbe2bfcf7e0 to your computer and use it in GitHub Desktop.
function isCircleInPath(circleData, path) {
const ctx = document.createElement("canvas").getContext("2d");
const radius = circleData.radius;
for (
let x = circleData.x - radius;
x <= circleData.x + 2 * radius;
x += radius
) {
for (
let y = circleData.y - radius;
y <= circleData.y + 2 * radius;
y += radius
) {
if (ctx.isPointInPath(path, x, y)) return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment