Tim's big refactoring of the Geometry modules. Fixes #590. All tests pass in FF (except the PanZoomBar stuff, which wasn't touched by this patch) and IE.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@2931 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Schuyler Erle
2007-03-30 21:42:32 +00:00
parent 91ec16c81a
commit 313704b844
16 changed files with 374 additions and 177 deletions

View File

@@ -105,6 +105,56 @@
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");
}
function test_Polygon_equals(t) {
t.plan(3);
var x0 = Math.random() * 100;
var y0 = Math.random() * 100;
var x1 = Math.random() * 100;
var y1 = Math.random() * 100;
var x2 = Math.random() * 100;
var y2 = Math.random() * 100;
var point0 = new OpenLayers.Geometry.Point(x0, y0);
var point1 = new OpenLayers.Geometry.Point(x1, y1);
var point2 = new OpenLayers.Geometry.Point(x2, y2);
var pointX = new OpenLayers.Geometry.Point(x0 + 1, y0);
var pointY = new OpenLayers.Geometry.Point(x0, y0 + 1);
var geometry = new OpenLayers.Geometry.Polygon([
new OpenLayers.Geometry.LinearRing([point0, point1, point2])]);
var equal = new OpenLayers.Geometry.Polygon([
new OpenLayers.Geometry.LinearRing([point0, point1, point2])]);
var offX = new OpenLayers.Geometry.Polygon([
new OpenLayers.Geometry.LinearRing([pointX, point1, point2])]);
var offY = new OpenLayers.Geometry.Polygon([
new OpenLayers.Geometry.LinearRing([pointY, point1, point2])]);
t.ok(geometry.equals(equal),
"equals() returns true for a geometry with equivalent coordinates");
t.ok(!geometry.equals(offX),
"equals() returns false for a geometry with offset x");
t.ok(!geometry.equals(offY),
"equals() returns false for a geometry with offset y");
}
function test_Polygon_clone(t) {
t.plan(2);
var x0 = Math.random() * 100;
var y0 = Math.random() * 100;
var x1 = Math.random() * 100;
var y1 = Math.random() * 100;
var x2 = Math.random() * 100;
var y2 = Math.random() * 100;
var point0 = new OpenLayers.Geometry.Point(x0, y0);
var point1 = new OpenLayers.Geometry.Point(x1, y1);
var point2 = new OpenLayers.Geometry.Point(x2, y2);
var geometry = new OpenLayers.Geometry.Polygon([
new OpenLayers.Geometry.LinearRing([point0, point1, point2])]);
var clone = geometry.clone();
t.ok(clone instanceof OpenLayers.Geometry.Polygon,
"clone() creates an OpenLayers.Geometry.Polygon");
t.ok(geometry.equals(clone), "clone has equivalent coordinates");
}
// -->
</script>