Use degrees instead of radians for geometry.rotate method (closes #948).

git-svn-id: http://svn.openlayers.org/trunk/openlayers@4127 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2007-08-30 17:10:26 +00:00
parent b78aec44c9
commit be4180fd75
6 changed files with 13 additions and 12 deletions

View File

@@ -82,11 +82,11 @@
var center = new OpenLayers.Feature.Vector(origin, null, style); var center = new OpenLayers.Feature.Vector(origin, null, style);
vectorLayer.addFeatures([center]); vectorLayer.addFeatures([center]);
window.setInterval(rotateFeature, 100, window.setInterval(rotateFeature, 100,
pointFeature, Math.PI / 10, origin); pointFeature, 360 / 20, origin);
window.setInterval(rotateFeature, 100, window.setInterval(rotateFeature, 100,
lineFeature, Math.PI / 20, origin); lineFeature, 360 / 40, origin);
window.setInterval(rotateFeature, 100, window.setInterval(rotateFeature, 100,
polygonFeature, -1 * Math.PI / 10, origin); polygonFeature, -360 / 20, origin);
} }
function rotateFeature(feature, angle, origin) { function rotateFeature(feature, angle, origin) {

View File

@@ -248,7 +248,7 @@ OpenLayers.Geometry.Collection = OpenLayers.Class(OpenLayers.Geometry, {
* Rotate a geometry around some origin * Rotate a geometry around some origin
* *
* Parameters: * Parameters:
* angle - {Float} Rotation angle in radians (measured counterclockwise * angle - {Float} Rotation angle in degrees (measured counterclockwise
* from the positive x-axis) * from the positive x-axis)
* origin - {<OpenLayers.Geometry.Point>} Center point for the rotation * origin - {<OpenLayers.Geometry.Point>} Center point for the rotation
*/ */

View File

@@ -124,7 +124,7 @@ OpenLayers.Geometry.LinearRing = OpenLayers.Class(
* Rotate a geometry around some origin * Rotate a geometry around some origin
* *
* Parameters: * Parameters:
* angle - {Float} Rotation angle in radians (measured counterclockwise * angle - {Float} Rotation angle in degrees (measured counterclockwise
* from the positive x-axis) * from the positive x-axis)
* origin - {<OpenLayers.Geometry.Point>} Center point for the rotation * origin - {<OpenLayers.Geometry.Point>} Center point for the rotation
*/ */

View File

@@ -133,14 +133,15 @@ OpenLayers.Geometry.Point = OpenLayers.Class(OpenLayers.Geometry, {
/** /**
* APIMethod: rotate * APIMethod: rotate
* Rotate a point around another * Rotate a point around another.
* *
* Parameters: * Parameters:
* angle - {Float} Rotation angle in radians (measured counterclockwise * angle - {Float} Rotation angle in degrees (measured counterclockwise
* from the positive x-axis) * from the positive x-axis)
* origin - {<OpenLayers.Geometry.Point>} Center point for the rotation * origin - {<OpenLayers.Geometry.Point>} Center point for the rotation
*/ */
rotate: function(angle, origin) { rotate: function(angle, origin) {
angle *= Math.PI / 180;
var radius = this.distanceTo(origin); var radius = this.distanceTo(origin);
var theta = angle + Math.atan2(this.y - origin.y, this.x - origin.x); var theta = angle + Math.atan2(this.y - origin.y, this.x - origin.x);
this.x = origin.x + (radius * Math.cos(theta)); this.x = origin.x + (radius * Math.cos(theta));

View File

@@ -159,7 +159,7 @@
// rotate a quarter turn around the origin // rotate a quarter turn around the origin
var origin = new OpenLayers.Geometry.Point(0, 0); var origin = new OpenLayers.Geometry.Point(0, 0);
var angle = Math.PI / 2; var angle = 90;
ring.rotate(angle, origin); ring.rotate(angle, origin);

View File

@@ -92,16 +92,16 @@
// rotate a full revolution // rotate a full revolution
point.bounds = "foo"; point.bounds = "foo";
point.rotate(2 * Math.PI, origin); point.rotate(360, origin);
t.ok(((point.x - x) / x) < tolerance, t.ok(((point.x - x) / x) < tolerance,
"rotate by 2 * Math.PI returns to the same y"); "rotate by 360 returns to the same y");
t.ok(((point.y - y) / y) < tolerance, t.ok(((point.y - y) / y) < tolerance,
"rotate by 2 * Math.PI returns to the same y"); "rotate by 360 returns to the same y");
t.ok(point.bounds == null, "bounds is cleared after a rotate()"); t.ok(point.bounds == null, "bounds is cleared after a rotate()");
// rotate an 1/8 turn // rotate an 1/8 turn
point.rotate(Math.PI / 4, origin); point.rotate(45, origin);
t.ok(((point.x - 1.4644660940672636) / 1.4644660940672636) < tolerance, t.ok(((point.x - 1.4644660940672636) / 1.4644660940672636) < tolerance,
"rotate 1/8 turn correctly"); "rotate 1/8 turn correctly");
t.ok(((point.y - 20.606601717798213) / 20.606601717798213) < tolerance, t.ok(((point.y - 20.606601717798213) / 20.606601717798213) < tolerance,