Skip to content

Commit

Permalink
round -> floor
Browse files Browse the repository at this point in the history
  • Loading branch information
ColCh committed Feb 4, 2014
1 parent abe5861 commit c40d6b6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/abstractions.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,10 @@
* @extends Easing
*/
function CubicBezier (p1x, p1y, p2x, p2y) {
this.p1x = round(p1x, CUBIC_BEZIER_POINTS_DIGITS);
this.p1y = round(p1y, CUBIC_BEZIER_POINTS_DIGITS);
this.p2x = round(p2x, CUBIC_BEZIER_POINTS_DIGITS);
this.p2y = round(p2y, CUBIC_BEZIER_POINTS_DIGITS);
this.p1x = floor(p1x, CUBIC_BEZIER_POINTS_DIGITS);
this.p1y = floor(p1y, CUBIC_BEZIER_POINTS_DIGITS);
this.p2x = floor(p2x, CUBIC_BEZIER_POINTS_DIGITS);
this.p2y = floor(p2y, CUBIC_BEZIER_POINTS_DIGITS);
}

goog.inherits(CubicBezier, Easing);
Expand Down
16 changes: 8 additions & 8 deletions src/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
var lightness = args[2][0] / 100;
var m2 = (lightness <= 0.5) ? lightness * (saturation + 1) : (lightness + saturation - lightness * saturation);
var m1 = lightness * 2 - m2;
var red = round(hueToRGB(m1, m2, hue + 1/3) * 255, 0);
var green = round(hueToRGB(m1, m2, hue) * 255, 0);
var blue = round(hueToRGB(m1, m2, hue - 1/3) * 255, 0);
var red = floor(hueToRGB(m1, m2, hue + 1/3) * 255, 0);
var green = floor(hueToRGB(m1, m2, hue) * 255, 0);
var blue = floor(hueToRGB(m1, m2, hue - 1/3) * 255, 0);
return [ red, green, blue ];
},

Expand All @@ -98,22 +98,22 @@
}
}

red = round(args[0][0], 0);
green = round(args[1][0], 0);
blue = round(args[2][0], 0);
red = floor(args[0][0], 0);
green = floor(args[1][0], 0);
blue = floor(args[2][0], 0);

return [ red, green, blue ];
},

"hsla": function (args) {
var rgb = colorFunctions["hsl"](args);
var opacity = round(args[3][0], 1);
var opacity = floor(args[3][0], 1);
return rgb.concat(opacity);
},

"rgba": function (args) {
var rgb = colorFunctions["rgb"](args);
var opacity = round(args[3][0], 1);
var opacity = floor(args[3][0], 1);
return rgb.concat(opacity);
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
* @param {number} number
* @param {number} digits
*/
function round (number, digits) {
function floor (number, digits) {
if (digits === 0) {
return number | 0;
} else {
Expand All @@ -140,7 +140,7 @@
var valueIsChanged = false;

for (var i = from.length; i--; ) {
valueIsChanged = currentValue[i] !== (currentValue[i] = round( (to[i] - from[i]) * progress + from[i] , roundDigits)) || valueIsChanged;
valueIsChanged = currentValue[i] !== (currentValue[i] = floor( (to[i] - from[i]) * progress + from[i] , roundDigits)) || valueIsChanged;
}

return valueIsChanged;
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ test('toNumericValueHooks["color"]', function () {
deepEqual(toNumericValueHooks["color"](dummyElement, propertyName, '#00FFFF', vendorizedPropName), [0, 255, 255], 'conversion of hex color (aqua)');

deepEqual(toNumericValueHooks["color"](dummyElement, propertyName, 'rgb(255, 255, 0)', vendorizedPropName), [255, 255, 0], 'conversion of rgb integers color (yellow)');
deepEqual(toNumericValueHooks["color"](dummyElement, propertyName, 'rgb(254.999, 254.999, 0)', vendorizedPropName), [255, 255, 0], 'conversion of rgb FLOATED integers color (yellow)');
deepEqual(toNumericValueHooks["color"](dummyElement, propertyName, 'rgb(254.999, 254.999, 0)', vendorizedPropName), [254, 254, 0], 'conversion of rgb FLOATED integers color (yellow)');
deepEqual(toNumericValueHooks["color"](dummyElement, propertyName, 'rgb(100%, 100%, 0%)', vendorizedPropName), [255, 255, 0], 'conversion of rgb percents color (yellow)');

deepEqual(toNumericValueHooks["color"](dummyElement, propertyName, 'hsl(0, 100%, 50%)', vendorizedPropName), [255, 0, 0], 'conversion of hsl color (red)');
deepEqual(toNumericValueHooks["color"](dummyElement, propertyName, 'hsl(0, 99.999%, 49.999%)', vendorizedPropName), [255, 0, 0], 'conversion of hsl FLOATED color (red)');
deepEqual(toNumericValueHooks["color"](dummyElement, propertyName, 'hsl(0, 99.999%, 49.999%)', vendorizedPropName), [254, 0, 0], 'conversion of hsl FLOATED color (red)');

deepEqual(toNumericValueHooks["color"](dummyElement, propertyName, 'rgba(255, 255, 0, 0.5)', vendorizedPropName), [255, 255, 0, 0.5], 'conversion of rgba integers color (with transparency) (yellow)');
deepEqual(toNumericValueHooks["color"](dummyElement, propertyName, 'rgba(254.999, 254.999, 0, 0.4999)', vendorizedPropName), [255, 255, 0, 0.5], 'conversion of FLOATED rgba integers color (with transparency) (yellow)');
deepEqual(toNumericValueHooks["color"](dummyElement, propertyName, 'rgba(254.999, 254.999, 0, 0.4999)', vendorizedPropName), [254, 254, 0, 0.4], 'conversion of FLOATED rgba integers color (with transparency) (yellow)');
deepEqual(toNumericValueHooks["color"](dummyElement, propertyName, 'hsla(0, 100%, 50%, 0.5)', vendorizedPropName), [255, 0, 0, 0.5], 'conversion of hsla color (with transparency) (red)');
deepEqual(toNumericValueHooks["color"](dummyElement, propertyName, 'hsla(0, 99.999%, 49.999%, 0.4999)', vendorizedPropName), [255, 0, 0, 0.5], 'conversion of FLOATED hsla color (with transparency) (red)');
deepEqual(toNumericValueHooks["color"](dummyElement, propertyName, 'hsla(0, 99.999%, 49.999%, 0.4999)', vendorizedPropName), [254, 0, 0, 0.4], 'conversion of FLOATED hsla color (with transparency) (red)');
});

test('toStringValueHooks["color"]', function () {
Expand Down
12 changes: 6 additions & 6 deletions tests/tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ test('sortArray', function () {

});

test('round', function () {
strictEqual(round(4, 0), 4, 'integer rounding');
strictEqual(round(4.5, 0), 5, 'float rounding');
strictEqual(round(4.123456, 5), 4.12346, 'precision rounding');
test('floor', function () {
strictEqual(floor(4, 0), 4, 'integer rounding');
strictEqual(floor(4.5, 0), 4, 'float rounding');
strictEqual(floor(4.123456, 5), 4.12345, 'precision rounding');
});

test('blend', function () {
Expand All @@ -96,9 +96,9 @@ test('blend', function () {
ok(!blend(from, to, progress, current, roundDigits), 'valueIsChanged (is not changed)');
strictEqual(current[0], 0.5, 'check result value');
blend(from, to, 0.5555, current, 2);
strictEqual(current[0], 0.56, 'check rounding (precision)');
strictEqual(current[0], 0.55, 'check rounding (precision)');
blend(from, to, 0.5555, current, 0);
strictEqual(current[0], 1, 'check rounding (to integer)');
strictEqual(current[0], 0, 'check rounding (to integer)');
});

test('trim', function () {
Expand Down

0 comments on commit c40d6b6

Please sign in to comment.