vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.54k stars 2.14k forks source link

gx - operator overloading not working for Color #21549

Open Linklancien opened 1 month ago

Linklancien commented 1 month ago

Describe the bug

gx - operator overloading not working for Color

Reproduction Steps

import gx print(gx.rgba(128, 128, 128, 255) - gx.rgba(0, 0, 0, 155))

Expected Behavior

gx - operator have to return 128, 128, 128, 100

Current Behavior

return 128, 128, 128, 255

Possible Solution

mut na := int(a.a) - b.a if na < 0 { na = 0 }

Additional Information/Context

No response

V version

V 0.4.6 7a36b44

Environment details (OS name and version, etc.)

windows, Microsoft Windows 10 Famille v19045 64 bits

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

Linklancien commented 1 month ago

After reading the code of gx, a thinks it isn't a bug but maybe it nead some comment or else about it in the doc

spytheman commented 1 month ago

We can special case the .a == 255 case, to not modify the alpha, so that the tests for the defined colors (that are fully visible) will continue to work, while the - can be closer to the reverse operation for the + operation.

I do not see the use case for the current behavior 🤔 .