primitives/foundation/colorspace/
round.rs1use super::prelude::*;
2
3use super::*;
4
5pub trait Round {
7 fn round(self) -> Self;
9}
10
11impl Round for Color {
12 fn round(self) -> Self {
13 Color {
14 red: self.red.round(),
15 green: self.green.round(),
16 blue: self.blue.round(),
17 alpha: self.alpha.round(),
18 }
19 }
20}
21
22impl Round for HslColor {
23 fn round(self) -> Self {
24 HslColor {
25 hue: self.hue.round(),
26 saturation: self.saturation.round(),
27 lightness: self.lightness.round(),
28 }
29 }
30}
31
32impl Round for HsvColor {
33 fn round(self) -> Self {
34 HsvColor {
35 hue: self.hue.round(),
36 saturation: self.saturation.round(),
37 value: self.value.round(),
38 }
39 }
40}
41
42impl Round for CmykColor {
43 fn round(self) -> Self {
44 CmykColor {
45 cyan: self.cyan.round(),
46 magenta: self.magenta.round(),
47 yellow: self.yellow.round(),
48 key: self.key.round(),
49 }
50 }
51}
52
53impl Round for CmyColor {
54 fn round(self) -> Self {
55 CmyColor {
56 cyan: self.cyan.round(),
57 magenta: self.magenta.round(),
58 yellow: self.yellow.round(),
59 }
60 }
61}
62
63impl<C: Round + ColorSpace> Round for Alpha<C> {
64 fn round(self) -> Self {
65 let (color, alpha) = self.split();
66 Alpha::new(color.round(), alpha)
67 }
68}