| | 174 | } |
|---|
| | 175 | |
|---|
| | 176 | function test_Polygon_createRegular(t) { |
|---|
| | 177 | t.plan(22); |
|---|
| | 178 | var sides = 40; |
|---|
| | 179 | var poly = OpenLayers.Geometry.Polygon.createRegularPolygon(new OpenLayers.Geometry.Point(5,0), 6, sides); |
|---|
| | 180 | var polyBounds = poly.getBounds(); |
|---|
| | 181 | t.eq(polyBounds.toBBOX(), "-0.981504,-5.981504,10.981504,5.981504", sides + " sided figure generates correct bbox."); |
|---|
| | 182 | t.eq(poly.components.length, 1, "Poly has one linear ring"); |
|---|
| | 183 | t.eq(poly.components[0].components.length, sides + 1, "ring has 41 components"); |
|---|
| | 184 | t.eq(poly.components[0].components[0].id, poly.components[0].components[sides].id, "ring starts and ends with same geom"); |
|---|
| | 185 | t.eq(Math.round(poly.getArea()), Math.round(Math.PI * 36), "area of "+sides+" sided poly rounds to same area as a circle."); |
|---|
| | 186 | |
|---|
| | 187 | var sides = 3; |
|---|
| | 188 | var poly = OpenLayers.Geometry.Polygon.createRegularPolygon(new OpenLayers.Geometry.Point(5,0), 6, sides); |
|---|
| | 189 | var polyBounds = poly.getBounds(); |
|---|
| | 190 | t.eq(polyBounds.toBBOX(), "-0.196152,-3,10.196152,6", sides + " sided figure generates correct bbox."); |
|---|
| | 191 | t.eq(poly.components.length, 1, "Poly has one linear ring"); |
|---|
| | 192 | t.eq(poly.components[0].components.length, sides + 1, "ring has correct count of components"); |
|---|
| | 193 | t.eq(poly.components[0].components[0].id, poly.components[0].components[sides].id, "ring starts and ends with same geom"); |
|---|
| | 194 | t.eq(Math.round(poly.getArea()), 47, "area of 3 sided poly is correct"); |
|---|
| | 195 | |
|---|
| | 196 | var sides = 3; |
|---|
| | 197 | var poly3 = OpenLayers.Geometry.Polygon.createRegularPolygon(new OpenLayers.Geometry.Point(10,0), 15, sides); |
|---|
| | 198 | var polyBounds = poly3.getBounds(); |
|---|
| | 199 | t.eq(polyBounds.toBBOX(), "-2.990381,-7.5,22.990381,15", sides + " sided figure generates correct bbox."); |
|---|
| | 200 | t.eq(Math.round(polyBounds.getCenterLonLat().lon), 10, "longitude of center of bounds is same as origin"); |
|---|
| | 201 | t.eq(poly3.components.length, 1, "Poly has one linear ring"); |
|---|
| | 202 | t.eq(poly3.components[0].components.length, sides + 1, "ring has correct count of components"); |
|---|
| | 203 | t.eq(poly3.components[0].components[0].id, poly3.components[0].components[sides].id, "ring starts and ends with same geom"); |
|---|
| | 204 | t.ok(poly3.getArea() > poly.getArea(), "area with radius 15 > poly with radius 6"); |
|---|
| | 205 | |
|---|
| | 206 | var sides = 4; |
|---|
| | 207 | var poly4 = OpenLayers.Geometry.Polygon.createRegularPolygon(new OpenLayers.Geometry.Point(10,0), 15, sides); |
|---|
| | 208 | var polyBounds = poly4.getBounds(); |
|---|
| | 209 | t.eq(polyBounds.toBBOX(), "-0.606602,-10.606602,20.606602,10.606602", sides + " sided figure generates correct bbox."); |
|---|
| | 210 | t.eq(Math.round(polyBounds.getCenterLonLat().lon), 10, "longitude of center of bounds is same as origin"); |
|---|
| | 211 | t.eq(poly4.components.length, 1, "Poly has one linear ring"); |
|---|
| | 212 | t.eq(poly4.components[0].components.length, sides + 1, "ring has correct count of components"); |
|---|
| | 213 | t.eq(poly4.components[0].components[0].id, poly4.components[0].components[sides].id, "ring starts and ends with same geom"); |
|---|
| | 214 | t.ok(poly4.getArea() > poly3.getArea(), "square with radius 15 > triangle with radius 15"); |
|---|