From 958221d5f4268c8f34cc89c935933df9aceb8a7f Mon Sep 17 00:00:00 2001 From: tschaub Date: Thu, 29 Dec 2011 14:14:49 -0700 Subject: [PATCH 1/8] Moving Rectangle geometries to deprecated.js. The VML and SVG renderers still have support for drawing rectangles. This can be safely removed in 3.0. --- lib/OpenLayers.js | 1 - lib/OpenLayers/Geometry/Rectangle.js | 99 ------------------- lib/deprecated.js | 93 +++++++++++++++++ .../{ => deprecated}/Geometry/Rectangle.html | 3 +- tests/list-tests.html | 2 +- 5 files changed, 96 insertions(+), 102 deletions(-) delete mode 100644 lib/OpenLayers/Geometry/Rectangle.js rename tests/{ => deprecated}/Geometry/Rectangle.html (95%) diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index aaf8a51104..0ac4aa0323 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -202,7 +202,6 @@ "OpenLayers/Control/TransformFeature.js", "OpenLayers/Control/SLDSelect.js", "OpenLayers/Geometry.js", - "OpenLayers/Geometry/Rectangle.js", "OpenLayers/Geometry/Collection.js", "OpenLayers/Geometry/Point.js", "OpenLayers/Geometry/MultiPoint.js", diff --git a/lib/OpenLayers/Geometry/Rectangle.js b/lib/OpenLayers/Geometry/Rectangle.js deleted file mode 100644 index 5f05cbedbb..0000000000 --- a/lib/OpenLayers/Geometry/Rectangle.js +++ /dev/null @@ -1,99 +0,0 @@ -/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for - * full list of contributors). Published under the Clear BSD license. - * See http://svn.openlayers.org/trunk/openlayers/license.txt for the - * full text of the license. */ - -/** - * @requires OpenLayers/Geometry.js - */ - -/** - * Class: OpenLayers.Geometry.Rectangle - * This class is *not supported*, and probably isn't what you're looking for. - * Instead, most users probably want something like: - * (code) - * var poly = new OpenLayers.Bounds(0,0,10,10).toGeometry(); - * (end) - * This will create a rectangular Polygon geometry. - * - * Inherits: - * - - */ - -OpenLayers.Geometry.Rectangle = OpenLayers.Class(OpenLayers.Geometry, { - - /** - * Property: x - * {Float} - */ - x: null, - - /** - * Property: y - * {Float} - */ - y: null, - - /** - * Property: width - * {Float} - */ - width: null, - - /** - * Property: height - * {Float} - */ - height: null, - - /** - * Constructor: OpenLayers.Geometry.Rectangle - * - * Parameters: - * points - {Array()} - */ - initialize: function(x, y, width, height) { - OpenLayers.Geometry.prototype.initialize.apply(this, arguments); - - this.x = x; - this.y = y; - - this.width = width; - this.height = height; - }, - - /** - * Method: calculateBounds - * Recalculate the bounds for the geometry. - */ - calculateBounds: function() { - this.bounds = new OpenLayers.Bounds(this.x, this.y, - this.x + this.width, - this.y + this.height); - }, - - - /** - * APIMethod: getLength - * - * Returns: - * {Float} The length of the geometry - */ - getLength: function() { - var length = (2 * this.width) + (2 * this.height); - return length; - }, - - /** - * APIMethod: getArea - * - * Returns: - * {Float} The area of the geometry - */ - getArea: function() { - var area = this.width * this.height; - return area; - }, - - CLASS_NAME: "OpenLayers.Geometry.Rectangle" -}); diff --git a/lib/deprecated.js b/lib/deprecated.js index cde92fd6f6..33be206fd9 100644 --- a/lib/deprecated.js +++ b/lib/deprecated.js @@ -20,8 +20,10 @@ * @requires OpenLayers/Format/JSON.js * @requires OpenLayers/Format/WKT.js * @requires OpenLayers/Format/XML.js + * @requires OpenLayers/Geometry.js */ + /** * Namespace: OpenLayers.Class */ @@ -4938,3 +4940,94 @@ OpenLayers.Layer.GML = OpenLayers.Class(OpenLayers.Layer.Vector, { CLASS_NAME: "OpenLayers.Layer.GML" }); + +/** + * Class: OpenLayers.Geometry.Rectangle + * This class is *not supported*, and probably isn't what you're looking for. + * Instead, most users probably want something like: + * (code) + * var poly = new OpenLayers.Bounds(0,0,10,10).toGeometry(); + * (end) + * This will create a rectangular Polygon geometry. + * + * Inherits: + * - + */ + +OpenLayers.Geometry.Rectangle = OpenLayers.Class(OpenLayers.Geometry, { + + /** + * Property: x + * {Float} + */ + x: null, + + /** + * Property: y + * {Float} + */ + y: null, + + /** + * Property: width + * {Float} + */ + width: null, + + /** + * Property: height + * {Float} + */ + height: null, + + /** + * Constructor: OpenLayers.Geometry.Rectangle + * + * Parameters: + * points - {Array()} + */ + initialize: function(x, y, width, height) { + OpenLayers.Geometry.prototype.initialize.apply(this, arguments); + + this.x = x; + this.y = y; + + this.width = width; + this.height = height; + }, + + /** + * Method: calculateBounds + * Recalculate the bounds for the geometry. + */ + calculateBounds: function() { + this.bounds = new OpenLayers.Bounds(this.x, this.y, + this.x + this.width, + this.y + this.height); + }, + + + /** + * APIMethod: getLength + * + * Returns: + * {Float} The length of the geometry + */ + getLength: function() { + var length = (2 * this.width) + (2 * this.height); + return length; + }, + + /** + * APIMethod: getArea + * + * Returns: + * {Float} The area of the geometry + */ + getArea: function() { + var area = this.width * this.height; + return area; + }, + + CLASS_NAME: "OpenLayers.Geometry.Rectangle" +}); diff --git a/tests/Geometry/Rectangle.html b/tests/deprecated/Geometry/Rectangle.html similarity index 95% rename from tests/Geometry/Rectangle.html rename to tests/deprecated/Geometry/Rectangle.html index 41dc95a010..75778e8c18 100644 --- a/tests/Geometry/Rectangle.html +++ b/tests/deprecated/Geometry/Rectangle.html @@ -1,6 +1,7 @@ - + + diff --git a/tests/Test.AnotherWay.geom_eq.js b/tests/Test.AnotherWay.geom_eq.js index 3e3ad8486f..87e40e2134 100644 --- a/tests/Test.AnotherWay.geom_eq.js +++ b/tests/Test.AnotherWay.geom_eq.js @@ -34,6 +34,34 @@ } } + /** + * Function assertFloatEqual + * Test two objects for floating point equivalence. Throw an exception + * if not equivalent. + * + * Parameters: + * got - {Object} + * expected - {Object} + * msg - {String} The message to be thrown. This message will be appended + * with ": got {got} but expected {expected}" where got and expected are + * replaced with string representations of the above arguments. + */ + function assertFloatEqual(got, expected, msg) { + if(got === undefined) { + got = "undefined"; + } else if (got === null) { + got = "null"; + } + if(expected === undefined) { + expected = "undefined"; + } else if (expected === null) { + expected = "null"; + } + if(Math.abs(got - expected) > 0.000000001) { + throw msg + ": got '" + got + "' but expected '" + expected + "'"; + } + } + /** * Function assertGeometryEqual * Test two geometries for equivalence. Geometries are considered @@ -58,9 +86,9 @@ if(got instanceof OpenLayers.Geometry.Point) { // compare points - assertEqual(got.x, expected.x, "x mismatch"); - assertEqual(got.y, expected.y, "y mismatch"); - assertEqual(got.z, expected.z, "z mismatch"); + assertFloatEqual(got.x, expected.x, "x mismatch"); + assertFloatEqual(got.y, expected.y, "y mismatch"); + assertFloatEqual(got.z, expected.z, "z mismatch"); } else { // compare components assertEqual( @@ -107,4 +135,4 @@ } } -})(); \ No newline at end of file +})(); From 533ee475ee91b6edea3ba0bc09cadfa7202527bb Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 18 Oct 2011 10:50:18 +0100 Subject: [PATCH 7/8] Improve documentation of regular versus irregular transformation --- lib/OpenLayers/Control/TransformFeature.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/Control/TransformFeature.js b/lib/OpenLayers/Control/TransformFeature.js index a52f8d84fd..571963146c 100644 --- a/lib/OpenLayers/Control/TransformFeature.js +++ b/lib/OpenLayers/Control/TransformFeature.js @@ -165,13 +165,16 @@ OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, { * {} */ dragControl: null, - + /** * APIProperty: irregular - * {Boolean} + * {Boolean} Make scaling/resizing work irregularly. If true then + * dragging a handle causes the feature to resize in the direction + * of movement. If false then the feature resizes symetrically + * about it's center. */ irregular: false, - + /** * Constructor: OpenLayers.Control.TransformFeature * Create a new transform feature control. From dd103ebf821297a916e4bddec9c76225f1ab5852 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sat, 31 Dec 2011 14:00:25 +0000 Subject: [PATCH 8/8] Use OpenLayers.Util.DEFAULT_PRECISION for geometry comparisons --- tests/Test.AnotherWay.geom_eq.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Test.AnotherWay.geom_eq.js b/tests/Test.AnotherWay.geom_eq.js index 87e40e2134..893c5b5a2f 100644 --- a/tests/Test.AnotherWay.geom_eq.js +++ b/tests/Test.AnotherWay.geom_eq.js @@ -47,6 +47,7 @@ * replaced with string representations of the above arguments. */ function assertFloatEqual(got, expected, msg) { + var OpenLayers = Test.AnotherWay._g_test_iframe.OpenLayers; if(got === undefined) { got = "undefined"; } else if (got === null) { @@ -57,7 +58,7 @@ } else if (expected === null) { expected = "null"; } - if(Math.abs(got - expected) > 0.000000001) { + if(Math.abs(got - expected) > Math.pow(10, -OpenLayers.Util.DEFAULT_PRECISION)) { throw msg + ": got '" + got + "' but expected '" + expected + "'"; } }