Improve type checking in ol.RotationConstraint

This commit is contained in:
Tom Payne
2013-04-30 21:32:19 +02:00
parent bd9d723315
commit fe9fee1609
+31 -19
View File
@@ -28,14 +28,20 @@ ol.RotationConstraint.none = function(rotation, delta) {
*/ */
ol.RotationConstraint.createSnapToN = function(n) { ol.RotationConstraint.createSnapToN = function(n) {
var theta = 2 * Math.PI / n; var theta = 2 * Math.PI / n;
return function(rotation, delta) { return (
if (goog.isDef(rotation)) { /**
rotation = Math.floor((rotation + delta) / theta + 0.5) * theta; * @param {number|undefined} rotation Rotation.
return rotation; * @param {number} delta Delta.
} else { * @return {number|undefined} Rotation.
return undefined; */
} function(rotation, delta) {
}; if (goog.isDef(rotation)) {
rotation = Math.floor((rotation + delta) / theta + 0.5) * theta;
return rotation;
} else {
return undefined;
}
});
}; };
@@ -45,15 +51,21 @@ ol.RotationConstraint.createSnapToN = function(n) {
*/ */
ol.RotationConstraint.createSnapToZero = function(opt_tolerance) { ol.RotationConstraint.createSnapToZero = function(opt_tolerance) {
var tolerance = opt_tolerance || 0.1; var tolerance = opt_tolerance || 0.1;
return function(rotation, delta) { return (
if (goog.isDef(rotation)) { /**
if (Math.abs(rotation + delta) <= tolerance) { * @param {number|undefined} rotation Rotation.
return 0; * @param {number} delta Delta.
} else { * @return {number|undefined} Rotation.
return rotation + delta; */
} function(rotation, delta) {
} else { if (goog.isDef(rotation)) {
return undefined; if (Math.abs(rotation + delta) <= tolerance) {
} return 0;
}; } else {
return rotation + delta;
}
} else {
return undefined;
}
});
}; };