Avoiding infinite recursion when getting bounds of geometry collections. r=ahocevar (closes #2967)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10953 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2010-12-07 23:37:56 +00:00
parent 92493cc12b
commit 43dd65d357
2 changed files with 28 additions and 4 deletions

View File

@@ -108,12 +108,19 @@ OpenLayers.Geometry.Collection = OpenLayers.Class(OpenLayers.Geometry, {
*/
calculateBounds: function() {
this.bounds = null;
if ( this.components && this.components.length > 0) {
this.setBounds(this.components[0].getBounds());
for (var i=1, len=this.components.length; i<len; i++) {
this.extendBounds(this.components[i].getBounds());
var bounds = new OpenLayers.Bounds();
var components = this.components;
if (components) {
for (var i=0, len=components.length; i<len; i++) {
bounds.extend(components[i].getBounds());
}
}
// to preserve old behavior, we only set bounds if non-null
// in the future, we could add bounds.isEmpty()
if (bounds.left != null && bounds.bottom != null &&
bounds.right != null && bounds.top != null) {
this.setBounds(bounds);
}
},
/**

View File

@@ -392,6 +392,23 @@
coll.destroy();
}
function test_avoid_infinite_recursion(t) {
t.plan(1);
var g = new OpenLayers.Geometry.Polygon([
new OpenLayers.Geometry.LinearRing(),
new OpenLayers.Geometry.LinearRing()
]);
var bounds;
try {
bounds = g.getBounds();
t.eq(bounds, null, "Polygon with empty linear ring has null bounds");
} catch (err) {
t.fail("Failed to get bounds of polygon with empty linear ring: " + err.message);
}
}
function test_Collection_destroy(t) {
t.plan( 3 );