#805 - all geometries now know how to rotate - see the examples/rotate-features.html for geometry.rotate in action

git-svn-id: http://svn.openlayers.org/trunk/openlayers@3602 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2007-07-05 22:03:27 +00:00
parent debca7c477
commit dcffa03e7d
6 changed files with 207 additions and 0 deletions

View File

@@ -77,6 +77,35 @@
t.eq(line.components[1].y, y1 + dy, "move() correctly modifies second y");
}
function test_LineString_rotate(t) {
t.plan(6);
var components = [new OpenLayers.Geometry.Point(10,15),
new OpenLayers.Geometry.Point(0,0)];
var geometry = new OpenLayers.Geometry.LineString(components);
var originals = [];
var comp;
var angle = 2 * Math.PI * Math.random();
var origin = new OpenLayers.Geometry.Point(10 * Math.random(),
10 * Math.random());
for(var i=0; i<geometry.components.length; ++i) {
comp = geometry.components[i];
originals[i] = comp.rotate;
comp.rotate = function(a, o) {
t.ok(true, "rotate called for component " + i);
t.ok(a == angle, "rotate called with correct angle");
t.ok(o == origin, "rotate called with correct origin");
}
}
geometry.rotate(angle, origin);
// restore the original rotate defs
for(var i=0; i<geometry.components.length; ++i) {
comp.rotate = originals[i];
}
}
function test_LineString_equals(t) {
t.plan(3);

View File

@@ -79,6 +79,30 @@
t.eq(point.y, y + dy, "move() correctly modifies y");
}
function test_Point_rotate(t) {
t.plan(4);
var tolerance = 1e-10;
var x = 10;
var y = 20;
var point = new OpenLayers.Geometry.Point(x, y);
var origin = new OpenLayers.Geometry.Point(5, 10);
// rotate a full revolution
point.rotate(2 * Math.PI, origin);
t.ok(((point.x - x) / x) < tolerance,
"rotate by 2 * Math.PI returns to the same y");
t.ok(((point.y - y) / y) < tolerance,
"rotate by 2 * Math.PI returns to the same y")
// rotate an 1/8 turn
point.rotate(Math.PI / 4, origin);
t.ok(((point.x - 1.4644660940672636) / 1.4644660940672636) < tolerance,
"rotate 1/8 turn correctly");
t.ok(((point.y - 20.606601717798213) / 20.606601717798213) < tolerance,
"rotate 1/8 turn correctly")
}
function test_Point_equals(t) {
t.plan(3);

View File

@@ -106,6 +106,33 @@
t.eq(polygon.components[1].components[0].y, y2 + dy, "move() correctly modifies second y");
}
function test_Polygon_rotate(t) {
t.plan(6);
var geometry = new OpenLayers.Geometry.Polygon([linearRing, linearRing2]);
var originals = [];
var comp;
var angle = 2 * Math.PI * Math.random();
var origin = new OpenLayers.Geometry.Point(10 * Math.random(),
10 * Math.random());
for(var i=0; i<geometry.components.length; ++i) {
comp = geometry.components[i];
originals[i] = comp.rotate;
comp.rotate = function(a, o) {
t.ok(true, "rotate called for component " + i);
t.ok(a == angle, "rotate called with correct angle");
t.ok(o == origin, "rotate called with correct origin");
}
}
geometry.rotate(angle, origin);
// restore the original rotate defs
for(var i=0; i<geometry.components.length; ++i) {
comp.rotate = originals[i];
}
}
function test_Polygon_equals(t) {
t.plan(3);