geometry.resize returns obj for chaining. r=tschaub, (Closes #1931)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@8840 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2009-02-05 22:28:22 +00:00
parent 3274491b95
commit 5cc2445a6a
5 changed files with 18 additions and 4 deletions

View File

@@ -272,11 +272,15 @@ OpenLayers.Geometry.Collection = OpenLayers.Class(OpenLayers.Geometry, {
* will have four times the area).
* origin - {<OpenLayers.Geometry.Point>} Point of origin for resizing
* ratio - {Float} Optional x:y ratio for resizing. Default ratio is 1.
*
* Returns:
* {OpenLayers.Geometry} - The current geometry.
*/
resize: function(scale, origin, ratio) {
for(var i=0; i<this.components.length; ++i) {
this.components[i].resize(scale, origin, ratio);
}
return this;
},
/**

View File

@@ -148,11 +148,15 @@ OpenLayers.Geometry.LinearRing = OpenLayers.Class(
* will have four times the area).
* origin - {<OpenLayers.Geometry.Point>} Point of origin for resizing
* ratio - {Float} Optional x:y ratio for resizing. Default ratio is 1.
*
* Returns:
* {OpenLayers.Geometry} - The current geometry.
*/
resize: function(scale, origin, ratio) {
for(var i=0, len=this.components.length; i<len - 1; ++i) {
this.components[i].resize(scale, origin, ratio);
}
return this;
},
/**

View File

@@ -198,12 +198,16 @@ OpenLayers.Geometry.Point = OpenLayers.Class(OpenLayers.Geometry, {
* distance between the point and origin.
* origin - {<OpenLayers.Geometry.Point>} Point of origin for resizing
* ratio - {Float} Optional x:y ratio for resizing. Default ratio is 1.
*
* Returns:
* {OpenLayers.Geometry} - The current geometry.
*/
resize: function(scale, origin, ratio) {
ratio = (ratio == undefined) ? 1 : ratio;
this.x = origin.x + (scale * ratio * (this.x - origin.x));
this.y = origin.y + (scale * (this.y - origin.y));
this.clearBounds();
return this;
},
/**

View File

@@ -107,7 +107,7 @@
}
function test_LineString_resize(t) {
t.plan(7);
t.plan(8);
var tolerance = 1e-10;
@@ -123,7 +123,8 @@
var scale = 10 * Math.random();
var oldLength = geometry.getLength();
geometry.resize(scale, origin);
var ret = geometry.resize(scale, origin);
t.ok(ret === geometry, "resize returns geometry");
var newLength = geometry.getLength();
t.ok((((newLength / oldLength) - scale) / scale) < tolerance,
"resize correctly changes the length of a linestring")

View File

@@ -132,7 +132,7 @@
}
function test_Point_resize(t) {
t.plan(5);
t.plan(6);
var tolerance = 1e-10;
var x = 100 * Math.random();
@@ -147,9 +147,10 @@
var scale = 10 * Math.random();
var oldDistance = origin.distanceTo(point);
point.resize(scale, origin);
var ret = point.resize(scale, origin);
var newDistance = origin.distanceTo(point);
t.ok(ret === point, "resize returns geometry");
t.ok((origin.x == i) && (origin.y == j),
"resize leaves the origin untouched");
t.ok((((newDistance / oldDistance) - scale) / scale) < tolerance,