Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- impl Color {
- // Constructor for CMYK model
- pub fn from_cmyk(c: f64, m: f64, y: f64, k: f64) -> Color {
- if !Self::is_valid_ratio(c) {
- panic!("Invalid Cyan value {} in CMYK model", c);
- }
- if !Self::is_valid_ratio(m) {
- panic!("Invalid Magenta value {} in CMYK model", m);
- }
- if !Self::is_valid_ratio(y) {
- panic!("Invalid Yellow value {} in CMYK model", y);
- }
- if !Self::is_valid_ratio(k) {
- panic!("Invalid Black value {} in CMYK model", k);
- }
- Color::CMYK{ c: c, m: m, y: y, k: k }
- }
- }
- impl Color {
- // Private class method used to validate ratio value
- fn is_valid_ratio(n: f64) -> bool {
- 0.0 <= n && n <= 1.0
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement