improved alpha channel handling for math ops, removed 'can't substract or divide a color from a number' constraint

This commit is contained in:
seven-phases-max
2013-11-24 04:46:27 +04:00
parent 3b242daacd
commit 4b113be27e
4 changed files with 9 additions and 21 deletions

View File

@@ -70,16 +70,12 @@ tree.Color.prototype = {
// we create a new Color node to hold the result.
//
operate: function (env, op, other) {
var result = [];
if (! (other instanceof tree.Color)) {
other = other.toColor();
}
var rgb = [];
var alpha = this.alpha * (1 - other.alpha) + other.alpha;
for (var c = 0; c < 3; c++) {
result[c] = tree.operate(env, op, this.rgb[c], other.rgb[c]);
rgb[c] = tree.operate(env, op, this.rgb[c], other.rgb[c]);
}
return new(tree.Color)(result, this.alpha + other.alpha);
return new(tree.Color)(rgb, alpha);
},
toRGB: function () {

View File

@@ -12,17 +12,14 @@ tree.Operation.prototype = {
},
eval: function (env) {
var a = this.operands[0].eval(env),
b = this.operands[1].eval(env),
temp;
b = this.operands[1].eval(env);
if (env.isMathOn()) {
if (a instanceof tree.Dimension && b instanceof tree.Color) {
if (this.op === '*' || this.op === '+') {
temp = b, b = a, a = temp;
} else {
throw { type: "Operation",
message: "Can't substract or divide a color from a number" };
}
a = a.toColor();
}
if (b instanceof tree.Dimension && a instanceof tree.Color) {
b = b.toColor();
}
if (!a.operate) {
throw { type: "Operation",

View File

@@ -1,3 +0,0 @@
.a {
prop: (3 / #fff);
}

View File

@@ -1,2 +0,0 @@
OperationError: Can't substract or divide a color from a number in {path}color-operation-error.less on line null, column 0:
1 prop: (3 / #fff);