-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quick-fix for #1673 #1676
Quick-fix for #1673 #1676
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been thinking about this too. If I see what was your thinking in now allowing this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Let's see, w/o this patch it's:
Does it make sense that the addition is commutative (for type) and the substraction is not?
Or did you mean to convert black to a number? Maybe. But it's a common practice to convert operands to a "bigger" operand type regardless of which operand comes first, e.g. javascript:
Same for many other languages (at least those that allow math ops on different types).
... strange but not absolutely meaningless. |
||
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", | ||
|
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conside 0.1 and 0,9 - used to give 1, now would give
0.1 * (1-0.9) + 0.9
or
0.9 * (1-0.1) + 0.1
e.g.
0.91
why this instead of the old result, e.g. why shouldn't it be Math.min(1, this.alpha + other.alpha)
otherwise this looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And that is exactly what was wrong. Real-world example: Consider two half-transparent pieces of glass, when you put them together you can never get a completely non-transparent glass packet. The new formula is a common standard of handling alpha channel within color operations, basically it's just this one also known as this one (the same alpha compositing algorithm is used in svg, html.canvas and it was used in most of graphics editors and libraries since 80's :)
Nope, this is incorrect method. Alpha channel is like a color multiplier - so
(c1 * c1alpha) op (c2 * c2alpha)
cannot be implemented as just(c1 op c2) * clamp(c1alpha + c2alpha)
.Although this patch only fixes the overflowed alpha channel (i.e. #1673), but the operations themselves remain incorrect (so it is actually possible to use
Math.min(1, this.alpha + other.alpha)
for backward compatibility since it only makes either way incorrect transaparent-color ops to be just a bit more incorrect :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I see that, but is it correct to handle alpha like this but not the other components? this is the reason we added the extra blend functions, because standard add and mix handle things in a very standard way.
I like the change.. as long as no-one is relying on rgba(1,2,3,0.5) + rgb(1,2,3,0.5) to have alpha 1 like it is at the moment.. I'm just cautious about breaking changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope (though it still gives just a bit more "fair" result than
clamp(c1a + c2a)
), but in fact I used this formula only because it's simple and gives correct result for non-transparent colors passed (e.g. for alpha 1 + 1). So I absolutely do not mind if you change it toMath.min(1, this.alpha + other.alpha)
.I understand. Though I'd say the earlier a breaking change comes the less code it breaks :) I doubt if there's any code out there that really does something like
rgba(1,2,3,0.5) + rgba(1,2,3,0.5)