소스 검색

Fix Y patterning

Kevin Lee 10 달 전
부모
커밋
e43a681102
2개의 변경된 파일82개의 추가작업 그리고 68개의 파일을 삭제
  1. 6 1
      README.md
  2. 76 67
      src/config/object.rs

+ 6 - 1
README.md

@@ -147,7 +147,7 @@ Array:
   Spacing: 1.0
   RandomizeOrder: True
   StartingPen: 1
-  PatternX: <PenPattern>
+  PatternX: <PenPattern> // Optional
   PatternY: <PenPattern> // Optional
 ```
 
@@ -185,3 +185,8 @@ Pattern: !Background # (not supported)
 Pattern: !Fill
 Pattern: !Zigzag
 ```
+
+## Settings
+
+### Stainless Steel (mirror finish)
+

+ 76 - 67
src/config/object.rs

@@ -114,7 +114,7 @@ pub struct ArrayConfig {
     spacing: f64,
     randomize_order: bool,
     starting_pen: usize,
-    pattern_x: PatternField,
+    pattern_x: Option<PatternField>,
     pattern_y: Option<PatternField>,
 }
 
@@ -258,78 +258,87 @@ impl ObjectOperation {
         });
 
         // Process array generation of object
-        let new_objects = self.array.as_ref().map_or(vec![object.clone()], |array| {
-            let mut new_obj: Vec<Object> = vec![];
-
-            let bottom_left: Coordinate = Coordinate {
-                x: (array.columns - 1) as f64 * array.spacing / -2.0,
-                y: (array.rows - 1) as f64 * array.spacing / -2.0,
-            };
-
-            // Generate objects
-            for y in 0..array.rows {
-                for x in 0..array.columns {
-                    let delta: Coordinate = bottom_left
-                        + Coordinate {
-                            x: array.spacing * x as f64,
-                            y: array.spacing * y as f64,
-                        };
-
-                    let pen: usize = array.starting_pen + y * array.columns + x;
-
-                    let mut object: Object = object.clone();
-                    object.move_relative(Some(delta), None);
-                    object.set_pen(pen.try_into().unwrap());
-
-                    debug!(
-                        "Adding new object at {} with pen #{}",
-                        object.core().origin,
-                        pen
-                    );
-                    new_obj.push(object);
+        let new_objects = self.array.as_ref().map_or_else(
+            || vec![object.clone()],
+            |array| {
+                let mut new_obj: Vec<Object> = vec![];
+
+                let bottom_left: Coordinate = Coordinate {
+                    x: (array.columns - 1) as f64 * array.spacing / -2.0,
+                    y: (array.rows - 1) as f64 * array.spacing / -2.0,
+                };
+
+                // Generate objects
+                for y in 0..array.rows {
+                    for x in 0..array.columns {
+                        let delta: Coordinate = bottom_left
+                            + Coordinate {
+                                x: array.spacing * x as f64,
+                                y: array.spacing * y as f64,
+                            };
+
+                        let pen: usize = array.starting_pen + y * array.columns + x;
+
+                        let mut object: Object = object.clone();
+                        object.move_relative(Some(delta), None);
+                        object.set_pen(pen.try_into().unwrap());
+
+                        debug!(
+                            "Adding new object at {} with pen #{}",
+                            object.core().origin,
+                            pen
+                        );
+                        new_obj.push(object);
+                    }
                 }
-            }
 
-            // Generate pens
-            match &array.pattern_y {
-                None => {
-                    array.pattern_x.pattern(
-                        &mut pens
-                            .iter_mut()
-                            .enumerate()
-                            .skip(array.starting_pen)
-                            .take(array.columns * array.rows),
-                    );
-                }
-                Some(pattern_y) => {
-                    pattern_y.pattern(
-                        &mut pens
-                            .iter_mut()
-                            .enumerate()
-                            .skip(array.starting_pen)
-                            .step_by(array.columns)
-                            .take(array.rows),
-                    );
-                    for y in 0..array.rows {
-                        array.pattern_x.pattern(
-                            &mut pens
-                                .iter_mut()
-                                .enumerate()
-                                .skip(array.starting_pen)
-                                .skip(y * array.columns)
-                                .take(array.columns),
-                        )
+                // Generate pens
+                match &array.pattern_y {
+                    None => {
+                        if let Some(pattern_x) = &array.pattern_x {
+                            pattern_x.pattern(
+                                &mut pens
+                                    .iter_mut()
+                                    .enumerate()
+                                    .skip(array.starting_pen)
+                                    .take(array.columns * array.rows),
+                            );
+                        }
+                    }
+                    Some(pattern_y) => {
+                        for x in 0..array.columns {
+                            pattern_y.pattern(
+                                &mut pens
+                                    .iter_mut()
+                                    .enumerate()
+                                    .skip(x + array.starting_pen)
+                                    .step_by(array.columns)
+                                    .take(array.rows),
+                            );
+                        }
+                        if let Some(pattern_x) = &array.pattern_x {
+                            for y in 0..array.rows {
+                                pattern_x.pattern(
+                                    &mut pens
+                                        .iter_mut()
+                                        .enumerate()
+                                        .skip(array.starting_pen)
+                                        .skip(y * array.columns)
+                                        .take(array.columns),
+                                )
+                            }
+                        }
                     }
                 }
-            }
 
-            if array.randomize_order {
-                debug!("Randomizing draw order of array objects");
-                new_obj.shuffle(&mut thread_rng());
-            }
+                if array.randomize_order {
+                    debug!("Randomizing draw order of array objects");
+                    new_obj.shuffle(&mut thread_rng());
+                }
 
-            new_obj
-        });
+                new_obj
+            },
+        );
 
         let layer_id: usize = self.layer.unwrap_or(0);
         let layer: &mut Layer = layers.get_mut(layer_id).expect("Invalid layer index");