Skip to content

Commit

Permalink
Uncomment the rest of the From impls
Browse files Browse the repository at this point in the history
  • Loading branch information
bschwind committed Dec 26, 2023
1 parent 843d097 commit a3f47fe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 34 deletions.
8 changes: 8 additions & 0 deletions crates/kicad-parser/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ impl GraphicRect {
Ok(line)
}

pub fn start_point(&self) -> (f64, f64) {
self.start
}

pub fn end_point(&self) -> (f64, f64) {
self.end
}

pub fn layer(&self) -> BoardLayer {
BoardLayer::from(self.layer.as_str())
}
Expand Down
58 changes: 24 additions & 34 deletions crates/opencascade/src/kicad.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::{
angle::ToAngle,
primitives::{Edge, EdgeConnection, Wire},
primitives::{Edge, EdgeConnection, Face, Wire},
workplane::Workplane,
Error,
};
use glam::{dvec3, DVec2};
use kicad_parser::{
board::{BoardLayer, KicadBoard},
graphics::{GraphicArc, GraphicLine},
graphics::{GraphicArc, GraphicCircle, GraphicLine, GraphicRect},
};
use std::path::Path;

Expand All @@ -27,25 +28,27 @@ impl From<&GraphicArc> for Edge {
}
}

// impl From<&GraphicCircle> for Face {
// fn from(circle: &GraphicCircle) -> Face {
// let delta_x = (circle.center.0 - circle.end.0).abs();
// let delta_y = (circle.center.1 - circle.end.1).abs();
// let radius = (delta_x * delta_x + delta_y * delta_y).sqrt();
// Workplane::xy()
// .translated(circle.center_point())
// .circle(circle.center.0, circle.center.1, radius)
// .to_face()
// }
// }

// impl From<&GraphicRect> for Face {
// fn from(rect: &GraphicRect) -> Face {
// let height = (rect.end.1 - rect.start.1).abs();
// let width = (rect.end.0 - rect.start.0).abs();
// Workplane::xy().translated(rect.start_point()).rect(height, width).to_face()
// }
// }
impl From<&GraphicCircle> for Face {
fn from(circle: &GraphicCircle) -> Face {
let center = DVec2::from(circle.center_point());
let end = DVec2::from(circle.end_point());

let delta = (center - end).abs();

let radius = (delta.x * delta.x + delta.y * delta.y).sqrt();
Workplane::xy().translated(center.extend(0.0)).circle(center.x, center.y, radius).to_face()
}
}

impl From<&GraphicRect> for Face {
fn from(rect: &GraphicRect) -> Face {
let start = DVec2::from(rect.start_point());
let end = DVec2::from(rect.end_point());

let dimensions = (end - start).abs();
Workplane::xy().translated(start.extend(0.0)).rect(dimensions.x, dimensions.y).to_face()
}
}

pub struct KicadPcb {
board: KicadBoard,
Expand Down Expand Up @@ -106,17 +109,4 @@ impl KicadPcb {
.chain(self.board.arcs().filter(|arc| arc.layer() == *layer).map(Edge::from))
.chain(footprint_edges)
}

// pub fn layer_wire(&self, layer: BoardLayer) -> Wire {
// Wire::from_unordered_edges(&self.layer_edges(layer), EdgeConnection::default())
// }

// pub fn layer_face(&self, layer: BoardLayer) -> Face {
// Face::from_wire(&self.layer_wire(layer))
// }

// pub fn outline(&self, _offset: f64) -> Face {
// // TODO apply offset around the face
// self.layer_face(BoardLayer::EdgeCuts)
// }
}

0 comments on commit a3f47fe

Please sign in to comment.