Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* /tests/Geometry/Polygon.html */
- function testGetCentroid(t) {
- t.plan(4);
- var bounds = new OpenLayers.Bounds(5, 10, 5, 10);
- var geometry = bounds.toGeometry();
- var centroid = geometry.getCentroid();
- t.eq(geometry.components[0].components.length, 2, "only two vertices since the box has left=right and bottom=top");
- 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");
- bounds = new OpenLayers.Bounds(123456789.0, 123456789.0, 123456789.1, 123456789.1);
- geometry = bounds.toGeometry();
- centroid = geometry.getCentroid();
- t.eq(geometry.components[0].components.length, 5, "five vertices expected");
- var dX = Math.abs(centroid.x - 123456789.05);
- var dY = Math.abs(centroid.y - 123456789.05);
- t.ok(centroid && dX < 0.0001 && dY < 0.0001, " getCentroid returns the correct point geometry dX = " + dX + ", dY = " + dY);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement