Advertisement
Guest User

OL APIMethod: getCentroid TEST

a guest
Mar 29th, 2012
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement