Commit fb8c5a4f by Dmitry Baranovskiy

fixed snapTo for first value as a number

parent 744b8506
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
rg = /^(?=[\da-f]$)/, rg = /^(?=[\da-f]$)/,
ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i, ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i,
colourRegExp = /^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+(?:\s*,\s*[\d\.]+)?)\s*\)|rgba?\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%(?:\s*,\s*[\d\.]+%)?)\s*\)|hsb\(\s*([\d\.]+(?:deg|\xb0)?\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hsb\(\s*([\d\.]+(?:deg|\xb0|%)\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\)|hsl\(\s*([\d\.]+(?:deg|\xb0)?\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hsl\(\s*([\d\.]+(?:deg|\xb0|%)\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i, colourRegExp = /^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+\s*,\s*[\d\.]+\s*,\s*[\d\.]+(?:\s*,\s*[\d\.]+)?)\s*\)|rgba?\(\s*([\d\.]+%\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%(?:\s*,\s*[\d\.]+%)?)\s*\)|hsb\(\s*([\d\.]+(?:deg|\xb0)?\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hsb\(\s*([\d\.]+(?:deg|\xb0|%)\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\)|hsl\(\s*([\d\.]+(?:deg|\xb0)?\s*,\s*[\d\.]+\s*,\s*[\d\.]+)\s*\)|hsl\(\s*([\d\.]+(?:deg|\xb0|%)\s*,\s*[\d\.]+%\s*,\s*[\d\.]+%)\s*\))\s*$/i,
isnan = /^(NaN|-?Infinity)$/, isnan = {"NaN": 1, "Infinity": 1, "-Infinity": 1},
bezierrg = /^cubic-bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/, bezierrg = /^cubic-bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/,
round = math.round, round = math.round,
setAttribute = "setAttribute", setAttribute = "setAttribute",
...@@ -109,7 +109,7 @@ ...@@ -109,7 +109,7 @@
R.is = function (o, type) { R.is = function (o, type) {
type = lowerCase.call(type); type = lowerCase.call(type);
if (type == "finite") { if (type == "finite") {
return !isnan.test(+o); return !isnan[has](+o);
} }
return (type == "null" && o === null) || return (type == "null" && o === null) ||
(type == typeof o) || (type == typeof o) ||
...@@ -130,12 +130,22 @@ ...@@ -130,12 +130,22 @@
} }
}; };
R.snapTo = function (values, value, tolerance) { R.snapTo = function (values, value, tolerance) {
tolerance = tolerance || 10; tolerance = R.is(tolerance, "finite") ? tolerance : 10;
values = [][concat](values); if (R.is(values, array)) {
var i = values.length; var i = values.length;
while (i--) if (abs(values[i] - value) <= tolerance) { while (i--) if (abs(values[i] - value) <= tolerance) {
return values[i]; return values[i];
} }
} else {
values = +values;
var rem = value % values;
if (rem < tolerance) {
return value - rem;
}
if (rem > values - tolerance) {
return value - rem + values;
}
}
return value; return value;
}; };
function createUUID() { function createUUID() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment