mirror of https://codeberg.org/topola/topola.git
specctra: remove casts, accept floating point precision used internally
This commit is contained in:
parent
f37e7ce88d
commit
13c8237da6
|
|
@ -184,12 +184,12 @@ impl SpecctraDesign {
|
|||
);
|
||||
Self::add_circle(
|
||||
&mut board,
|
||||
(place.x as f64, place.y as f64).into(),
|
||||
place.rotation as f64,
|
||||
(pin.x as f64, pin.y as f64).into(),
|
||||
pin.rotate.unwrap_or(0.0) as f64,
|
||||
circle.diameter as f64 / 2.0,
|
||||
layer as usize,
|
||||
(place.x, place.y).into(),
|
||||
place.rotation,
|
||||
(pin.x, pin.y).into(),
|
||||
pin.rotate.unwrap_or(0.0),
|
||||
circle.diameter / 2.0,
|
||||
layer,
|
||||
*net,
|
||||
Some(pinname.clone()),
|
||||
)
|
||||
|
|
@ -203,15 +203,15 @@ impl SpecctraDesign {
|
|||
);
|
||||
Self::add_rect(
|
||||
&mut board,
|
||||
(place.x as f64, place.y as f64).into(),
|
||||
place.rotation as f64,
|
||||
(pin.x as f64, pin.y as f64).into(),
|
||||
pin.rotate.unwrap_or(0.0) as f64,
|
||||
rect.x1 as f64,
|
||||
rect.y1 as f64,
|
||||
rect.x2 as f64,
|
||||
rect.y2 as f64,
|
||||
layer as usize,
|
||||
(place.x, place.y).into(),
|
||||
place.rotation,
|
||||
(pin.x, pin.y).into(),
|
||||
pin.rotate.unwrap_or(0.0),
|
||||
rect.x1,
|
||||
rect.y1,
|
||||
rect.x2,
|
||||
rect.y2,
|
||||
layer,
|
||||
*net,
|
||||
Some(pinname.clone()),
|
||||
)
|
||||
|
|
@ -225,13 +225,13 @@ impl SpecctraDesign {
|
|||
);
|
||||
Self::add_path(
|
||||
&mut board,
|
||||
(place.x as f64, place.y as f64).into(),
|
||||
place.rotation as f64,
|
||||
(pin.x as f64, pin.y as f64).into(),
|
||||
pin.rotate.unwrap_or(0.0) as f64,
|
||||
(place.x, place.y).into(),
|
||||
place.rotation,
|
||||
(pin.x, pin.y).into(),
|
||||
pin.rotate.unwrap_or(0.0),
|
||||
&path.coords,
|
||||
path.width as f64,
|
||||
layer as usize,
|
||||
path.width,
|
||||
layer,
|
||||
*net,
|
||||
Some(pinname.clone()),
|
||||
)
|
||||
|
|
@ -245,13 +245,13 @@ impl SpecctraDesign {
|
|||
);
|
||||
Self::add_polygon(
|
||||
&mut board,
|
||||
(place.x as f64, place.y as f64).into(),
|
||||
place.rotation as f64,
|
||||
(pin.x as f64, pin.y as f64).into(),
|
||||
pin.rotate.unwrap_or(0.0) as f64,
|
||||
(place.x, place.y).into(),
|
||||
place.rotation,
|
||||
(pin.x, pin.y).into(),
|
||||
pin.rotate.unwrap_or(0.0),
|
||||
&polygon.coords,
|
||||
polygon.width as f64,
|
||||
layer as usize,
|
||||
polygon.width,
|
||||
layer,
|
||||
*net,
|
||||
Some(pinname.clone()),
|
||||
)
|
||||
|
|
@ -294,8 +294,8 @@ impl SpecctraDesign {
|
|||
0.0,
|
||||
(0.0, 0.0).into(),
|
||||
0.0,
|
||||
circle.diameter as f64 / 2.0,
|
||||
layer as usize,
|
||||
circle.diameter / 2.0,
|
||||
layer,
|
||||
net,
|
||||
None,
|
||||
)
|
||||
|
|
@ -309,11 +309,11 @@ impl SpecctraDesign {
|
|||
0.0,
|
||||
(0.0, 0.0).into(),
|
||||
0.0,
|
||||
rect.x1 as f64,
|
||||
rect.y1 as f64,
|
||||
rect.x2 as f64,
|
||||
rect.y2 as f64,
|
||||
layer as usize,
|
||||
rect.x1,
|
||||
rect.y1,
|
||||
rect.x2,
|
||||
rect.y2,
|
||||
layer,
|
||||
net,
|
||||
None,
|
||||
)
|
||||
|
|
@ -328,8 +328,8 @@ impl SpecctraDesign {
|
|||
(0.0, 0.0).into(),
|
||||
0.0,
|
||||
&path.coords,
|
||||
path.width as f64,
|
||||
layer as usize,
|
||||
path.width,
|
||||
layer,
|
||||
net,
|
||||
None,
|
||||
)
|
||||
|
|
@ -348,8 +348,8 @@ impl SpecctraDesign {
|
|||
(0.0, 0.0).into(),
|
||||
0.0,
|
||||
&polygon.coords,
|
||||
polygon.width as f64,
|
||||
layer as usize,
|
||||
polygon.width,
|
||||
layer,
|
||||
net,
|
||||
None,
|
||||
)
|
||||
|
|
@ -379,7 +379,7 @@ impl SpecctraDesign {
|
|||
(0.0, 0.0).into(),
|
||||
0.0,
|
||||
&wire.path.coords,
|
||||
wire.path.width as f64,
|
||||
wire.path.width,
|
||||
layer,
|
||||
net,
|
||||
None,
|
||||
|
|
@ -423,9 +423,9 @@ impl SpecctraDesign {
|
|||
.unwrap();
|
||||
|
||||
if front {
|
||||
image_layer as usize
|
||||
image_layer
|
||||
} else {
|
||||
layers.len() - image_layer as usize - 1
|
||||
layers.len() - image_layer - 1
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -584,8 +584,8 @@ impl SpecctraDesign {
|
|||
place_rot,
|
||||
pin_pos,
|
||||
pin_rot,
|
||||
coords[0].x as f64,
|
||||
coords[0].y as f64,
|
||||
coords[0].x,
|
||||
coords[0].y,
|
||||
);
|
||||
let mut prev_index = board.add_fixed_dot_infringably(
|
||||
FixedDotWeight {
|
||||
|
|
@ -606,8 +606,8 @@ impl SpecctraDesign {
|
|||
place_rot,
|
||||
pin_pos,
|
||||
pin_rot,
|
||||
coord.x as f64,
|
||||
coord.y as f64,
|
||||
coord.x,
|
||||
coord.y,
|
||||
);
|
||||
|
||||
if pos == prev_pos {
|
||||
|
|
@ -673,8 +673,8 @@ impl SpecctraDesign {
|
|||
place_rot,
|
||||
pin_pos,
|
||||
pin_rot,
|
||||
coords[0].x as f64,
|
||||
coords[0].y as f64,
|
||||
coords[0].x,
|
||||
coords[0].y,
|
||||
),
|
||||
r: width / 2.0,
|
||||
},
|
||||
|
|
@ -696,8 +696,8 @@ impl SpecctraDesign {
|
|||
place_rot,
|
||||
pin_pos,
|
||||
pin_rot,
|
||||
coord.x as f64,
|
||||
coord.y as f64,
|
||||
coord.x,
|
||||
coord.y,
|
||||
)
|
||||
.into(),
|
||||
r: width / 2.0,
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ impl<R: std::io::BufRead> ReadDsn<R> for u32 {
|
|||
.map_err(|_| ParseError::Expected("u32"))?)
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: std::io::BufRead> ReadDsn<R> for usize {
|
||||
fn read_dsn(tokenizer: &mut ListTokenizer<R>) -> Result<Self, ParseError> {
|
||||
Ok(tokenizer
|
||||
|
|
@ -89,6 +90,7 @@ impl<R: std::io::BufRead> ReadDsn<R> for usize {
|
|||
.map_err(|_| ParseError::Expected("usize"))?)
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: std::io::BufRead> ReadDsn<R> for f32 {
|
||||
fn read_dsn(tokenizer: &mut ListTokenizer<R>) -> Result<Self, ParseError> {
|
||||
Ok(tokenizer
|
||||
|
|
@ -99,6 +101,16 @@ impl<R: std::io::BufRead> ReadDsn<R> for f32 {
|
|||
}
|
||||
}
|
||||
|
||||
impl<R: std::io::BufRead> ReadDsn<R> for f64 {
|
||||
fn read_dsn(tokenizer: &mut ListTokenizer<R>) -> Result<Self, ParseError> {
|
||||
Ok(tokenizer
|
||||
.consume_token()?
|
||||
.expect_leaf()?
|
||||
.parse()
|
||||
.map_err(|_| ParseError::Expected("f64"))?)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ListTokenizer<R: std::io::BufRead> {
|
||||
reader: R,
|
||||
peeked_char: Option<char>,
|
||||
|
|
|
|||
|
|
@ -141,13 +141,13 @@ pub struct Place {
|
|||
#[anon]
|
||||
pub name: String,
|
||||
#[anon]
|
||||
pub x: f32,
|
||||
pub x: f64,
|
||||
#[anon]
|
||||
pub y: f32,
|
||||
pub y: f64,
|
||||
#[anon]
|
||||
pub side: String,
|
||||
#[anon]
|
||||
pub rotation: f32,
|
||||
pub rotation: f64,
|
||||
pub PN: Option<String>,
|
||||
}
|
||||
|
||||
|
|
@ -180,18 +180,13 @@ pub struct Outline {
|
|||
pub struct Pin {
|
||||
#[anon]
|
||||
pub name: String,
|
||||
pub rotate: Option<f32>,
|
||||
pub rotate: Option<f64>,
|
||||
#[anon]
|
||||
pub id: String,
|
||||
#[anon]
|
||||
pub x: f32,
|
||||
pub x: f64,
|
||||
#[anon]
|
||||
pub y: f32,
|
||||
}
|
||||
|
||||
#[derive(ReadDsn, WriteSes, Debug)]
|
||||
pub struct Rotate {
|
||||
pub angle: f32,
|
||||
pub y: f64,
|
||||
}
|
||||
|
||||
#[derive(ReadDsn, WriteSes, Debug)]
|
||||
|
|
@ -251,7 +246,7 @@ pub struct Circle {
|
|||
#[anon]
|
||||
pub layer: String,
|
||||
#[anon]
|
||||
pub diameter: u32,
|
||||
pub diameter: f64,
|
||||
#[anon]
|
||||
pub offset: Option<Point>,
|
||||
}
|
||||
|
|
@ -318,8 +313,8 @@ pub struct Wire {
|
|||
// (and enforce that such an array actually contains a whole number of points)
|
||||
#[derive(Debug)]
|
||||
pub struct Point {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
pub x: f64,
|
||||
pub y: f64,
|
||||
}
|
||||
|
||||
// Custom impl for the case described above
|
||||
|
|
@ -329,8 +324,8 @@ impl<R: std::io::BufRead> ReadDsn<R> for Vec<Point> {
|
|||
loop {
|
||||
let token = tokenizer.consume_token()?;
|
||||
if let ListToken::Leaf { value: ref x } = token {
|
||||
let x = x.parse::<f32>().unwrap();
|
||||
let y = tokenizer.read_value::<f32>()?;
|
||||
let x = x.parse::<f64>().unwrap();
|
||||
let y = tokenizer.read_value::<f64>()?;
|
||||
array.push(Point { x, y });
|
||||
} else {
|
||||
tokenizer.return_token(token);
|
||||
|
|
@ -345,8 +340,8 @@ impl<R: std::io::BufRead> ReadDsn<R> for Option<Point> {
|
|||
fn read_dsn(tokenizer: &mut ListTokenizer<R>) -> Result<Self, ParseError> {
|
||||
let token = tokenizer.consume_token()?;
|
||||
if let ListToken::Leaf { value: ref x } = token {
|
||||
let x = x.parse::<f32>().unwrap();
|
||||
let y = tokenizer.read_value::<f32>()?;
|
||||
let x = x.parse::<f64>().unwrap();
|
||||
let y = tokenizer.read_value::<f64>()?;
|
||||
Ok(Some(Point { x, y }))
|
||||
} else {
|
||||
tokenizer.return_token(token);
|
||||
|
|
@ -380,7 +375,7 @@ pub struct Polygon {
|
|||
#[anon]
|
||||
pub layer: String,
|
||||
#[anon]
|
||||
pub width: f32,
|
||||
pub width: f64,
|
||||
#[anon]
|
||||
pub coords: Vec<Point>,
|
||||
}
|
||||
|
|
@ -390,7 +385,7 @@ pub struct Path {
|
|||
#[anon]
|
||||
pub layer: String,
|
||||
#[anon]
|
||||
pub width: f32,
|
||||
pub width: f64,
|
||||
#[anon]
|
||||
pub coords: Vec<Point>,
|
||||
}
|
||||
|
|
@ -400,13 +395,13 @@ pub struct Rect {
|
|||
#[anon]
|
||||
pub layer: String,
|
||||
#[anon]
|
||||
pub x1: f32,
|
||||
pub x1: f64,
|
||||
#[anon]
|
||||
pub y1: f32,
|
||||
pub y1: f64,
|
||||
#[anon]
|
||||
pub x2: f32,
|
||||
pub x2: f64,
|
||||
#[anon]
|
||||
pub y2: f32,
|
||||
pub y2: f64,
|
||||
}
|
||||
|
||||
#[derive(ReadDsn, WriteSes, Debug)]
|
||||
|
|
|
|||
|
|
@ -61,6 +61,12 @@ impl<W: io::Write> WriteSes<W> for f32 {
|
|||
}
|
||||
}
|
||||
|
||||
impl<W: io::Write> WriteSes<W> for f64 {
|
||||
fn write_dsn(&self, writer: &mut ListWriter<W>) -> Result<(), io::Error> {
|
||||
writer.write_leaf(self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ListWriter<W: io::Write> {
|
||||
writable: W,
|
||||
indent_level: usize,
|
||||
|
|
|
|||
Loading…
Reference in New Issue