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
+16 -4
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 (
/**
* @param {number|undefined} rotation Rotation.
* @param {number} delta Delta.
* @return {number|undefined} Rotation.
*/
function(rotation, delta) {
if (goog.isDef(rotation)) { if (goog.isDef(rotation)) {
rotation = Math.floor((rotation + delta) / theta + 0.5) * theta; rotation = Math.floor((rotation + delta) / theta + 0.5) * theta;
return rotation; return rotation;
} else { } else {
return undefined; return undefined;
} }
}; });
}; };
@@ -45,7 +51,13 @@ 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 (
/**
* @param {number|undefined} rotation Rotation.
* @param {number} delta Delta.
* @return {number|undefined} Rotation.
*/
function(rotation, delta) {
if (goog.isDef(rotation)) { if (goog.isDef(rotation)) {
if (Math.abs(rotation + delta) <= tolerance) { if (Math.abs(rotation + delta) <= tolerance) {
return 0; return 0;
@@ -55,5 +67,5 @@ ol.RotationConstraint.createSnapToZero = function(opt_tolerance) {
} else { } else {
return undefined; return undefined;
} }
}; });
}; };