AngleSharp / AngleSharp.Css

:angel: Library to enable support for cascading stylesheets in AngleSharp.
https://anglesharp.github.io
MIT License
72 stars 34 forks source link

Even if the RGB value is 100%, it will not be 255(ColorParser) #134

Closed SDH0531 closed 1 year ago

SDH0531 commented 1 year ago

[AngleSharp.CSS v0.17.0]

If the color is specified in % like "RGB(100%,100%,100%);", the RGB value will be 254 instead of 255. I checked the source code, the calculation of the color value was as follows.

ColorParser.cs(217) return (Byte)(255f / 100f * value);

With this, even if the value is 100, the result will be 254. I don't think this is the correct behavior.

FlorianRappl commented 1 year ago

Yes for stability it should be multiplication before division, otherwise we run into FP issues.

PR welcome.

SDH0531 commented 1 year ago

Hi Florian That's right, this problem caused by performing division first. Therefore, this problem can be solved by simply performing the multiplication first. Thanks

cyraid commented 1 year ago

If value is between 0.0 and 1.0, why wouldn't you just do return (byte)(255.0 * value); ? Or am I missing something?