Ogeon / palette

A Rust library for linear color calculations and conversion
Apache License 2.0
752 stars 60 forks source link

Make most operator traits take their input by value and change `TransferFn` to `TransferFn<T>` #246

Closed Ogeon closed 3 years ago

Ogeon commented 3 years ago

This makes all of the traits have the same convention, modeled after the core::ops traits, and leaves any cloning to the caller. I considered adding an Outputtype too, but that can go into a separate pass.

Breaking Change

Almost every trait that takes parameters have changed here, so that may be breaking for non-Copy types. The clamp_self method is also gone.

github-actions[bot] commented 3 years ago

Benchmark for 0d7a57a

Click to view benchmark | Test | PR Benchmark | Master Benchmark | % | |------|--------------|------------------|---| | Cie family/lab to lch | **3.5±0.03µs** | 3.6±0.14µs | **-2.78%** | | Cie family/lab to xyz | **964.2±15.61ns** | 974.1±7.31ns | **-1.02%** | | Cie family/lch to lab | **2.5±0.03µs** | 2.6±0.08µs | **-3.85%** | | Cie family/linsrgb to xyz | 3.9±0.06µs | 3.9±0.05µs | 0.00% | | Cie family/xyz to lab | **10.7±0.23µs** | 11.2±0.94µs | **-4.46%** | | Cie family/xyz to yxy | 750.3±22.61ns | **735.2±7.73ns** | **+2.05%** | | Cie family/yxy to xyz | **622.6±10.83ns** | 680.8±8.03ns | **-8.55%** | | Matrix functions/matrix_inverse | 13.4±0.21ns | **13.0±0.24ns** | **+3.08%** | | Matrix functions/multiply_3x3 | **11.0±0.21ns** | 11.4±0.15ns | **-3.51%** | | Matrix functions/multiply_rgb_to_xyz | 4.8±0.07ns | 4.8±0.07ns | 0.00% | | Matrix functions/multiply_xyz | **4.9±0.07ns** | 5.0±0.20ns | **-2.00%** | | Matrix functions/multiply_xyz_to_rgb | 4.8±0.07ns | 4.8±0.09ns | 0.00% | | Matrix functions/rgb_to_xyz_matrix | 25.4±0.35ns | 25.6±0.25ns | -0.78% | | Rgb family/hsl to hsv | **689.3±11.26ns** | 790.6±10.95ns | **-12.81%** | | Rgb family/hsl to linear hsl | 9.8±0.15µs | **9.6±0.14µs** | **+2.08%** | | Rgb family/hsl to rgb | 2.5±0.05µs | 2.5±0.03µs | 0.00% | | Rgb family/hsv to hsl | 1135.3±16.47ns | 1148.2±16.81ns | -1.12% | | Rgb family/hsv to hwb | 281.2±9.33ns | **268.4±7.73ns** | **+4.77%** | | Rgb family/hsv to linear hsv | 9.1±0.13µs | 9.1±0.12µs | 0.00% | | Rgb family/hsv to rgb | 2.5±0.03µs | 2.5±0.05µs | 0.00% | | Rgb family/hwb to hsv | 569.8±8.28ns | **561.7±7.81ns** | **+1.44%** | | Rgb family/hwb to linear hwb | 10.9±0.16µs | 11.0±0.48µs | -0.91% | | Rgb family/linear hsl to hsl | 10.3±0.14µs | 10.2±0.18µs | +0.98% | | Rgb family/linear hsv to hsv | **9.6±0.21µs** | 9.8±0.10µs | **-2.04%** | | Rgb family/linear hwb to hwb | **11.9±0.13µs** | 12.2±0.38µs | **-2.46%** | | Rgb family/linsrgb to rgb | 4.7±0.08µs | 4.7±0.06µs | 0.00% | | Rgb family/linsrgb_f32 to rgb_u8 | 6.4±0.08µs | 6.4±0.10µs | 0.00% | | Rgb family/rgb to hsl | 880.7±14.32ns | 881.3±14.46ns | -0.07% | | Rgb family/rgb to hsv | 679.3±6.31ns | 675.4±10.20ns | +0.58% | | Rgb family/rgb to linsrgb | 5.1±0.05µs | 5.1±0.08µs | 0.00% | | Rgb family/rgb_u8 to linsrgb_f32 | 5.4±0.09µs | 5.4±0.10µs | 0.00% | | Rgb family/xyz to linsrgb | 9.0±0.07µs | **8.4±0.08µs** | **+7.14%** |
Ogeon commented 3 years ago

I'm going to go through the traits again and do some more focused improvements. These were just some fixes and low hanging fruit they had in common.

bors r+

bors[bot] commented 3 years ago

Build succeeded: