Merge vector-2.4 branch back to trunk.

svn merge sandbox/vector-2.4/@2307 sandbox/vector-2.4/@HEAD trunk/openlayers/


git-svn-id: http://svn.openlayers.org/trunk/openlayers@2803 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-03-16 13:23:56 +00:00
parent 8b9d974dc2
commit 3ca974acec
159 changed files with 10193 additions and 343 deletions
+215
View File
@@ -0,0 +1,215 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var coll;
function test_01_Collection_constructor (t) {
t.plan( 4 );
//null param
coll = new OpenLayers.Geometry.Collection();
t.ok( coll instanceof OpenLayers.Geometry.Collection, "new OpenLayers.Geometry.Collection returns coll object" );
t.eq( coll.CLASS_NAME, "OpenLayers.Geometry.Collection", "coll.CLASS_NAME is set correctly");
t.eq( coll.components.length, 0, "coll.components is set correctly");
OpenLayers.Geometry.Collection.prototype._addComponents =
OpenLayers.Geometry.Collection.prototype.addComponents;
OpenLayers.Geometry.Collection.prototype.addComponents =
function(comps) { g_addcomponents = comps; };
//valid param
g_addcomponents = null;
var components = {};
coll = new OpenLayers.Geometry.Collection(components);
t.ok(g_addcomponents, components, "addcomponents called on non-null param")
OpenLayers.Geometry.Collection.prototype.addComponents =
OpenLayers.Geometry.Collection.prototype._addComponents;
}
function test_02_Collection_addComponents (t) {
t.plan( 10 );
coll = new OpenLayers.Geometry.Collection();
//null
coll.addComponents(null);
t.ok(true, "doesn't break on add null components");
OpenLayers.Geometry.Collection.prototype._addComponent =
OpenLayers.Geometry.Collection.prototype.addComponent;
OpenLayers.Geometry.Collection.prototype.addComponent =
function(comp) { g_addComp = comp; g_added++};
//nonarray argument
var g_added = 0;
var g_addComp = 0;
var component = {};
coll.addComponents(component);
t.eq(g_added, 1, "added once");
t.eq(g_addComp, component, "added component");
//array arg
var g_added = 0;
var g_addComp = 0;
var component1 = {};
var component2 = {};
coll.addComponents([component1, component2]);
t.eq(g_added, 2, "added twice");
t.eq(g_addComp, component2, "added component");
OpenLayers.Geometry.Collection.prototype.addComponent =
OpenLayers.Geometry.Collection.prototype._addComponent;
coll.addComponents(new OpenLayers.Geometry.Point(0,0));
coll.addComponents(new OpenLayers.Geometry.Point(10,10));
t.eq( coll.components.length, 2, "added two components to collection" );
bounds = coll.getBounds();
t.eq( bounds.left, 0, "left bound is 0" );
t.eq( bounds.bottom, 0, "bottom bound is 0" );
t.eq( bounds.right, 10, "right bound is 10" );
t.eq( bounds.top, 10, "top bound is 10" );
}
function test_03_Collection_clone (t) {
t.plan( 3 );
coll = new OpenLayers.Geometry.Collection();
coll.addComponents(new OpenLayers.Geometry.Point(0,0));
coll.addComponents(new OpenLayers.Geometry.Point(10,10));
coll2 = coll.clone();
t.ok( coll2 instanceof OpenLayers.Geometry.Collection, "coll.clone() returns collection object" );
t.eq( coll2.getComponents().length, 2, "coll2.components.length is set correctly");
t.ok( coll2.components[0] instanceof OpenLayers.Geometry.Point,
"coll2.components.length is set correctly");
}
function test_04_Collection_removeComponents (t) {
t.plan( 4 );
coll = new OpenLayers.Geometry.Collection();
point = new OpenLayers.Geometry.Point(0,0);
coll.addComponents(point);
coll.addComponents(new OpenLayers.Geometry.Point(10,10));
coll.removeComponents(coll.components[0]);
t.eq( coll.getComponents().length, 1, "coll.components.length is smaller after removeComponent" );
t.ok( coll.bounds == null, "bounds are nullified after call to remove (to trigger recalc on getBounds()");
bounds = coll.getBounds();
t.eq( bounds.left, 10, "left bound is 10 after removeComponent" );
t.eq( bounds.bottom, 10, "bottom bound is 10 after removeComponent" );
}
function test_05_Collection_getComponents (t) {
t.plan(1);
coll = new OpenLayers.Geometry.Collection();
coll.components = {};
t.eq( coll.getComponents(), coll.components, "getComponents returns great");
}
function test_06_Collection_calculateBounds(t) {
t.plan( 9 );
var coll = new OpenLayers.Geometry.Collection();
coll.calculateBounds();
t.eq(coll.bounds, null, "null components list gives null bounds on calculation()");
var p1 = new OpenLayers.Geometry.Point(10,20);
var p2 = new OpenLayers.Geometry.Point(30,40);
var components = [p1, p2];
coll = new OpenLayers.Geometry.Collection(components);
coll.calculateBounds();
t.eq(coll.bounds.left, 10, "good left bounds");
t.eq(coll.bounds.bottom, 20, "good bottom bounds");
t.eq(coll.bounds.right, 30, "good right bounds");
t.eq(coll.bounds.top, 40, "good top bounds");
var newPoint = new OpenLayers.Geometry.Point(60,70);
coll.addComponent(newPoint);
coll.calculateBounds();
t.eq(coll.bounds.left, 10, "good left bounds");
t.eq(coll.bounds.bottom, 20, "good bottom bounds");
t.eq(coll.bounds.right, 60, "good right bounds");
t.eq(coll.bounds.top, 70, "good top bounds");
}
function test_07_Collection_addComponent(t) {
t.plan(3);
var coll = new OpenLayers.Geometry.Collection();
//null
coll.addComponent(null);
t.ok(true, "no breakage, no executage from null input")
//good component
var component = new OpenLayers.Geometry.Point(3,4);
coll.addComponent(component);
t.ok(coll.bounds == null, "bounds cache correctly cleared");
var foundComponent = false;
for(var i=0; i< coll.components.length; i++) {
if (coll.components[i].equals(component)) {
foundComponent = true;
}
}
t.ok(foundComponent, "component added to internal array");
}
function test_08_collection_getLength(t) {
t.plan(2);
//null
var coll = new OpenLayers.Geometry.Collection();
t.eq( coll.getLength(), 0, "null coll has 0 getlength");
//valid
coll.components = [
{ 'getLength': function() { return 50; } },
{ 'getLength': function() { return 15; } }
];
t.eq( coll.getLength(), 65, "coll with valid components correctly sums getlength");
}
function test_09_collection_getArea(t) {
t.plan(2);
//null
var coll = new OpenLayers.Geometry.Collection();
t.eq( coll.getArea(), 0, "null coll has 0 getArea");
//valid
coll.components = [
{ 'getArea': function() { return 50; } },
{ 'getArea': function() { return 15; } }
];
t.eq( coll.getArea(), 65, "coll with valid components correctly sums getArea");
}
function test_99_Collection_destroy(t) {
t.plan( 1 );
coll = new OpenLayers.Geometry.Collection();
coll.components = {};
coll.destroy();
t.ok(coll.components == null, "components array cleared");
}
// -->
</script>
</head>
<body>
</body>
</html>
+157
View File
@@ -0,0 +1,157 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var curve;
var components = [new OpenLayers.Geometry.Point(10,10),
new OpenLayers.Geometry.Point(0,0)];
function test_01_Curve_constructor (t) {
t.plan( 3 );
curve = new OpenLayers.Geometry.Curve();
t.ok( curve instanceof OpenLayers.Geometry.Curve, "new OpenLayers.Geometry.Curve returns curve object" );
t.eq( curve.CLASS_NAME, "OpenLayers.Geometry.Curve", "curve.CLASS_NAME is set correctly");
t.eq( curve.components, [], "curve.components is set correctly");
}
function test_01a_Curve_constructor (t) {
t.plan( 2 );
curve = new OpenLayers.Geometry.Curve(components);
t.ok( curve instanceof OpenLayers.Geometry.Curve, "new OpenLayers.Geometry.Curve returns curve object" );
t.eq( curve.components.length, 2, "curve.components.length is set correctly");
}
function test_02_Curve_clone (t) {
t.plan( 2 );
curve = new OpenLayers.Geometry.Curve(components);
curve2 = curve.clone();
t.ok( curve2 instanceof OpenLayers.Geometry.Curve, "curve.clone() returns curve object" );
t.eq( curve2.components.length, 2, "curve2.components.length is set correctly");
}
function test_03_Curve_calculateBounds(t) {
t.plan( 17 );
var curve = new OpenLayers.Geometry.Curve();
curve.calculateBounds();
t.eq(curve.bounds, null, "bounds null when no components");
var p1 = new OpenLayers.Geometry.Point(10,20);
var p2 = new OpenLayers.Geometry.Point(30,40);
var components = [p1, p2];
var curve = new OpenLayers.Geometry.Curve(components);
curve.calculateBounds();
t.eq(curve.bounds.left, 10, "good left bounds");
t.eq(curve.bounds.bottom, 20, "good bottom bounds");
t.eq(curve.bounds.right, 30, "good right bounds");
t.eq(curve.bounds.top, 40, "good top bounds");
var newPoint = new OpenLayers.Geometry.Point(60,70);
curve.addComponent(newPoint);
curve.calculateBounds();
t.eq(curve.bounds.left, 10, "good left bounds");
t.eq(curve.bounds.bottom, 20, "good bottom bounds");
t.eq(curve.bounds.right, 60, "good right bounds");
t.eq(curve.bounds.top, 70, "good top bounds");
//nullifying the bounds
//before calculation
curve = new OpenLayers.Geometry.Curve(components);
curve.bounds = null;
curve.calculateBounds();
t.eq(curve.bounds.left, 10, "good left bounds");
t.eq(curve.bounds.bottom, 20, "good bottom bounds");
t.eq(curve.bounds.right, 30, "good right bounds");
t.eq(curve.bounds.top, 40, "good top bounds");
//before addComponent
curve.bounds = null;
curve.addComponent(newPoint);
curve.calculateBounds();
t.eq(curve.bounds.left, 10, "good left bounds");
t.eq(curve.bounds.bottom, 20, "good bottom bounds");
t.eq(curve.bounds.right, 60, "good right bounds");
t.eq(curve.bounds.top, 70, "good top bounds");
}
function test_04_Curve_addComponent (t) {
t.plan( 8 );
curve = new OpenLayers.Geometry.Curve(components);
curve.addComponent(new OpenLayers.Geometry.Point(20,30));
bounds = curve.getBounds();
t.eq( curve.components.length, 3, "new point added to array" );
t.eq( bounds.top, 30, "top bound is 30 after addComponent" );
t.eq( bounds.right, 20, "right bound is 20 after addComponent" );
curve.addComponent(new OpenLayers.Geometry.Point(-20,-30), 1);
bounds = curve.getBounds();
t.eq( curve.components.length, 4, "new point added to array" );
t.eq( bounds.bottom, -30, "bottom bound is -30 after 2nd addComponent" );
t.eq( bounds.left, -20, "left bound is 20 after 2nd addComponent" );
t.eq( curve.components[1].lon, -20, "new point.lon is -20 (index worked)" );
t.eq( curve.components[1].lat, -30, "new point.lat is -30 (index worked)" );
}
function test_05_Curve_removeComponent (t) {
t.plan( 4 );
curve = new OpenLayers.Geometry.Curve(components);
curve.removeComponent(curve.components[1]);
t.eq( curve.components.length, 1, "curve.components.length is smaller after removeComponent" );
t.eq( curve.bounds, null, "curve.bounds nullified after removeComponent (for recalculation)" );
bounds = curve.getBounds();
t.eq( bounds.left, 10, "left bound is 10 after removeComponent" );
t.eq( bounds.bottom, 10, "bottom bound is 10 after removeComponent" );
}
function test_06_Curve_getLength (t) {
t.plan( 4 );
//no components
curve = new OpenLayers.Geometry.Curve();
curve.components = null;
t.eq(curve.getLength(), 0, "curve with no components has length 0");
//empty components
curve.components = [];
t.eq(curve.getLength(), 0, "curve with empty components has length 0");
//single point curve
curve.components = [ new OpenLayers.Geometry.Point(0,0) ];
t.eq(curve.getLength(), 0, "curve with only one point has length 0");
//multipoint
var newcomponents = [ new OpenLayers.Geometry.Point(0,0),
new OpenLayers.Geometry.Point(0,10),
new OpenLayers.Geometry.Point(20,10),
new OpenLayers.Geometry.Point(20,-10)
];
curve = new OpenLayers.Geometry.Curve(newcomponents);
t.eq(curve.getLength(), 50, "curve.getLength returns a reasonably accurate length" );
}
function test_07_Curve_destroy(t) {
t.plan(1);
var curve = new OpenLayers.Geometry.Curve();
curve.components = {};
curve.destroy();
t.ok( curve.components == null, "components is cleared well in destruction");
}
// -->
</script>
</head>
<body>
</body>
</html>
+82
View File
@@ -0,0 +1,82 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var line;
var components = [new OpenLayers.Geometry.Point(10,15),
new OpenLayers.Geometry.Point(0,0)];
function test_01_LineString_constructor (t) {
t.plan( 3 );
line = new OpenLayers.Geometry.LineString();
t.ok( line instanceof OpenLayers.Geometry.LineString, "new OpenLayers.Geometry.LineString returns line object" );
t.eq( line.CLASS_NAME, "OpenLayers.Geometry.LineString", "line.CLASS_NAME is set correctly");
t.eq( line.components, [], "line.components is set correctly");
}
function test_01a_LineString_constructor (t) {
t.plan( 3 );
line = new OpenLayers.Geometry.LineString(components);
t.ok( line instanceof OpenLayers.Geometry.LineString, "new OpenLayers.Geometry.LineString returns line object" );
t.eq( line.CLASS_NAME, "OpenLayers.Geometry.LineString", "line.CLASS_NAME is set correctly");
// TBD FIXME, recursion
// t.eq( line.components, components, "line.components is set correctly");
t.eq( line.components.length, 2, "line.components.length is set correctly");
}
function test_02_LineString_toString(t) {
t.plan(1);
line = new OpenLayers.Geometry.LineString(components);
t.eq( line.toString(), components.toString(), "toString output checks in");
}
function test_03_LineString_removeComponent(t) {
t.plan(2);
OpenLayers.Geometry.Curve.prototype._removeComponent =
OpenLayers.Geometry.Curve.prototype.removeComponent;
OpenLayers.Geometry.Curve.prototype.removeComponent =
function(point) { g_removeComponent = point; };
line = new OpenLayers.Geometry.LineString(components);
g_removeComponent = null;
line.removeComponent(components[0]);
t.ok(g_removeComponent == null, "point not removed if only 2 points in components");
line.components.push(new OpenLayers.Geometry.Point(4,4));
line.removeComponent(components[0]);
t.ok(g_removeComponent, components[0], "point removed if 3 points in components");
OpenLayers.Geometry.Curve.prototype.removeComponent =
OpenLayers.Geometry.Curve.prototype._removeComponent;
}
function test_04_LineString_move(t) {
t.plan(4);
line = new OpenLayers.Geometry.LineString(components);
var x0 = components[0].x;
var y0 = components[0].y;
var x1 = components[1].x;
var y1 = components[1].y;
var dx = 10 * Math.random();
var dy = 10 * Math.random();
line.move(dx, dy);
t.eq(line.components[0].x, x0 + dx, "move() correctly modifies first x");
t.eq(line.components[0].y, y0 + dy, "move() correctly modifies first y");
t.eq(line.components[1].x, x1 + dx, "move() correctly modifies second x");
t.eq(line.components[1].y, y1 + dy, "move() correctly modifies second y");
}
// -->
</script>
</head>
<body>
</body>
</html>
+98
View File
@@ -0,0 +1,98 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var line;
var components = [new OpenLayers.Geometry.Point(10,10),
new OpenLayers.Geometry.Point(0,0)];
function test_01_LinearRing_constructor (t) {
t.plan( 6 );
//null
ring = new OpenLayers.Geometry.LinearRing();
t.ok( ring instanceof OpenLayers.Geometry.LinearRing, "new OpenLayers.Geometry.LinearRing returns ring object" );
t.eq( ring.CLASS_NAME, "OpenLayers.Geometry.LinearRing", "ring.CLASS_NAME is set correctly");
t.eq( ring.components, [], "ring.components is set correctly");
//valid components
ring = new OpenLayers.Geometry.LinearRing(components);
t.ok( ring instanceof OpenLayers.Geometry.LinearRing, "new OpenLayers.Geometry.LinearRing returns ring object" );
t.eq( ring.CLASS_NAME, "OpenLayers.Geometry.LinearRing", "ring.CLASS_NAME is set correctly");
t.eq( ring.components.length, 3, "ring.components.length is set correctly");
}
function test_02_LinearRing_addComponent(t) {
t.plan(12);
var ring = new OpenLayers.Geometry.LinearRing();
var point = new OpenLayers.Geometry.Point(0,0);
ring.addComponent( point );
t.eq(ring.components.length, 2, "add first point, correct length");
t.ok(ring.components[0].equals(point), "point one correct");
t.ok(ring.components[0].equals(ring.components[ring.components.length - 1]), "first and last point equal");
ring.addComponent( point );
t.eq(ring.components.length, 3, "add second point, correct length");
t.ok(ring.components[0].equals(point), "point one correct");
t.ok(ring.components[1].equals(point), "point two correct");
t.ok(ring.components[0].equals(ring.components[ring.components.length - 1]), "first and last point equal");
newPoint = new OpenLayers.Geometry.Point(10,10);
ring.addComponent( newPoint );
t.eq(ring.components.length, 4, "correctly adds 3rd point");
t.ok(ring.components[0].equals(point), "point one correct");
t.ok(ring.components[1].equals(point), "point two correct");
t.ok(ring.components[2].equals(newPoint), "point one correct");
t.ok(ring.components[0].equals(ring.components[ring.components.length - 1]), "first and last point equal");
}
function test_03_LinearRing_removeComponent(t) {
t.plan(11);
var components = [new OpenLayers.Geometry.Point(0,0),
new OpenLayers.Geometry.Point(0,10),
new OpenLayers.Geometry.Point(15,15),
new OpenLayers.Geometry.Point(10,0)
];
var ring = new OpenLayers.Geometry.LinearRing(components);
ring.removeComponent( ring.components[2] );
t.eq(ring.components.length, 4, "removing from linear ring with 5 points: length ok");
t.ok(ring.components[0].equals(components[0]), "point one correct");
t.ok(ring.components[1].equals(components[1]), "point two correct");
t.ok(ring.components[2].equals(components[3]), "point one correct");
t.ok(ring.components[0].equals(ring.components[ring.components.length - 1]), "first and last point equal");
var testBounds = new OpenLayers.Bounds(0,0,10,10);
var ringBounds = ring.getBounds();
t.ok(ringBounds.equals(testBounds), "bounds correctly recalculated");
ring.removeComponent( ring.components[2] );
t.eq(ring.components.length, 4, "cant remove from linear ring with only 4 points. new length ok (unchanged)");
t.ok(ring.components[0].equals(components[0]), "point one correct");
t.ok(ring.components[1].equals(components[1]), "point two correct");
t.ok(ring.components[2].equals(components[3]), "point one correct");
t.ok(ring.components[0].equals(ring.components[ring.components.length - 1]), "first and last point equal");
}
function test_04_LinearRing_getArea(t) {
t.plan(1);
var components = [new OpenLayers.Geometry.Point(0,0),
new OpenLayers.Geometry.Point(0,10),
new OpenLayers.Geometry.Point(10,10),
new OpenLayers.Geometry.Point(10,0)
];
var ring = new OpenLayers.Geometry.LinearRing(components);
t.eq(ring.getArea(), 100, "getArea works lovely");
}
// -->
</script>
</head>
<body>
</body>
</html>
+29
View File
@@ -0,0 +1,29 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var line;
function test_01_MultiLineString_constructor (t) {
t.plan( 3 );
mline = new OpenLayers.Geometry.MultiLineString();
t.ok( mline instanceof OpenLayers.Geometry.MultiLineString, "new OpenLayers.Geometry.MultiLineString returns mline object" );
t.eq( mline.CLASS_NAME, "OpenLayers.Geometry.MultiLineString", "mline.CLASS_NAME is set correctly");
t.eq( mline.components, [], "line.components is set correctly");
}
function test_01a_MultiLineString_constructor (t) {
t.plan( 3 );
line = new OpenLayers.Geometry.LineString();
mline = new OpenLayers.Geometry.MultiLineString(line);
t.ok( mline instanceof OpenLayers.Geometry.MultiLineString, "new OpenLayers.Geometry.MultiLineString returns mline object" );
t.eq( mline.CLASS_NAME, "OpenLayers.Geometry.MultiLineString", "mline.CLASS_NAME is set correctly");
t.eq( mline.components.length, 1, "mline.components.length is set correctly");
}
// -->
</script>
</head>
<body>
</body>
</html>
+44
View File
@@ -0,0 +1,44 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var point = new OpenLayers.Geometry.Point(10, 15);
function test_01_MultiPoint_constructor (t) {
t.plan( 2 );
multipoint = new OpenLayers.Geometry.MultiPoint();
t.ok( multipoint instanceof OpenLayers.Geometry.MultiPoint, "new OpenLayers.Geometry.MultiPoint returns multipoint object" );
t.eq( multipoint.CLASS_NAME, "OpenLayers.Geometry.MultiPoint", "multipoint.CLASS_NAME is set correctly");
}
function test_01a_MultiPoint_constructor (t) {
t.plan( 3 );
multipoint = new OpenLayers.Geometry.MultiPoint([point]);
t.ok( multipoint instanceof OpenLayers.Geometry.MultiPoint, "new OpenLayers.Geometry.MultiPoint returns multipoint object" );
t.eq( multipoint.CLASS_NAME, "OpenLayers.Geometry.MultiPoint", "multipoint.CLASS_NAME is set correctly");
t.eq( multipoint.components.length, 1, "multipolygon.components.length is set correctly");
}
function test_02_MultiPoint_move(t) {
t.plan(4);
multipoint = new OpenLayers.Geometry.MultiPoint([point]);
var x = point.x;
var y = point.y;
var dx = 10 * Math.random();
var dy = 10 * Math.random();
multipoint.move(dx, dy);
t.eq(multipoint.components[0].x, x + dx, "move() correctly modifies x");
t.eq(multipoint.components[0].y, y + dy, "move() correctly modifies y");
t.eq(multipoint.components[0].lon, x + dx, "move() correctly modifies lon");
t.eq(multipoint.components[0].lat, y + dy, "move() correctly modifies lat");
}
// -->
</script>
</head>
<body>
</body>
</html>
+34
View File
@@ -0,0 +1,34 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var polygon;
var components = [new OpenLayers.Geometry.Point(10,10), new OpenLayers.Geometry.Point(0,0)];
var components2 = [new OpenLayers.Geometry.Point(10,10), new OpenLayers.Geometry.Point(0,0), new OpenLayers.Geometry.Point(10,0), new OpenLayers.Geometry.Point(10,10)];
var linearRing = new OpenLayers.Geometry.LinearRing(components);
var linearRing2 = new OpenLayers.Geometry.LinearRing(components2);
var polygon = new OpenLayers.Geometry.Polygon([linearRing]);
var polygon2 = new OpenLayers.Geometry.Polygon([linearRing2]);
function test_01_MultiPolygon_constructor (t) {
t.plan( 2 );
multipolygon = new OpenLayers.Geometry.MultiPolygon();
t.ok( multipolygon instanceof OpenLayers.Geometry.MultiPolygon, "new OpenLayers.Geometry.MultiPolygon returns multipolygon object" );
t.eq( multipolygon.CLASS_NAME, "OpenLayers.Geometry.MultiPolygon", "multipolygon.CLASS_NAME is set correctly");
}
function test_01a_MultiPolygon_constructor (t) {
t.plan( 3 );
multipolygon = new OpenLayers.Geometry.MultiPolygon([polygon, polygon2]);
t.ok( multipolygon instanceof OpenLayers.Geometry.MultiPolygon, "new OpenLayers.Geometry.MultiPolygon returns multipolygon object" );
t.eq( multipolygon.CLASS_NAME, "OpenLayers.Geometry.MultiPolygon", "multipolygon.CLASS_NAME is set correctly");
t.eq( multipolygon.components.length, 2, "multipolygon.components.length is set correctly");
}
// -->
</script>
</head>
<body>
</body>
</html>
+112
View File
@@ -0,0 +1,112 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var point;
function test_01_Point_constructor (t) {
t.plan( 8 );
//empty
point = new OpenLayers.Geometry.Point();
t.ok( point instanceof OpenLayers.Geometry.Point, "new OpenLayers.Geometry.Point returns point object" );
t.eq( point.CLASS_NAME, "OpenLayers.Geometry.Point", "point.CLASS_NAME is set correctly");
//valid
var x = 10;
var y = 20;
point = new OpenLayers.Geometry.Point(x, y);
t.ok( point instanceof OpenLayers.Geometry.Point, "new OpenLayers.Geometry.Point returns point object" );
t.eq( point.CLASS_NAME, "OpenLayers.Geometry.Point", "point.CLASS_NAME is set correctly");
t.eq( point.x, x, "point.x is set correctly");
t.eq( point.y, y, "point.y is set correctly");
t.eq( point.lon, x, "point.lon is set correctly");
t.eq( point.lat, y, "point.lat is set correctly");
}
function test_02_Point_accessors(t) {
t.plan( 6 )
//valid
var x = 10;
var y = 20;
point = new OpenLayers.Geometry.Point(x, y);
t.eq( point.getX(), x, "point.x is get() correctly");
t.eq( point.getY(), y, "point.y is get() correctly");
var x1 = 55;
var y1 = 73;
point.setX(x1);
point.setY(y1);
t.eq( point.x, x1, "point.x is set() correctly");
t.eq( point.y, y1, "point.y is set() correctly");
t.eq( point.lon, x1, "point.lon is set() correctly");
t.eq( point.lat, y1, "point.lat is set() correctly");
}
function test_03_Point_calculateBounds (t) {
t.plan(4);
var x = 10;
var y = 20;
point = new OpenLayers.Geometry.Point(x, y);
point.calculateBounds();
t.eq( point.bounds.left, x, "bounds.left is 10" );
t.eq( point.bounds.right, x, "bounds.right is 10" );
t.eq( point.bounds.top, y, "bounds.top is 20" );
t.eq( point.bounds.bottom, y, "bounds.bottom is 20" );
}
function test_04_Point_distanceTo(t) {
t.plan(2);
var x1 = 10;
var y1 = 20;
point1 = new OpenLayers.Geometry.Point(x1, y1);
var x2 = 100;
var y2 = 200;
point2 = new OpenLayers.Geometry.Point(x2, y2);
var dist = point1.distanceTo(point2)
t.eq( dist, 201.24611797498107267682563018581, "distances calculating correctly");
t.eq( dist, Math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)), "distance calculation correct");
}
function test_05_Point_toString(t) {
t.plan(1);
var x = 10;
var y = 20;
point = new OpenLayers.Geometry.Point(x, y);
bounds = point.getBounds();
t.eq( point.toString(), x + ", " + y, "toString() works" );
}
function test_06_Point_move(t) {
t.plan(4);
var x = 10;
var y = 20;
point = new OpenLayers.Geometry.Point(x, y);
var dx = 10 * Math.random();
var dy = 10 * Math.random();
point.move(dx, dy);
t.eq(point.x, x + dx, "move() correctly modifies x");
t.eq(point.y, y + dy, "move() correctly modifies y");
t.eq(point.lon, x + dx, "move() correctly modifies lon");
t.eq(point.lat, y + dy, "move() correctly modifies lat");
}
// -->
</script>
</head>
<body>
</body>
</html>
+114
View File
@@ -0,0 +1,114 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
var polygon;
var components = [new OpenLayers.Geometry.Point(10,14), new OpenLayers.Geometry.Point(5,3)];
var components2 = [new OpenLayers.Geometry.Point(12,15), new OpenLayers.Geometry.Point(2,3), new OpenLayers.Geometry.Point(10,0), new OpenLayers.Geometry.Point(10,10)];
var linearRing = new OpenLayers.Geometry.LinearRing(components);
var linearRing2 = new OpenLayers.Geometry.LinearRing(components2);
function test_01_Polygon_constructor (t) {
t.plan( 3 );
polygon = new OpenLayers.Geometry.Polygon();
t.ok( polygon instanceof OpenLayers.Geometry.Polygon, "new OpenLayers.Geometry.Polygon returns polygon object" );
t.eq( polygon.CLASS_NAME, "OpenLayers.Geometry.Polygon", "polygon.CLASS_NAME is set correctly");
t.eq( polygon.components.length, 0, "polygon.components is set correctly");
}
function test_01a_Polygon_constructor (t) {
t.plan( 3 );
polygon = new OpenLayers.Geometry.Polygon([linearRing]);
t.ok( polygon instanceof OpenLayers.Geometry.Polygon, "new OpenLayers.Geometry.Polygon returns polygon object" );
t.eq( polygon.CLASS_NAME, "OpenLayers.Geometry.Polygon", "polygon.CLASS_NAME is set correctly");
t.eq( polygon.components.length, 1, "polygon.components.length is set correctly");
}
function test_01b_Polygon_constructor (t) {
t.plan( 3 );
polygon = new OpenLayers.Geometry.Polygon([linearRing, linearRing2]);
t.ok( polygon instanceof OpenLayers.Geometry.Polygon, "new OpenLayers.Geometry.Polygon returns polygon object" );
t.eq( polygon.CLASS_NAME, "OpenLayers.Geometry.Polygon", "polygon.CLASS_NAME is set correctly");
t.eq( polygon.components.length, 2, "polygon.components.length is set correctly");
}
function test_02_Polygon_getArea(t) {
t.plan( 5 );
//no components
var polygon = new OpenLayers.Geometry.Polygon();
t.eq(polygon.getArea(), 0, "getArea empty polygon is 0");
var createSquareRing = function(area) {
var points = [
new OpenLayers.Geometry.Point(0, 0),
new OpenLayers.Geometry.Point(0, area),
new OpenLayers.Geometry.Point(area, area),
new OpenLayers.Geometry.Point(area, 0)
];
var ring = new OpenLayers.Geometry.LinearRing(points);
return ring;
};
//simple polygon
var comps = [ createSquareRing(2) ];
var polygon = new OpenLayers.Geometry.Polygon(comps);
t.eq(polygon.getArea(), 4, "getArea simple polygon works lovely");
//polygon with holes
comps = [ createSquareRing(10),
createSquareRing(2),
createSquareRing(3),
createSquareRing(4),
];
var polygon = new OpenLayers.Geometry.Polygon(comps);
t.eq(polygon.getArea(), 71, "getArea polygon with holes works lovely");
//simple polygon negative
comps = [ createSquareRing(-2) ];
var polygon = new OpenLayers.Geometry.Polygon(comps);
t.eq(polygon.getArea(), 4, "getArea simple polygon negative works lovely");
//polygon with holes negative
comps = [ createSquareRing(-10),
createSquareRing(-2),
createSquareRing(-3),
createSquareRing(-4),
];
var polygon = new OpenLayers.Geometry.Polygon(comps);
t.eq(polygon.getArea(), 71, "getArea negative polygon with holes works lovely");
}
function test_03_Polygon_move(t) {
t.plan(4);
polygon = new OpenLayers.Geometry.Polygon([linearRing, linearRing2]);
var x = linearRing.components[0].x;
var y = linearRing.components[0].y;
var x2 = linearRing2.components[0].x;
var y2 = linearRing2.components[0].y;
var dx = 10 * Math.random();
var dy = 10 * Math.random();
polygon.move(dx, dy);
t.eq(polygon.components[0].components[0].x, x + dx, "move() correctly modifies first x");
t.eq(polygon.components[0].components[0].y, y + dy, "move() correctly modifies first y");
t.eq(polygon.components[1].components[0].x, x2 + dx, "move() correctly modifies second x");
t.eq(polygon.components[1].components[0].y, y2 + dy, "move() correctly modifies second y");
}
// -->
</script>
</head>
<body>
</body>
</html>
+88
View File
@@ -0,0 +1,88 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
function test_01_Rectangle_constructor (t) {
t.plan( 8 );
//empty
var rect = new OpenLayers.Geometry.Rectangle();
t.ok( rect instanceof OpenLayers.Geometry.Rectangle, "new OpenLayers.Geometry.Rectangle returns Rectangle object" );
t.eq( rect.CLASS_NAME, "OpenLayers.Geometry.Rectangle", "Rectangle.CLASS_NAME is set correctly");
t.ok( rect.id != null, "rect.id is set");
t.ok( ! (rect.x || rect.y || rect.width || rect.height), "empty construct leaves properties empty");
//good
var x = {};
var y = {};
var w = {};
var h = {};
var rect = new OpenLayers.Geometry.Rectangle(x, y, w, h);
t.eq( rect.x, x, "good init correctly sets x property");
t.eq( rect.y, y, "good init correctly sets y property");
t.eq( rect.width, w, "good init correctly sets width property");
t.eq( rect.height, h, "good init correctly sets height property");
}
function test_02_Rectangle_calculateBounds(t) {
t.plan(1);
var x = 1;
var y = 2;
var w = 10;
var h = 20;
var rect = new OpenLayers.Geometry.Rectangle(x, y, w, h);
rect.calculateBounds();
var testBounds = new OpenLayers.Bounds(x, y, x + w, y + h)
t.ok( rect.bounds.equals(testBounds), "calculateBounds works correctly");
}
function test_03_Rectangle_getLength(t) {
var x = 1;
var y = 2;
var w = 10;
var h = 20;
var rect = new OpenLayers.Geometry.Rectangle(x, y, w, h);
var testLength = (2 * w) + (2 * h);
t.eq(rect.getLength(), testLength, "getLength() works");
}
function test_03_Rectangle_getLength(t) {
t.plan(1);
var x = 1;
var y = 2;
var w = 10;
var h = 20;
var rect = new OpenLayers.Geometry.Rectangle(x, y, w, h);
var testLength = (2 * w) + (2 * h);
t.eq(rect.getLength(), testLength, "getLength() works");
}
function test_04_Rectangle_getArea(t) {
t.plan(1);
var x = 1;
var y = 2;
var w = 10;
var h = 20;
var rect = new OpenLayers.Geometry.Rectangle(x, y, w, h);
var testArea = w * h;
t.eq(rect.getArea(), testArea, "testArea() works");
}
// -->
</script>
</head>
<body>
</body>
</html>
+21
View File
@@ -0,0 +1,21 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
function test_01_Surface_constructor (t) {
t.plan( 2 );
var g = new OpenLayers.Geometry.Surface();
t.eq(g.CLASS_NAME, "OpenLayers.Geometry.Surface", "correct CLASS_NAME")
t.ok(g.id.startsWith("OpenLayers.Geometry.Surface_"), "id correctly set");
}
// -->
</script>
</head>
<body>
</body>
</html>