Last active
June 11, 2022 01:58
-
-
Save joehonton/9f69e4b34de21df5818cb1d240023b68 to your computer and use it in GitHub Desktop.
Revisions
-
joehonton revised this gist
Jun 11, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ function isInsideClippedPolygon(polygon, mouseX, mouseY) { let c = false; // make sure there are at least 3 visible nodes var countv = 0; -
joehonton revised this gist
Jun 11, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ function isInsideClippedPolygon(polygon, mouseX, mouseY) { if (countv < 3) return false; // get the first visible node let firstv = null; for (let k=0; k < polygon.length; k++) { if (polygon[k].visible == true) { firstv = k; -
joehonton created this gist
Apr 11, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,57 @@ function isInsideClippedPolygon(polygon, mouseX, mouseY) { const c = false; // make sure there are at least 3 visible nodes var countv = 0; for (let k=0; k < polygon.length && countv < 3; k++) { if (polygon[k].visible == true) countv++; } if (countv < 3) return false; // get the first visible node const firstv = null; for (let k=0; k < polygon.length; k++) { if (polygon[k].visible == true) { firstv = k; break; } } // raycast most-recent-visible-node -> next-visible-node const mrv = firstv; for (let i=mrv+1; i < polygon.length; i++) { if (polygon[i].visible == false) continue; let j = mrv; const ix = polygon[i].x; const iy = polygon[i].y; const jx = polygon[j].x; const jy = polygon[j].y; const iySide = (iy > mouseY); const jySide = (jy > mouseY); if (iySide != jySide) { const intersectX = (jx-ix) * (mouseY-iy) / (jy-iy) + ix; if (mouseX < intersectX) c = !c; } mrv = i; } // raycast most-recent-visible-node -> first-visible-node const ix = polygon[firstv].x; const iy = polygon[firstv].y; const jx = polygon[mrv].x; const jy = polygon[mrv].y; const iySide = (iy > mouseY); const jySide = (jy > mouseY); if (iySide != jySide) { const intersectX = (jx-ix) * (mouseY-iy) / (jy-iy) + ix; if (mouseX < intersectX) c = !c; } return c; }