This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

✨ Implement Color.solid/translucent/etc to create Fill objects

+25 -11
+25 -11
src/graphics/fill.rs
··· 4 4 pub enum Fill { 5 5 Solid(Color), 6 6 Translucent(Color, f32), 7 + /// Hatches(color, angle, thickness_ratio, spacing) 7 8 Hatches(Color, Angle, f32, f32), 9 + /// Dotted(color, diameter, spacing) 8 10 Dotted(Color, f32, f32), 9 11 } 10 12 13 + impl Color { 14 + pub fn solid(self) -> Fill { 15 + Fill::Solid(self) 16 + } 17 + 18 + pub fn translucent(self, opacity: f32) -> Fill { 19 + Fill::Translucent(self, opacity) 20 + } 21 + 22 + pub fn hatches(self, angle: Angle, thickness: f32, spacing: f32) -> Fill { 23 + Fill::Hatches(self, angle, thickness, spacing) 24 + } 25 + 26 + pub fn dotted(self, diameter: f32, spacing: f32) -> Fill { 27 + Fill::Dotted(self, diameter, spacing) 28 + } 29 + } 30 + 11 31 // Operations that can be applied on fills. 12 - // Applying them on Option<Fill> is also possible, and will return an Option<Fill>. 13 32 pub trait FillOperations { 14 33 fn opacify(&self, opacity: f32) -> Self; 15 - fn bottom_up_hatches(color: Color, thickness: f32, spacing: f32) -> Self; 16 34 } 17 35 18 36 impl FillOperations for Fill { ··· 23 41 _ => *self, 24 42 } 25 43 } 26 - 27 - fn bottom_up_hatches(color: Color, thickness: f32, spacing: f32) -> Self { 28 - Fill::Hatches(color, Angle(45.0), thickness, spacing) 29 - } 30 44 } 31 45 32 46 impl FillOperations for Option<Fill> { 33 47 fn opacify(&self, opacity: f32) -> Self { 34 - self.as_ref().map(|fill| fill.opacify(opacity)) 48 + self.map(|fill| fill.opacify(opacity)) 35 49 } 50 + } 36 51 37 - fn bottom_up_hatches(color: Color, thickness: f32, spacing: f32) -> Self { 38 - Some(Fill::bottom_up_hatches(color, thickness, spacing)) 52 + impl Fill { 53 + pub fn bottom_up_hatches(color: Color, thickness: f32, spacing: f32) -> Self { 54 + Fill::Hatches(color, Angle(45.0), thickness, spacing) 39 55 } 40 - } 41 56 42 - impl Fill { 43 57 pub fn pattern_id(&self) -> String { 44 58 if let Fill::Hatches(color, angle, thickness, spacing) = self { 45 59 return format!(