Offsetting polygons in Javascript

There are no simple solutions when it comes to polygon inflating. If you have a concave polygon, sooner or later it will break into several smaller polygons if you decrease the offset enough. So I would suggest using an existing, proven, algorithm (Clipper should be a good one).

On your question about porting C# to JS, I would say it's certainly possible, but the question is how much time it would take and whether the auto-porting tools will be of any use. Judging from this discussion, I doubt it:

I took a quick stab at using ScriptSharp to translate the C# code to Javascript, but there are too many incompatible structures to use that and I couldn't get it to output a javascript file. Trying to implement the Vatti clipping algorithm in Javascript seems to be the next step.

...

And yes, it won't help you using all sorts of automatics conversion tools.The clipper has data structures like Int64 or Int128 which are non existent in JS or AS .I just removed them altogether .Int32 should be enough for most cases unless you work on smth related to geography or huge maps .

The ActionScript port one of the users there mentions is no longer available, unfortunately.


I have succeded in porting clipper to JS, and after a while, after thorough testing going to release it. Seems that all the functionality could have been ported.

One caveat, 128bit support is reduced to 106bit.

One of the pros is to reach large space of browsers and possibility to use svg, vml, html5 canvas as graphics interface.

Any ideas, Which host would be easiest to publish, with demo possibility?


EDIT:

Finally got Angus Johnson's Clipper library implemented in Javascript and selected Sourceforge for host.

LIVE DEMO: http://jsclipper.sourceforge.net/6.1.1.1/main_demo.html

Downloads: https://sourceforge.net/projects/jsclipper/

Wikipage with step-by-step tutorial: https://sourceforge.net/p/jsclipper/wiki/Home%206/

Presentation of Demo Program including tens of sample polygons: https://sourceforge.net/p/jsclipper/wiki/Main_Demo%206/

I hope this helps anyone who needs polyline and polygon clipping library with offsetting features.