AS3 Polygon Clipper
I was looking for an open source polygon clipper library for AS3 to use on a commercial project.
I found a few ports of the General Polygon Clipper library (GPC) but it is only free for non-commercial projects.
After more searching around I found this excellent library called Clipper by Angus Johnson. It did not have an AS3 port so I made one using Alchemy to wrap the c++ code.
The SWC and source code can be found on github: https://github.com/Flassari/as3clipper
It is completely free and open source for both personal and commercial projects. Clipper uses the Boost Software License.
Supported clipping operations: difference, intersection, union and XOR.
Here’s an example of how to use the AS3 port after importing the Clipper.swc file:
import com.flassari.geom.Clipper; import com.flassari.geom.ClipType; var subjectPolygon:Array = [new Point(0, 0), new Point(200, 0), new Point(100, 200)]; var clipPolygon:Array = [new Point(0, 100), new Point(200, 100), new Point(300, 200)]; var resultPolygons:Array = Clipper.clipPolygon(subjectPolygon, clipPolygon, ClipType.DIFFERENCE);
Update
There is now an AS3 port available at https://github.com/ChrisDenham/PolygonClipper.AS3
Tags: alchemy, AS3, boolean, clip, clipper, clipping, commercial, delete, Flash, free, github, GPC, library, mask, open source, polygon, polygon boolean operation, remove, subtract, swc
November 10th, 2011 at 07:59
Hi!
Excellent work with the wrapper. It was just what I needed. One observation though. The very first call to clipPolygon takes a very long time. Is there something that can be done about it?
November 15th, 2011 at 13:11
It happens because it is initializing the C library. You can not get rid of it, but you CAN choose when it happens. Just make a bogus call to it in the loading part of your code, people shouldn’t notice it that much.
December 1st, 2011 at 11:19
Hello,
Can you add method clipPolygons that work with
Polygons subjectPolygons
it’s will be amazing, i found that Clipper by Angus Johnson has this functionality.
March 9th, 2012 at 09:53
Thanks buddy. Thank you so much. This was the exact thing we have been searching for.
May 22nd, 2012 at 16:45
Hi, just want to say a big thank you for this, its working fantastic for me.
How much of the lib is converted to Alchemy? the SimplifyPolygons function looks really useful too.
May 28th, 2012 at 20:49
All of the lib is converted to alchemy, but to use the functions one would have to write a c++ function to expose that functionality. I haven’t had time to update the project for a while, but anyone can fork it and add to it.
December 4th, 2012 at 08:05
Hello again!
Now that the flascc has been released, have you thought about making a new version? Might be interesting to see if the new compiler produces faster code.
January 3rd, 2013 at 11:13
Hi Olli!
Actually, Chris Denham has created a new port that is pure AS3, you can find it at https://github.com/ChrisDenham/PolygonClipper.AS3
I’d recommend using that one since Adobe made flascc a “Premium Feature”.
http://www.adobe.com/devnet/flashplayer/articles/premium-features-licensing-faq.html
I will probably look into porting Clipper to flascc eventually, but until then I recommend you check out Chris’ port =)
March 10th, 2013 at 02:37
Wow, thank you. This is what I need :D