mirror of https://codeberg.org/topola/topola.git
math, spectra: factor out PointWithRotation
This commit is contained in:
parent
2a0b6464ae
commit
dc4ce2fbc7
19
src/math.rs
19
src/math.rs
|
|
@ -20,14 +20,29 @@ pub struct Circle {
|
||||||
pub r: f64,
|
pub r: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
|
pub struct PointWithRotation {
|
||||||
|
pub pos: Point,
|
||||||
|
pub rot: f64,
|
||||||
|
}
|
||||||
|
|
||||||
impl Sub for Circle {
|
impl Sub for Circle {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
fn sub(self, other: Self) -> Self {
|
fn sub(self, other: Self) -> Self {
|
||||||
return Self {
|
Self {
|
||||||
pos: self.pos - other.pos,
|
pos: self.pos - other.pos,
|
||||||
r: self.r,
|
r: self.r,
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for PointWithRotation {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
pos: (0.0, 0.0).into(),
|
||||||
|
rot: 0.0,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
geometry::{primitive::PrimitiveShape, GetWidth},
|
geometry::{primitive::PrimitiveShape, GetWidth},
|
||||||
layout::{poly::SolidPolyWeight, Layout},
|
layout::{poly::SolidPolyWeight, Layout},
|
||||||
math::Circle,
|
math::{Circle, PointWithRotation},
|
||||||
specctra::{
|
specctra::{
|
||||||
mesadata::SpecctraMesadata,
|
mesadata::SpecctraMesadata,
|
||||||
read::{self, ListTokenizer},
|
read::{self, ListTokenizer},
|
||||||
|
|
@ -253,10 +253,8 @@ impl SpecctraDesign {
|
||||||
);
|
);
|
||||||
Self::add_circle(
|
Self::add_circle(
|
||||||
&mut board,
|
&mut board,
|
||||||
(place.x, place.y).into(),
|
place.point_with_rotation(),
|
||||||
place.rotation,
|
pin.point_with_rotation(),
|
||||||
(pin.x, pin.y).into(),
|
|
||||||
pin.rotate.unwrap_or(0.0),
|
|
||||||
circle.diameter / 2.0,
|
circle.diameter / 2.0,
|
||||||
layer,
|
layer,
|
||||||
*net,
|
*net,
|
||||||
|
|
@ -272,10 +270,8 @@ impl SpecctraDesign {
|
||||||
);
|
);
|
||||||
Self::add_rect(
|
Self::add_rect(
|
||||||
&mut board,
|
&mut board,
|
||||||
(place.x, place.y).into(),
|
place.point_with_rotation(),
|
||||||
place.rotation,
|
pin.point_with_rotation(),
|
||||||
(pin.x, pin.y).into(),
|
|
||||||
pin.rotate.unwrap_or(0.0),
|
|
||||||
rect.x1,
|
rect.x1,
|
||||||
rect.y1,
|
rect.y1,
|
||||||
rect.x2,
|
rect.x2,
|
||||||
|
|
@ -294,10 +290,8 @@ impl SpecctraDesign {
|
||||||
);
|
);
|
||||||
Self::add_path(
|
Self::add_path(
|
||||||
&mut board,
|
&mut board,
|
||||||
(place.x, place.y).into(),
|
place.point_with_rotation(),
|
||||||
place.rotation,
|
pin.point_with_rotation(),
|
||||||
(pin.x, pin.y).into(),
|
|
||||||
pin.rotate.unwrap_or(0.0),
|
|
||||||
&path.coords,
|
&path.coords,
|
||||||
path.width,
|
path.width,
|
||||||
layer,
|
layer,
|
||||||
|
|
@ -314,10 +308,8 @@ impl SpecctraDesign {
|
||||||
);
|
);
|
||||||
Self::add_polygon(
|
Self::add_polygon(
|
||||||
&mut board,
|
&mut board,
|
||||||
(place.x, place.y).into(),
|
place.point_with_rotation(),
|
||||||
place.rotation,
|
pin.point_with_rotation(),
|
||||||
(pin.x, pin.y).into(),
|
|
||||||
pin.rotate.unwrap_or(0.0),
|
|
||||||
&polygon.coords,
|
&polygon.coords,
|
||||||
polygon.width,
|
polygon.width,
|
||||||
layer,
|
layer,
|
||||||
|
|
@ -359,10 +351,8 @@ impl SpecctraDesign {
|
||||||
);
|
);
|
||||||
Self::add_circle(
|
Self::add_circle(
|
||||||
&mut board,
|
&mut board,
|
||||||
(0.0, 0.0).into(),
|
PointWithRotation::default(),
|
||||||
0.0,
|
PointWithRotation::default(),
|
||||||
(0.0, 0.0).into(),
|
|
||||||
0.0,
|
|
||||||
circle.diameter / 2.0,
|
circle.diameter / 2.0,
|
||||||
layer,
|
layer,
|
||||||
net,
|
net,
|
||||||
|
|
@ -374,10 +364,8 @@ impl SpecctraDesign {
|
||||||
Self::layer(&mut board, &self.pcb.structure.layers, &rect.layer, true);
|
Self::layer(&mut board, &self.pcb.structure.layers, &rect.layer, true);
|
||||||
Self::add_rect(
|
Self::add_rect(
|
||||||
&mut board,
|
&mut board,
|
||||||
(0.0, 0.0).into(),
|
PointWithRotation::default(),
|
||||||
0.0,
|
PointWithRotation::default(),
|
||||||
(0.0, 0.0).into(),
|
|
||||||
0.0,
|
|
||||||
rect.x1,
|
rect.x1,
|
||||||
rect.y1,
|
rect.y1,
|
||||||
rect.x2,
|
rect.x2,
|
||||||
|
|
@ -392,10 +380,8 @@ impl SpecctraDesign {
|
||||||
Self::layer(&mut board, &self.pcb.structure.layers, &path.layer, true);
|
Self::layer(&mut board, &self.pcb.structure.layers, &path.layer, true);
|
||||||
Self::add_path(
|
Self::add_path(
|
||||||
&mut board,
|
&mut board,
|
||||||
(0.0, 0.0).into(),
|
PointWithRotation::default(),
|
||||||
0.0,
|
PointWithRotation::default(),
|
||||||
(0.0, 0.0).into(),
|
|
||||||
0.0,
|
|
||||||
&path.coords,
|
&path.coords,
|
||||||
path.width,
|
path.width,
|
||||||
layer,
|
layer,
|
||||||
|
|
@ -412,10 +398,8 @@ impl SpecctraDesign {
|
||||||
);
|
);
|
||||||
Self::add_polygon(
|
Self::add_polygon(
|
||||||
&mut board,
|
&mut board,
|
||||||
(0.0, 0.0).into(),
|
PointWithRotation::default(),
|
||||||
0.0,
|
PointWithRotation::default(),
|
||||||
(0.0, 0.0).into(),
|
|
||||||
0.0,
|
|
||||||
&polygon.coords,
|
&polygon.coords,
|
||||||
polygon.width,
|
polygon.width,
|
||||||
layer,
|
layer,
|
||||||
|
|
@ -443,10 +427,8 @@ impl SpecctraDesign {
|
||||||
|
|
||||||
Self::add_path(
|
Self::add_path(
|
||||||
&mut board,
|
&mut board,
|
||||||
(0.0, 0.0).into(),
|
PointWithRotation::default(),
|
||||||
0.0,
|
PointWithRotation::default(),
|
||||||
(0.0, 0.0).into(),
|
|
||||||
0.0,
|
|
||||||
&wire.path.coords,
|
&wire.path.coords,
|
||||||
wire.path.width,
|
wire.path.width,
|
||||||
layer,
|
layer,
|
||||||
|
|
@ -500,17 +482,15 @@ impl SpecctraDesign {
|
||||||
|
|
||||||
fn add_circle(
|
fn add_circle(
|
||||||
board: &mut Board<SpecctraMesadata>,
|
board: &mut Board<SpecctraMesadata>,
|
||||||
place_pos: Point,
|
place: PointWithRotation,
|
||||||
place_rot: f64,
|
pin: PointWithRotation,
|
||||||
pin_pos: Point,
|
|
||||||
pin_rot: f64,
|
|
||||||
r: f64,
|
r: f64,
|
||||||
layer: usize,
|
layer: usize,
|
||||||
net: usize,
|
net: usize,
|
||||||
maybe_pin: Option<String>,
|
maybe_pin: Option<String>,
|
||||||
) {
|
) {
|
||||||
let circle = Circle {
|
let circle = Circle {
|
||||||
pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, 0.0, 0.0),
|
pos: Self::pos(place, pin, 0.0, 0.0),
|
||||||
r,
|
r,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -526,10 +506,8 @@ impl SpecctraDesign {
|
||||||
|
|
||||||
fn add_rect(
|
fn add_rect(
|
||||||
board: &mut Board<SpecctraMesadata>,
|
board: &mut Board<SpecctraMesadata>,
|
||||||
place_pos: Point,
|
place: PointWithRotation,
|
||||||
place_rot: f64,
|
pin: PointWithRotation,
|
||||||
pin_pos: Point,
|
|
||||||
pin_rot: f64,
|
|
||||||
x1: f64,
|
x1: f64,
|
||||||
y1: f64,
|
y1: f64,
|
||||||
x2: f64,
|
x2: f64,
|
||||||
|
|
@ -551,7 +529,7 @@ impl SpecctraDesign {
|
||||||
let dot_1_1 = board.add_poly_fixed_dot_infringably(
|
let dot_1_1 = board.add_poly_fixed_dot_infringably(
|
||||||
FixedDotWeight {
|
FixedDotWeight {
|
||||||
circle: Circle {
|
circle: Circle {
|
||||||
pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x1, y1),
|
pos: Self::pos(place, pin, x1, y1),
|
||||||
r: 0.5,
|
r: 0.5,
|
||||||
},
|
},
|
||||||
layer,
|
layer,
|
||||||
|
|
@ -562,7 +540,7 @@ impl SpecctraDesign {
|
||||||
let dot_2_1 = board.add_poly_fixed_dot_infringably(
|
let dot_2_1 = board.add_poly_fixed_dot_infringably(
|
||||||
FixedDotWeight {
|
FixedDotWeight {
|
||||||
circle: Circle {
|
circle: Circle {
|
||||||
pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x2, y1),
|
pos: Self::pos(place, pin, x2, y1),
|
||||||
r: 0.5,
|
r: 0.5,
|
||||||
},
|
},
|
||||||
layer,
|
layer,
|
||||||
|
|
@ -573,7 +551,7 @@ impl SpecctraDesign {
|
||||||
let dot_2_2 = board.add_poly_fixed_dot_infringably(
|
let dot_2_2 = board.add_poly_fixed_dot_infringably(
|
||||||
FixedDotWeight {
|
FixedDotWeight {
|
||||||
circle: Circle {
|
circle: Circle {
|
||||||
pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x2, y2),
|
pos: Self::pos(place, pin, x2, y2),
|
||||||
r: 0.5,
|
r: 0.5,
|
||||||
},
|
},
|
||||||
layer,
|
layer,
|
||||||
|
|
@ -584,7 +562,7 @@ impl SpecctraDesign {
|
||||||
let dot_1_2 = board.add_poly_fixed_dot_infringably(
|
let dot_1_2 = board.add_poly_fixed_dot_infringably(
|
||||||
FixedDotWeight {
|
FixedDotWeight {
|
||||||
circle: Circle {
|
circle: Circle {
|
||||||
pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x1, y2),
|
pos: Self::pos(place, pin, x1, y2),
|
||||||
r: 0.5,
|
r: 0.5,
|
||||||
},
|
},
|
||||||
layer,
|
layer,
|
||||||
|
|
@ -637,10 +615,8 @@ impl SpecctraDesign {
|
||||||
|
|
||||||
fn add_path(
|
fn add_path(
|
||||||
board: &mut Board<SpecctraMesadata>,
|
board: &mut Board<SpecctraMesadata>,
|
||||||
place_pos: Point,
|
place: PointWithRotation,
|
||||||
place_rot: f64,
|
pin: PointWithRotation,
|
||||||
pin_pos: Point,
|
|
||||||
pin_rot: f64,
|
|
||||||
coords: &Vec<structure::Point>,
|
coords: &Vec<structure::Point>,
|
||||||
width: f64,
|
width: f64,
|
||||||
layer: usize,
|
layer: usize,
|
||||||
|
|
@ -648,14 +624,7 @@ impl SpecctraDesign {
|
||||||
maybe_pin: Option<String>,
|
maybe_pin: Option<String>,
|
||||||
) {
|
) {
|
||||||
// add the first coordinate in the wire path as a dot and save its index
|
// add the first coordinate in the wire path as a dot and save its index
|
||||||
let mut prev_pos = Self::pos(
|
let mut prev_pos = Self::pos(place, pin, coords[0].x, coords[0].y);
|
||||||
place_pos,
|
|
||||||
place_rot,
|
|
||||||
pin_pos,
|
|
||||||
pin_rot,
|
|
||||||
coords[0].x,
|
|
||||||
coords[0].y,
|
|
||||||
);
|
|
||||||
let mut prev_index = board.add_fixed_dot_infringably(
|
let mut prev_index = board.add_fixed_dot_infringably(
|
||||||
FixedDotWeight {
|
FixedDotWeight {
|
||||||
circle: Circle {
|
circle: Circle {
|
||||||
|
|
@ -670,7 +639,7 @@ impl SpecctraDesign {
|
||||||
|
|
||||||
// iterate through path coords starting from the second
|
// iterate through path coords starting from the second
|
||||||
for coord in coords.iter().skip(1) {
|
for coord in coords.iter().skip(1) {
|
||||||
let pos = Self::pos(place_pos, place_rot, pin_pos, pin_rot, coord.x, coord.y);
|
let pos = Self::pos(place, pin, coord.x, coord.y);
|
||||||
|
|
||||||
if pos == prev_pos {
|
if pos == prev_pos {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -707,10 +676,8 @@ impl SpecctraDesign {
|
||||||
|
|
||||||
fn add_polygon(
|
fn add_polygon(
|
||||||
board: &mut Board<SpecctraMesadata>,
|
board: &mut Board<SpecctraMesadata>,
|
||||||
place_pos: Point,
|
place: PointWithRotation,
|
||||||
place_rot: f64,
|
pin: PointWithRotation,
|
||||||
pin_pos: Point,
|
|
||||||
pin_rot: f64,
|
|
||||||
coords: &Vec<structure::Point>,
|
coords: &Vec<structure::Point>,
|
||||||
width: f64,
|
width: f64,
|
||||||
layer: usize,
|
layer: usize,
|
||||||
|
|
@ -730,14 +697,7 @@ impl SpecctraDesign {
|
||||||
let mut prev_index = board.add_poly_fixed_dot_infringably(
|
let mut prev_index = board.add_poly_fixed_dot_infringably(
|
||||||
FixedDotWeight {
|
FixedDotWeight {
|
||||||
circle: Circle {
|
circle: Circle {
|
||||||
pos: Self::pos(
|
pos: Self::pos(place, pin, coords[0].x, coords[0].y),
|
||||||
place_pos,
|
|
||||||
place_rot,
|
|
||||||
pin_pos,
|
|
||||||
pin_rot,
|
|
||||||
coords[0].x,
|
|
||||||
coords[0].y,
|
|
||||||
),
|
|
||||||
r: width / 2.0,
|
r: width / 2.0,
|
||||||
},
|
},
|
||||||
layer,
|
layer,
|
||||||
|
|
@ -753,8 +713,7 @@ impl SpecctraDesign {
|
||||||
let index = board.add_poly_fixed_dot_infringably(
|
let index = board.add_poly_fixed_dot_infringably(
|
||||||
FixedDotWeight {
|
FixedDotWeight {
|
||||||
circle: Circle {
|
circle: Circle {
|
||||||
pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, coord.x, coord.y)
|
pos: Self::pos(place, pin, coord.x, coord.y).into(),
|
||||||
.into(),
|
|
||||||
r: width / 2.0,
|
r: width / 2.0,
|
||||||
},
|
},
|
||||||
layer,
|
layer,
|
||||||
|
|
@ -782,14 +741,12 @@ impl SpecctraDesign {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pos(
|
fn pos(
|
||||||
place_pos: Point,
|
place: PointWithRotation,
|
||||||
place_rot: f64,
|
pin: PointWithRotation,
|
||||||
pin_pos: Point,
|
|
||||||
pin_rot: f64,
|
|
||||||
x: f64,
|
x: f64,
|
||||||
y: f64,
|
y: f64,
|
||||||
) -> Point {
|
) -> Point {
|
||||||
let pos = (point! {x: x, y: y} + pin_pos).rotate_around_point(pin_rot, pin_pos);
|
let pos = (point! {x: x, y: y} + pin.pos).rotate_around_point(pin.rot, pin.pos);
|
||||||
(pos + place_pos).rotate_around_point(place_rot, place_pos)
|
(pos + place.pos).rotate_around_point(place.rot, place.pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ use super::read::ReadDsn;
|
||||||
use super::read::{ListTokenizer, ParseError};
|
use super::read::{ListTokenizer, ParseError};
|
||||||
use super::write::ListWriter;
|
use super::write::ListWriter;
|
||||||
use super::write::WriteSes;
|
use super::write::WriteSes;
|
||||||
|
use crate::math::PointWithRotation;
|
||||||
use specctra_derive::ReadDsn;
|
use specctra_derive::ReadDsn;
|
||||||
use specctra_derive::WriteSes;
|
use specctra_derive::WriteSes;
|
||||||
|
|
||||||
|
|
@ -151,6 +152,15 @@ pub struct Place {
|
||||||
pub PN: Option<String>,
|
pub PN: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Place {
|
||||||
|
pub fn point_with_rotation(&self) -> PointWithRotation {
|
||||||
|
PointWithRotation {
|
||||||
|
pos: (self.x, self.y).into(),
|
||||||
|
rot: self.rotation,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(ReadDsn, WriteSes, Debug)]
|
#[derive(ReadDsn, WriteSes, Debug)]
|
||||||
pub struct Library {
|
pub struct Library {
|
||||||
#[vec("image")]
|
#[vec("image")]
|
||||||
|
|
@ -189,6 +199,15 @@ pub struct Pin {
|
||||||
pub y: f64,
|
pub y: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Pin {
|
||||||
|
pub fn point_with_rotation(&self) -> PointWithRotation {
|
||||||
|
PointWithRotation {
|
||||||
|
pos: (self.x, self.y).into(),
|
||||||
|
rot: self.rotate.unwrap_or(0.0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(ReadDsn, WriteSes, Debug)]
|
#[derive(ReadDsn, WriteSes, Debug)]
|
||||||
pub struct Keepout {
|
pub struct Keepout {
|
||||||
#[anon]
|
#[anon]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue