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:
@@ -82,11 +82,11 @@
|
||||
var center = new OpenLayers.Feature.Vector(origin, null, style);
|
||||
vectorLayer.addFeatures([center]);
|
||||
window.setInterval(rotateFeature, 100,
|
||||
pointFeature, Math.PI / 10, origin);
|
||||
pointFeature, 360 / 20, origin);
|
||||
window.setInterval(rotateFeature, 100,
|
||||
lineFeature, Math.PI / 20, origin);
|
||||
lineFeature, 360 / 40, origin);
|
||||
window.setInterval(rotateFeature, 100,
|
||||
polygonFeature, -1 * Math.PI / 10, origin);
|
||||
polygonFeature, -360 / 20, origin);
|
||||
}
|
||||
|
||||
function rotateFeature(feature, angle, origin) {
|
||||
|
||||
@@ -248,7 +248,7 @@ OpenLayers.Geometry.Collection = OpenLayers.Class(OpenLayers.Geometry, {
|
||||
* Rotate a geometry around some origin
|
||||
*
|
||||
* Parameters:
|
||||
* angle - {Float} Rotation angle in radians (measured counterclockwise
|
||||
* angle - {Float} Rotation angle in degrees (measured counterclockwise
|
||||
* from the positive x-axis)
|
||||
* origin - {<OpenLayers.Geometry.Point>} Center point for the rotation
|
||||
*/
|
||||
|
||||
@@ -124,7 +124,7 @@ OpenLayers.Geometry.LinearRing = OpenLayers.Class(
|
||||
* Rotate a geometry around some origin
|
||||
*
|
||||
* Parameters:
|
||||
* angle - {Float} Rotation angle in radians (measured counterclockwise
|
||||
* angle - {Float} Rotation angle in degrees (measured counterclockwise
|
||||
* from the positive x-axis)
|
||||
* origin - {<OpenLayers.Geometry.Point>} Center point for the rotation
|
||||
*/
|
||||
|
||||
@@ -133,14 +133,15 @@ OpenLayers.Geometry.Point = OpenLayers.Class(OpenLayers.Geometry, {
|
||||
|
||||
/**
|
||||
* APIMethod: rotate
|
||||
* Rotate a point around another
|
||||
* Rotate a point around another.
|
||||
*
|
||||
* Parameters:
|
||||
* angle - {Float} Rotation angle in radians (measured counterclockwise
|
||||
* angle - {Float} Rotation angle in degrees (measured counterclockwise
|
||||
* from the positive x-axis)
|
||||
* origin - {<OpenLayers.Geometry.Point>} Center point for the rotation
|
||||
*/
|
||||
rotate: function(angle, origin) {
|
||||
angle *= Math.PI / 180;
|
||||
var radius = this.distanceTo(origin);
|
||||
var theta = angle + Math.atan2(this.y - origin.y, this.x - origin.x);
|
||||
this.x = origin.x + (radius * Math.cos(theta));
|
||||
|
||||
@@ -159,7 +159,7 @@
|
||||
|
||||
// rotate a quarter turn around the origin
|
||||
var origin = new OpenLayers.Geometry.Point(0, 0);
|
||||
var angle = Math.PI / 2;
|
||||
var angle = 90;
|
||||
|
||||
ring.rotate(angle, origin);
|
||||
|
||||
|
||||
@@ -92,16 +92,16 @@
|
||||
|
||||
// rotate a full revolution
|
||||
point.bounds = "foo";
|
||||
point.rotate(2 * Math.PI, origin);
|
||||
point.rotate(360, origin);
|
||||
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,
|
||||
"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()");
|
||||
|
||||
// rotate an 1/8 turn
|
||||
point.rotate(Math.PI / 4, origin);
|
||||
point.rotate(45, origin);
|
||||
t.ok(((point.x - 1.4644660940672636) / 1.4644660940672636) < tolerance,
|
||||
"rotate 1/8 turn correctly");
|
||||
t.ok(((point.y - 20.606601717798213) / 20.606601717798213) < tolerance,
|
||||
|
||||
Reference in New Issue
Block a user