polygon-clipping
polygon-clipping copied to clipboard
Example of use without node.js
Thanx a lot for you lib Please can you give a small example of using it without node.js We have "snake" track and we need to calculate interselections and show it. is anyone hase the same task ?
Hi @yurikaz
Depending on how your app is setup you should be able to use the files within the dist
directory of this repo as they have been compiled and are ready for use in the browser.
So for example with the most basic approach you should be able to do something like
// Include one of the dist files in your html doc
<script src="polygon-clipping.min.js"></script>
// Then reference the lib using the polygon-clipping global var that is exposed
<script>
const poly1 = [[[0,0],[2,0],[0,2],[0,0]]]
const poly2 = [[[-1,0],[1,0],[0,1],[-1,0]]]
polygon-clipping.union(poly1, poly2)
</script>
Hope that helps
Thanx for your answer. When I am doing something lile this I have an error "Uncaught ReferenceError: polygon is not defined"
I think if we change in js "polygon-clipping" to "polygonclipping" it will work
ah yes of course the hyphen isn't ideal, that said as a temporary work around you can do something like window['polygon-clipping'].union(poly1, poly2)
Agreed, it would be good to add to the README quickstart instructions for use directly in the browser. I'll try to fit this into the next non-bug-fix-focused release.