Skip to content
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

Relax color parser based on the current and upcoming CSS specs #478

Merged
merged 1 commit into from
Jun 4, 2021

Conversation

kimikage
Copy link
Collaborator

This adds supports for:

  • fractional RGB values, e.g. "rgb(255.0, 0.0, 0.0)"
  • fractional percentages, e.g. "rgb(1e2%, 34.5%, .6%)"
  • more clamping, e.g. "hsla(0, -10%, 120%, 1.5)"
  • hue angle units, e.g. "turn", "rad"
  • case-insensitive function names, e.g. "Rgb(0, 0, 0)"

This throws an error when mixing percentages and numbers, e.g. "rgb(100%, 128, 0%)".
This also changes the type of the errors from ErrorException to ArgumentError.

Closes #431

@kimikage kimikage added this to the 0.13 milestone May 29, 2021
@codecov
Copy link

codecov bot commented May 29, 2021

Codecov Report

Merging #478 (d6bb85e) into master (81aaf1e) will increase coverage by 0.55%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #478      +/-   ##
==========================================
+ Coverage   91.88%   92.44%   +0.55%     
==========================================
  Files           9        9              
  Lines         937      979      +42     
==========================================
+ Hits          861      905      +44     
+ Misses         76       74       -2     
Impacted Files Coverage Δ
src/parse.jl 97.47% <100.00%> (+3.97%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 81aaf1e...d6bb85e. Read the comment docs.

@kimikage kimikage removed this from the 0.13 milestone May 29, 2021
This adds supports for:
- fractional RGB values, e.g. "rgb(255.0, 0.0, 0.0)"
- fractional percentages, e.g. "rgb(1e2%, 34.5%, .6%)"
- more clamping, e.g. "hsla(0, -10%, 120%, 1.5)"
- hue angle units, e.g. "turn", "rad"
- case-insensitive function names, e.g. "Rgb(0, 0, 0)"

This throws an error when mixing percentages and numbers, e.g. "rgb(100%, 128, 0%)".
This also changes the type of the errors from `ErrorException` to `ArgumentError`.
@kimikage
Copy link
Collaborator Author

Benchmark

Linux (x86_64-linux-gnu) - Debian 10 on WSL2

Julia v1.6.1

target before(v0.12.8) after
"#C0FFEE" 251.870 ns (7 allocations: 352 bytes) 159.566 ns (5 allocations: 304 bytes)
"#C0FFEEaa" 268.553 ns (7 allocations: 352 bytes) 174.588 ns (5 allocations: 304 bytes)
"rgb(0,0,0)" 422.613 ns (7 allocations: 400 bytes) 409.000 ns (7 allocations: 400 bytes)
"rgba( 0, 11,222,0.45)" 714.925 ns (8 allocations: 432 bytes) 578.022 ns (8 allocations: 432 bytes)
"hsl(60,70%,80%)" 572.826 ns (7 allocations: 416 bytes) 459.898 ns (7 allocations: 416 bytes)
"LightGoldenRodYellow" 519.251 ns (6 allocations: 240 bytes) 347.907 ns (6 allocations: 240 bytes)
"lightgoldenrodyellow" 341.951 ns (3 allocations: 64 bytes) 185.286 ns (3 allocations: 64 bytes)

Windows (x86_64-w64-mingw32) - Windows 10

Julia v1.6.1

target before(v0.12.8) after
"#C0FFEE" 358.962 ns (7 allocations: 352 bytes) 242.280 ns (5 allocations: 304 bytes)
"#C0FFEEaa" 369.903 ns (7 allocations: 352 bytes) 261.408 ns (5 allocations: 304 bytes)
"rgb(0,0,0)" 628.902 ns (7 allocations: 400 bytes) 657.576 ns (7 allocations: 400 bytes)
"rgba( 0, 11,222,0.45)" 1.480 μs (8 allocations: 432 bytes) 1.250 μs (8 allocations: 432 bytes)
"hsl(60,70%,80%)" 805.882 ns (7 allocations: 416 bytes) 708.784 ns (7 allocations: 416 bytes)
"LightGoldenRodYellow" 878.723 ns (6 allocations: 240 bytes) 544.211 ns (6 allocations: 240 bytes)
"lightgoldenrodyellow" 692.199 ns (3 allocations: 64 bytes) 342.056 ns (3 allocations: 64 bytes)

@kimikage kimikage merged commit c28d392 into JuliaGraphics:master Jun 4, 2021
@kimikage kimikage deleted the issue431 branch June 4, 2021 22:36
@jonathanBieler jonathanBieler mentioned this pull request Sep 15, 2022
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fractional percentage notation in color parser
1 participant