Check out the Pastebin Gadgets Shop. We have thousands of fun, geeky & affordable gadgets on sale :-)Want more features on Pastebin? Sign Up, it's FREE!

OL APIMethod: getCentroid TEST

By: a guest on Mar 29th, 2012  |  syntax: JavaScript  |  size: 0.96 KB  |  views: 37  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. /* /tests/Geometry/Polygon.html */
2. function testGetCentroid(t) {
3.     t.plan(4);
4.     var bounds = new OpenLayers.Bounds(5, 10, 5, 10);
5.     var geometry = bounds.toGeometry();
6.     var centroid = geometry.getCentroid();
7.     t.eq(geometry.components[0].components.length, 2, "only two vertices since the box has left=right and bottom=top");
8.     t.ok(centroid && centroid.x === 5 && centroid.y === 10, "getCentroid returns a point geometry even if the ring of the polygon has only 2 vertices");
9.     bounds = new OpenLayers.Bounds(123456789.0, 123456789.0, 123456789.1, 123456789.1);
10.     geometry = bounds.toGeometry();
11.     centroid = geometry.getCentroid();
12.     t.eq(geometry.components[0].components.length, 5, "five vertices expected");
13.     var dX = Math.abs(centroid.x - 123456789.05);
14.     var dY = Math.abs(centroid.y - 123456789.05);
15.     t.ok(centroid && dX < 0.0001 && dY < 0.0001, " getCentroid returns the correct point geometry dX = " + dX + ", dY = " + dY);
16. }
clone this paste RAW Paste Data
Top