From 63203ee7172e70631d268bda79cb9b9771dcb481 Mon Sep 17 00:00:00 2001 From: Larsiiii Date: Fri, 16 Aug 2024 19:54:54 +0200 Subject: [PATCH] comments and inflate change --- src/application/canvas/gerbers.rs | 4 +++- src/geometry/gerber.rs | 40 ++++++++++++++++++------------- src/geometry/union.rs | 7 +++--- src/outline_geometry/mod.rs | 2 +- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/application/canvas/gerbers.rs b/src/application/canvas/gerbers.rs index 9ece61d..a73691e 100644 --- a/src/application/canvas/gerbers.rs +++ b/src/application/canvas/gerbers.rs @@ -12,6 +12,7 @@ pub fn draw_gerbers_(ui: &mut PlotUi, app: &mut Application) { for (file_name, (_, geo)) in &app.gerbers { let selected = &app.selection == file_name; + // draw apertures for geometry in geo.apertures.iter() { draw_on_plot_canvas( ui, @@ -20,6 +21,7 @@ pub fn draw_gerbers_(ui: &mut PlotUi, app: &mut Application) { ); } + // draw lines for line in geo.paths.iter() { draw_on_plot_canvas( ui, @@ -28,7 +30,7 @@ pub fn draw_gerbers_(ui: &mut PlotUi, app: &mut Application) { ); } - // draw union path + // draw outline union path for path in geo.outline_union.iter() { let mut points = path .iter() diff --git a/src/geometry/gerber.rs b/src/geometry/gerber.rs index 7b98ff9..a5b815d 100644 --- a/src/geometry/gerber.rs +++ b/src/geometry/gerber.rs @@ -30,6 +30,7 @@ impl From for Geometry { let mut path_container: Vec = Vec::new(); let mut added_apertures: Vec = Vec::new(); + // create geometries by applying all gerber commands for command in gerber.commands { println!("{command:?}"); match command { @@ -39,14 +40,15 @@ impl From for Geometry { match code { DCode::Operation(op) => match op { Operation::Interpolate(coordinates, offset) => { + // create line by interpolating from current position to new position if selected_interpolation_mode == InterpolationMode::Linear { - // self.add_draw_segment(coord); - let point = Point::try_from(&coordinates); + // add current position as starting position if active path is empty (=> start new one) if active_path.is_empty() { active_path.add(current_position); } - match point { + // add point (from gerber coordinates) to active path + match Point::try_from(&coordinates) { Ok(point) => { active_path.add(point); } @@ -56,25 +58,29 @@ impl From for Geometry { // TODO // self.add_arc_segment(coord, offset.as_ref().expect(format!("No offset coord with 'Circular' state\r\n{:#?}", c).as_str())) } + // move current coordinates to new position Self::move_position(&coordinates, &mut current_position); } + // move current coordinates to new position Operation::Move(m) => { - debug!("Move to {:?}, create path.", &m); - // self.create_path_from_data(); + // check if a aperture is selected and if it's circular if let Some(Aperture::Circle(c)) = selected_aperture.as_ref() { + // check if a path is currently active if !active_path.is_empty() { + // finish active path if there is an active one active_path.finalize(c.diameter); path_container.push(active_path); } } + // create new active path and move position tp current position active_path = LinePath::new(); - Geometry::move_position(&m, &mut current_position); + Self::move_position(&m, &mut current_position); } + // add selected Aperture Operation::Flash(f) => { - // self.create_path_from_data(); Self::add_geometry( &mut added_apertures, ¤t_position, @@ -85,8 +91,8 @@ impl From for Geometry { Self::move_position(&f, &mut current_position); } }, + // select an aperture DCode::SelectAperture(ap) => { - // self.create_path_from_data(); selected_aperture = Some( gerber .apertures @@ -121,6 +127,7 @@ impl From for Geometry { } } + // create empty path set let mut result = clipper2::Paths::new(vec![]); // if path_container.len() > 1 { // let mut clipper = path_container[1] @@ -149,15 +156,17 @@ impl From for Geometry { // .unwrap(); // } - let mut geo = Paths::new(vec![]); + // let mut geo = Paths::new(vec![]); + + // union all drawn lines into nets of conductors let conductor_net = union_lines(&path_container); - for outline in &conductor_net { - println!("{:?}", outline.included_points); - geo.push(outline.outline.clone()); - } + // for outline in &conductor_net { + // println!("{:?}", outline.included_points); + // geo.push(outline.outline.clone()); + // } - println!("Number of conductor net paths: {}", geo.len()); + // println!("Number of conductor net paths: {}", geo.len()); if let Some(geo) = union_with_apertures(&added_apertures, conductor_net) { println!("Number of finalized net paths: {}", geo.len()); @@ -175,7 +184,6 @@ impl From for Geometry { impl Geometry { fn move_position(coord: &Coordinates, position: &mut Point) -> () { if let Ok(pos) = Point::try_from(coord) { - debug!("Moved position to {pos:?}"); *position = pos; }; } @@ -201,10 +209,10 @@ impl Geometry { ))); } Aperture::Obround(o) => { - // error!("Unsupported Obround aperture:\r\n{:#?}", o); geometries.push(Element::Obround(Obround::from_aperture_obround(o, target))); } Aperture::Polygon(p) => { + // TODO add polygon error!("Unsupported Polygon aperture:\r\n{:#?}", p); } Aperture::Other(o) => { diff --git a/src/geometry/union.rs b/src/geometry/union.rs index 83be92f..e1feb88 100644 --- a/src/geometry/union.rs +++ b/src/geometry/union.rs @@ -30,7 +30,7 @@ pub fn union_lines(lines: &[LinePath]) -> Vec { // create list of intersecting lines let mut intersections = Vec::new(); let (p1, q1) = (line.points[0], line.points[1]); - println!("LINE 1 {p1:?}, {q1:?}"); + // println!("LINE 1 {p1:?}, {q1:?}"); for (i, l) in lines.iter().enumerate() { if !l.is_empty() { // do not check for intersection with itself @@ -38,13 +38,14 @@ pub fn union_lines(lines: &[LinePath]) -> Vec { // check for all lines in path let intersect = l.points.windows(2).any(|w| { let (p2, q2) = (w[0], w[1]); - println!("LINE 2 {p2:?}, {q2:?}"); + // println!("LINE 2 {p2:?}, {q2:?}"); do_intersect(p1, q1, p2, q2) }); - println!("INTERSECTING: {intersect}"); + // println!("INTERSECTING: {intersect}"); if intersect { // let entry = intersection_map.entry(index).or_insert(Vec::new()); // entry.push(i); + println!("INTERSECTING {:?} and {:?}", line.points, l.points); intersections.push(i); } } diff --git a/src/outline_geometry/mod.rs b/src/outline_geometry/mod.rs index eae6afd..6a0bf63 100644 --- a/src/outline_geometry/mod.rs +++ b/src/outline_geometry/mod.rs @@ -38,7 +38,7 @@ impl OutlineGeometry { // inflate given path let outline = outline .clone() - .inflate((stroke / 2.).into(), JoinType::Round, EndType::Polygon, 2.0) + .inflate((stroke / 2.).into(), JoinType::Miter, EndType::Polygon, 30.) .simplify(0.01, false); Self { // path: outline,