Browse Source

formatting

Inderjit Gill 1 month ago
parent
commit
2c055346bb
3 changed files with 24 additions and 31 deletions
  1. 14
    19
      core/src/colour.rs
  2. 1
    3
      core/src/native.rs
  3. 9
    9
      utils/palette-maker/src/main.rs

+ 14
- 19
core/src/colour.rs View File

@@ -238,15 +238,20 @@ impl Colour {
238 238
     // hex in the form: "ff00ff"
239 239
     pub fn from_rgb_hex(hex: &str) -> Result<Self> {
240 240
         if hex.len() != 6 {
241
-            error!("Colour::from_rgb_hex expects input as 6 hex digits, actual: {}", hex);
242
-            return Err(Error::Colour)
241
+            error!(
242
+                "Colour::from_rgb_hex expects input as 6 hex digits, actual: {}",
243
+                hex
244
+            );
245
+            return Err(Error::Colour);
243 246
         }
244 247
 
245
-        Ok(Colour::new(ColourFormat::Rgb,
246
-                       normalised_colour_from_hex_string(&hex[0..2])?,
247
-                       normalised_colour_from_hex_string(&hex[2..4])?,
248
-                       normalised_colour_from_hex_string(&hex[4..])?,
249
-                       1.0))
248
+        Ok(Colour::new(
249
+            ColourFormat::Rgb,
250
+            normalised_colour_from_hex_string(&hex[0..2])?,
251
+            normalised_colour_from_hex_string(&hex[2..4])?,
252
+            normalised_colour_from_hex_string(&hex[4..])?,
253
+            1.0,
254
+        ))
250 255
     }
251 256
 
252 257
     pub fn convert(&self, format: ColourFormat) -> Result<Colour> {
@@ -1128,12 +1133,7 @@ mod tests {
1128 1133
         )
1129 1134
     }
1130 1135
 
1131
-    fn assert_colour(col: Colour,
1132
-                     format: ColourFormat,
1133
-                     e0: f32,
1134
-                     e1: f32,
1135
-                     e2: f32,
1136
-                     e3: f32) {
1136
+    fn assert_colour(col: Colour, format: ColourFormat, e0: f32, e1: f32, e2: f32, e3: f32) {
1137 1137
         is_format(col.format, format);
1138 1138
         assert_eq!(col.e0, e0);
1139 1139
         assert_eq!(col.e1, e1);
@@ -1141,12 +1141,7 @@ mod tests {
1141 1141
         assert_eq!(col.e3, e3);
1142 1142
     }
1143 1143
 
1144
-    fn assert_hex_colour(hex: &str,
1145
-                         format: ColourFormat,
1146
-                         e0: f32,
1147
-                         e1: f32,
1148
-                         e2: f32,
1149
-                         e3: f32) {
1144
+    fn assert_hex_colour(hex: &str, format: ColourFormat, e0: f32, e1: f32, e2: f32, e3: f32) {
1150 1145
         if let Ok(col) = Colour::from_rgb_hex(hex) {
1151 1146
             assert_colour(col, format, e0, e1, e2, e3);
1152 1147
         } else {

+ 1
- 3
core/src/native.rs View File

@@ -1989,9 +1989,7 @@ fn col_value_execute(vm: &mut Vm) -> Result<Option<Var>> {
1989 1989
 fn col_palette_parameter_info() -> Result<(Vec<(Keyword, Var)>, i32)> {
1990 1990
     Ok((
1991 1991
         // input arguments
1992
-        vec![
1993
-            (Keyword::Index, Var::Float(0.0)),
1994
-        ],
1992
+        vec![(Keyword::Index, Var::Float(0.0))],
1995 1993
         // stack offset
1996 1994
         1,
1997 1995
     ))

+ 9
- 9
utils/palette-maker/src/main.rs View File

@@ -13,6 +13,9 @@
13 13
 // You should have received a copy of the GNU General Public License
14 14
 // along with this program.  If not, see <https://www.gnu.org/licenses/>.
15 15
 
16
+/// read in a json file from https://github.com/Jam3/nice-color-palettes.git
17
+/// and output a rust file which lists the palettes in hsluv colour space
18
+
16 19
 use clap::{App, Arg};
17 20
 use core::colour::{Colour, ColourFormat};
18 21
 use serde_json;
@@ -49,25 +52,22 @@ fn main() -> Result<()> {
49 52
 
50 53
 fn run(json_filename: &str, rs_filename: &str) -> Result<()> {
51 54
     let contents = std::fs::read_to_string(json_filename)?;
52
-
53
-    let rgb_palettes: Vec<Vec<String>> = serde_json::from_str(&contents)?;
54
-    let hsluv_palettes: Vec<Vec<Colour>> = convert_palettes(rgb_palettes)?;
55
-    // println!("{:#?}", hsluv_palettes);
56
-
57
-    let source_code = build_source(&hsluv_palettes)?;
55
+    let json_palettes: Vec<Vec<String>> = serde_json::from_str(&contents)?;
56
+    let converted_palettes: Vec<Vec<Colour>> = convert_palettes(json_palettes)?;
57
+    let source_code = build_source(&converted_palettes)?;
58 58
 
59 59
     std::fs::write(rs_filename, source_code)?;
60 60
 
61 61
     Ok(())
62 62
 }
63 63
 
64
-fn build_source(hsluv_palettes: &Vec<Vec<Colour>>) -> Result<String> {
65
-    let source_size = estimate_output_size(hsluv_palettes.len());
64
+fn build_source(palettes: &Vec<Vec<Colour>>) -> Result<String> {
65
+    let source_size = estimate_output_size(palettes.len());
66 66
     let mut source = String::with_capacity(source_size);
67 67
 
68 68
     source.push_str(get_header());
69 69
 
70
-    for palette in hsluv_palettes {
70
+    for palette in palettes {
71 71
         source.push_str("    &[\n");
72 72
         for colour in palette {
73 73
             source.push_str("        Colour {\n");

Loading…
Cancel
Save