[OpenLayers-Commits] r2368 - in sandbox/vector-2.4: lib/OpenLayers/Geometry tests tests/Geometry
commits at openlayers.org
commits at openlayers.org
Mon Mar 5 20:33:55 EST 2007
Author: sderle
Date: 2007-03-05 20:33:55 -0500 (Mon, 05 Mar 2007)
New Revision: 2368
Added:
sandbox/vector-2.4/tests/Geometry/test_Collection.html
Modified:
sandbox/vector-2.4/lib/OpenLayers/Geometry/Collection.js
sandbox/vector-2.4/tests/list-tests.html
Log:
Unit tests for Geometry.Collection.
Modified: sandbox/vector-2.4/lib/OpenLayers/Geometry/Collection.js
===================================================================
--- sandbox/vector-2.4/lib/OpenLayers/Geometry/Collection.js 2007-03-06 01:29:58 UTC (rev 2367)
+++ sandbox/vector-2.4/lib/OpenLayers/Geometry/Collection.js 2007-03-06 01:33:55 UTC (rev 2368)
@@ -46,6 +46,15 @@
return this.components ? this.components : null;
},
+ getBounds: function () {
+ if (!this.bounds) {
+ for (var i = 0; i < this.components.length; i++) {
+ this.extendBounds(this.components[i].getBounds());
+ }
+ }
+ return this.bounds;
+ },
+
/**
*
*/
@@ -53,12 +62,7 @@
if(!(components instanceof Array)) {
components = [components];
}
-
this.components = this.components.concat(components);
-
- for (var i = 0; i < components.length; i++) {
- this.extendBounds(components[i].bounds);
- }
},
/**
@@ -73,7 +77,9 @@
this.components = OpenLayers.Util.removeItem(this.components, components[i]);
}
- // TBD restrain the bounds
+ // reset this.bounds so that it gets recalculated on the next call
+ // to this.getBounds();
+ this.bounds = null;
},
// /**
Added: sandbox/vector-2.4/tests/Geometry/test_Collection.html
===================================================================
--- sandbox/vector-2.4/tests/Geometry/test_Collection.html (rev 0)
+++ sandbox/vector-2.4/tests/Geometry/test_Collection.html 2007-03-06 01:33:55 UTC (rev 2368)
@@ -0,0 +1,58 @@
+<html>
+<head>
+ <script src="../../lib/OpenLayers.js"></script>
+ <script type="text/javascript"><!--
+ var coll;
+
+ function test_01_Collection_constructor (t) {
+ t.plan( 3 );
+ 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");
+ }
+
+ function test_02_Collection_addComponents (t) {
+ t.plan( 5 );
+ coll = new OpenLayers.Geometry.Collection();
+ 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(3);
+ 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(point);
+ t.eq( coll.getComponents().length, 1, "coll.components.length is smaller after removePoint" );
+ bounds = coll.getBounds();
+ t.eq( bounds.left, 10, "left bound is 10 after removePoint" );
+ t.eq( bounds.bottom, 10, "bottom bound is 10 after removePoint" );
+ }
+
+ // -->
+ </script>
+</head>
+<body>
+</body>
+</html>
Modified: sandbox/vector-2.4/tests/list-tests.html
===================================================================
--- sandbox/vector-2.4/tests/list-tests.html 2007-03-06 01:29:58 UTC (rev 2367)
+++ sandbox/vector-2.4/tests/list-tests.html 2007-03-06 01:33:55 UTC (rev 2368)
@@ -6,9 +6,10 @@
<li>BaseTypes/test_Bounds.html</li>
<li>test_Geometry.html</li>
<li>Geometry/test_Point.html</li>
- <li>Geometry/test_MultiPoint.html</li>
<li>Geometry/test_Curve.html</li>
<li>Geometry/test_LineString.html</li>
+ <li>Geometry/test_Collection.html</li>
+ <li>Geometry/test_MultiPoint.html</li>
<li>Geometry/test_Polygon.html</li>
<li>Geometry/test_MultiPolygon.html</li>
<li>test_Icon.html</li>
More information about the Commits
mailing list