# CompGeoJS Polygon Proposed API

I’m currently working on the GeomUtils class, which is a set of low-level utilities for analytic geometry and the compGeo.shapes.Polygon class. The latter is particularly important as a lot of applications are built around polygonal shapes and this class serves as a foundation for building specific, named shapes. The API is pretty much set and all supporting code is written, however, nothing has been tested as of the time of this post. I’ve used every one of the methods proposed in past applications except for one (the isConvex() method). This is a chance for the public to comment on the completeness of the API and whether or not more methods need to be added. For example, what about an intersects() method to test if another Polygon intersects (overlaps with) the current one? In the past, I’ve handled that as a separate utility function, but it could easily be justified within the Polygon class.

Parameter and return types are Haxe-specific and are to be used as a general guide for what to pass as arguments and expect as a return in Javascript.

compGeo.shapes.Polygon

// access the number of vertices or points in the Polygon function get_numPoints():Int // access the area of the Polygon function get_area():Float // access the centroid of the Polygon function get_centroid():Point // access the axis-aligned bounding box of the Polygon function getBoundingBox(__yDown:Bool=true):Rect // scale the Polygon about its geometric center function scale(__s:Float):Void // rotate the Polygon about its geometric center function rotate(__a:Float):Void // is the specified point strictly inside the Polygon? function isInside(__x:Float, __y:Float):Bool // is the Polygon convex? function isConvex():Bool // add a vertex or point to the Polygon function addPoint(__x:Float, __y:Float):Void // assign a sequence of x-coordinates to the Polygon function setXCoordinates(__x:Array):Void // assign a sequence of y-coordinates to the Polygon function setYCoordinates(__y:Array):Void // clear the current vertex collection function clear():Void // clone the current Polygon function clone():Polygon

With luck, I’ll have a simple demo up within a week. Thanks for taking the time to look at and comment on the API.