cleanup: cargo fix, cargo fmt

This commit is contained in:
Mikolaj Wielgus 2024-06-13 13:34:16 +02:00
parent 6d66558a72
commit cff6b5aaf6
21 changed files with 170 additions and 191 deletions

View File

@ -1,14 +1,4 @@
use std::{
collections::HashSet,
iter::Peekable,
sync::{Arc, Mutex},
};
use geo::Point;
use petgraph::{
graph::{EdgeIndex, EdgeIndices},
visit::{EdgeRef, IntoEdgeReferences},
};
use petgraph::graph::EdgeIndex;
use spade::InsertionError;
use thiserror::Error;
@ -20,17 +10,9 @@ use crate::{
selection::Selection,
},
board::{mesadata::MesadataTrait, Board},
drawing::{
dot::FixedDotIndex,
graph::{GetLayer, GetMaybeNet},
Infringement,
},
layout::{via::ViaWeight, Layout},
math::Circle,
router::{
navmesh::{Navmesh, NavmeshError},
Router, RouterError, RouterObserverTrait,
},
drawing::{dot::FixedDotIndex, Infringement},
layout::via::ViaWeight,
router::{navmesh::NavmeshError, RouterError, RouterObserverTrait},
triangulation::GetTrianvertexIndex,
};

View File

@ -1,5 +1,3 @@
use geo::Point;
use crate::{
autorouter::{Autorouter, AutorouterError},
board::mesadata::MesadataTrait,

View File

@ -3,7 +3,7 @@ use std::collections::HashMap;
use enum_dispatch::enum_dispatch;
use geo::Point;
use petgraph::{
data::{Element, FromElements},
data::Element,
graph::{EdgeIndex, NodeIndex, UnGraph},
unionfind::UnionFind,
visit::{EdgeRef, IntoEdgeReferences, NodeIndexable},

View File

@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use crate::{
board::{mesadata::MesadataTrait, Board},
drawing::graph::{GetLayer, MakePrimitive, PrimitiveIndex},
drawing::graph::{GetLayer, MakePrimitive},
geometry::compound::CompoundManagerTrait,
graph::{GenericIndex, GetNodeIndex},
layout::{zone::ZoneWeight, CompoundWeight, NodeIndex},

View File

@ -5,9 +5,8 @@ use crate::{
drawing::{
band::BandIndex,
dot::{FixedDotIndex, FixedDotWeight},
graph::{GetLayer, GetMaybeNet, PrimitiveIndex},
graph::{GetLayer, GetMaybeNet},
seg::{FixedSegIndex, FixedSegWeight},
Infringement,
},
geometry::{shape::ShapeTrait, GenericNode},
graph::GenericIndex,

View File

@ -1,4 +1,4 @@
use crate::{drawing::rules::RulesTrait, layout::NodeIndex};
use crate::drawing::rules::RulesTrait;
pub trait MesadataTrait: RulesTrait {
fn bename_layer(&mut self, layer: u64, layername: String);

View File

@ -2,7 +2,7 @@ use contracts::debug_ensures;
use enum_dispatch::enum_dispatch;
use geo::Point;
use rstar::{RTree, RTreeObject, AABB};
use rstar::{RTree, AABB};
use thiserror::Error;
use crate::drawing::{

View File

@ -10,12 +10,8 @@ use crate::{
bend::{BendIndex, FixedBendWeight, LooseBendIndex, LooseBendWeight},
dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
graph::{GetLayer, GetMaybeNet, PrimitiveIndex, PrimitiveWeight, Retag},
loose::LooseIndex,
rules::{Conditions, GetConditions, RulesTrait},
seg::{
FixedSegWeight, LoneLooseSegIndex, LoneLooseSegWeight, SegIndex, SeqLooseSegIndex,
SeqLooseSegWeight,
},
seg::{FixedSegWeight, LoneLooseSegWeight, SegIndex, SeqLooseSegIndex, SeqLooseSegWeight},
Drawing,
},
geometry::GenericNode,

View File

@ -1,8 +1,4 @@
use dsn_derive::ReadDsn;
use super::structure2::*;
use super::read::{ListTokenizer, ReadDsn, ParseError};
use super::write::{ListWriter, WriteDsn};
use super::read::ParseError;
pub enum ListToken {
Start { name: String },
@ -55,4 +51,3 @@ impl ListToken {
}
}
}

View File

@ -1,6 +1,6 @@
use std::collections::HashMap;
use geo::{point, Point, Rotate, Translate};
use geo::{point, Point, Rotate};
use thiserror::Error;
use crate::{
@ -11,8 +11,6 @@ use crate::{
mesadata::DsnMesadata,
structure::{self, DsnFile, Layer, Pcb, Shape},
},
geometry::compound::CompoundManagerTrait,
graph::{GenericIndex, GetNodeIndex},
layout::{zone::SolidZoneWeight, Layout},
math::Circle,
};
@ -32,12 +30,11 @@ pub struct DsnDesign {
impl DsnDesign {
pub fn load_from_file(filename: &str) -> Result<Self, LoadingError> {
let file = std::fs::File::open(filename)?;
let reader = std::io::BufReader::new(file);
let mut list_reader = super::read::ListTokenizer::new(reader);
let mut dsn = list_reader.read_value::<super::structure2::DsnFile>();
let dsn = list_reader.read_value::<super::structure2::DsnFile>();
// TODO: make_board() still uses the old version of structure.rs
// so we can't pass the data to topola for real
@ -62,22 +59,28 @@ impl DsnDesign {
if let Some(net) = net_outs.get_mut(&wire.net) {
net.wire.push(wire);
} else {
net_outs.insert(wire.net.clone(), NetOut {
net_outs.insert(
wire.net.clone(),
NetOut {
name: wire.net.clone(),
wire: vec!(wire),
via: Vec::new()
});
wire: vec![wire],
via: Vec::new(),
},
);
}
}
for via in dsn.pcb.wiring.vias {
if let Some(net) = net_outs.get_mut(&via.net) {
net.via.push(via);
} else {
net_outs.insert(via.net.clone(), NetOut {
net_outs.insert(
via.net.clone(),
NetOut {
name: via.net.clone(),
wire: Vec::new(),
via: vec!(via)
});
via: vec![via],
},
);
}
}
@ -89,7 +92,7 @@ impl DsnDesign {
resolution: Resolution {
unit: "um".into(),
// TODO: why does resolution need to be adjusted from what was imported?
value: 1.0
value: 1.0,
},
library_out: Library {
images: Vec::new(),
@ -98,8 +101,8 @@ impl DsnDesign {
network_out: NetworkOut {
net: net_outs.into_values().collect(),
},
}
}
},
},
};
println!("{:?}", list_writer.write_value(&ses));

View File

@ -1,8 +1,8 @@
mod common;
mod de;
pub mod design;
pub mod mesadata;
mod structure;
mod common;
mod structure2;
mod read;
mod structure;
mod structure2;
mod write;

View File

@ -1,7 +1,7 @@
use thiserror::Error;
use utf8_chars::BufReadCharsExt;
use super::common::ListToken;
use super::structure2::Parser;
use thiserror::Error;
use utf8_chars::BufReadCharsExt;
#[derive(Error, Debug)]
pub enum ParseError {
@ -34,7 +34,6 @@ impl<R: std::io::BufRead> ReadDsn<R> for Parser {
}
}
impl<R: std::io::BufRead> ReadDsn<R> for String {
fn read_dsn(tokenizer: &mut ListTokenizer<R>) -> Result<Self, ParseError> {
Ok(tokenizer.consume_token()?.expect_leaf()?)
@ -236,12 +235,16 @@ impl<R: std::io::BufRead> ListTokenizer<R> {
Ok(if chr == '(' {
self.next_char().unwrap();
self.skip_whitespace()?;
ListToken::Start { name: self.read_string()? }
ListToken::Start {
name: self.read_string()?,
}
} else if chr == ')' {
self.next_char().unwrap();
ListToken::End
} else {
ListToken::Leaf { value: self.read_string()? }
ListToken::Leaf {
value: self.read_string()?,
}
})
}
@ -256,9 +259,15 @@ impl<R: std::io::BufRead> ListTokenizer<R> {
Ok(value)
}
pub fn read_optional<T: ReadDsn<R>>(&mut self, name: &'static str) -> Result<Option<T>, ParseError> {
pub fn read_optional<T: ReadDsn<R>>(
&mut self,
name: &'static str,
) -> Result<Option<T>, ParseError> {
let token = self.consume_token()?;
if let ListToken::Start { name: ref actual_name } = token {
if let ListToken::Start {
name: ref actual_name,
} = token
{
if actual_name == name {
let value = self.read_value::<T>()?;
self.consume_token()?.expect_end()?;
@ -282,31 +291,36 @@ impl<R: std::io::BufRead> ListTokenizer<R> {
array.push(self.read_value::<T>()?);
} else {
self.return_token(token);
break
break;
}
}
Ok(array)
}
pub fn read_named_array<T: ReadDsn<R>>(&mut self, name: &'static str) -> Result<Vec<T>, ParseError> {
pub fn read_named_array<T: ReadDsn<R>>(
&mut self,
name: &'static str,
) -> Result<Vec<T>, ParseError> {
let mut array = Vec::<T>::new();
loop {
let token = self.consume_token()?;
if let ListToken::Start { name: ref actual_name } = token {
if let ListToken::Start {
name: ref actual_name,
} = token
{
if actual_name == name {
let value = self.read_value::<T>()?;
self.consume_token()?.expect_end()?;
array.push(value);
} else {
self.return_token(token);
break
break;
}
} else {
self.return_token(token);
break
break;
}
}
Ok(array)
}
}

View File

@ -1,10 +1,10 @@
use super::common::ListToken;
use super::read::ReadDsn;
use super::read::{ListTokenizer, ParseError};
use super::write::ListWriter;
use super::write::WriteDsn;
use dsn_derive::ReadDsn;
use dsn_derive::WriteDsn;
use super::common::ListToken;
use super::read::{ListTokenizer, ParseError};
use super::write::ListWriter;
#[derive(ReadDsn, WriteDsn, Debug)]
pub struct Dummy {}
@ -16,7 +16,8 @@ pub struct SesFile {
#[derive(ReadDsn, WriteDsn, Debug)]
pub struct Session {
#[anon] pub id: String,
#[anon]
pub id: String,
pub routes: Routes,
}
@ -35,7 +36,8 @@ pub struct NetworkOut {
#[derive(ReadDsn, WriteDsn, Debug)]
pub struct NetOut {
#[anon] pub name: String,
#[anon]
pub name: String,
#[vec("wire")]
pub wire: Vec<Wire>,
#[vec("via")]
@ -49,7 +51,8 @@ pub struct DsnFile {
#[derive(ReadDsn, WriteDsn, Debug)]
pub struct Pcb {
#[anon] pub name: String,
#[anon]
pub name: String,
pub parser: Parser,
pub resolution: Resolution,
pub unit: String,
@ -70,8 +73,10 @@ pub struct Parser {
#[derive(ReadDsn, WriteDsn, Debug)]
pub struct Resolution {
#[anon] pub unit: String,
#[anon] pub value: f32,
#[anon]
pub unit: String,
#[anon]
pub value: f32,
}
#[derive(ReadDsn, WriteDsn, Debug)]
@ -87,7 +92,8 @@ pub struct Structure {
#[derive(ReadDsn, WriteDsn, Debug)]
pub struct Layer {
#[anon] pub name: String,
#[anon]
pub name: String,
pub r#type: String,
pub property: Property,
}
@ -104,7 +110,8 @@ pub struct Boundary {
#[derive(ReadDsn, WriteDsn, Debug)]
pub struct Plane {
#[anon] pub net: String,
#[anon]
pub net: String,
pub polygon: Polygon,
}
@ -122,7 +129,8 @@ pub struct Placement {
#[derive(ReadDsn, WriteDsn, Debug)]
pub struct Component {
#[anon] pub name: String,
#[anon]
pub name: String,
#[vec("place")]
pub places: Vec<Place>,
}
@ -130,11 +138,16 @@ pub struct Component {
#[derive(ReadDsn, WriteDsn, Debug)]
#[allow(non_snake_case)]
pub struct Place {
#[anon] pub name: String,
#[anon] pub x: f32,
#[anon] pub y: f32,
#[anon] pub side: String,
#[anon] pub rotation: f32,
#[anon]
pub name: String,
#[anon]
pub x: f32,
#[anon]
pub y: f32,
#[anon]
pub side: String,
#[anon]
pub rotation: f32,
pub PN: Option<String>,
}
@ -148,7 +161,8 @@ pub struct Library {
#[derive(ReadDsn, WriteDsn, Debug)]
pub struct Image {
#[anon] pub name: String,
#[anon]
pub name: String,
#[vec("outline")]
pub outlines: Vec<Outline>,
#[vec("pin")]
@ -164,11 +178,15 @@ pub struct Outline {
#[derive(ReadDsn, WriteDsn, Debug)]
pub struct Pin {
#[anon] pub name: String,
#[anon]
pub name: String,
pub rotate: Option<f32>,
#[anon] pub id: String,
#[anon] pub x: f32,
#[anon] pub y: f32,
#[anon]
pub id: String,
#[anon]
pub x: f32,
#[anon]
pub y: f32,
}
#[derive(ReadDsn, WriteDsn, Debug)]
@ -178,13 +196,16 @@ pub struct Rotate {
#[derive(ReadDsn, WriteDsn, Debug)]
pub struct Keepout {
#[anon] pub idk: String,
#[anon] pub shape: Shape,
#[anon]
pub idk: String,
#[anon]
pub shape: Shape,
}
#[derive(ReadDsn, WriteDsn, Debug)]
pub struct Padstack {
#[anon] pub name: String,
#[anon]
pub name: String,
#[vec("shape")]
pub shapes: Vec<Shape>,
pub attach: bool,
@ -227,9 +248,12 @@ impl<W: std::io::Write> WriteDsn<W> for Shape {
#[derive(ReadDsn, WriteDsn, Debug)]
pub struct Circle {
#[anon] pub layer: String,
#[anon] pub diameter: u32,
#[anon] pub offset: Option<Point>,
#[anon]
pub layer: String,
#[anon]
pub diameter: u32,
#[anon]
pub offset: Option<Point>,
}
#[derive(ReadDsn, WriteDsn, Debug)]
@ -243,7 +267,8 @@ pub struct Network {
#[derive(ReadDsn, WriteDsn, Debug)]
// dsn names this "net", but it's a structure unrelated to "net" in wiring or elsewhere
pub struct NetPinAssignments {
#[anon] pub name: String,
#[anon]
pub name: String,
pub pins: Pins,
}
@ -309,7 +334,7 @@ impl<R: std::io::BufRead> ReadDsn<R> for Vec<Point> {
array.push(Point { x, y });
} else {
tokenizer.return_token(token);
break
break;
}
}
Ok(array)
@ -352,25 +377,36 @@ impl<W: std::io::Write> WriteDsn<W> for Option<Point> {
#[derive(ReadDsn, WriteDsn, Debug)]
pub struct Polygon {
#[anon] pub layer: String,
#[anon] pub width: f32,
#[anon] pub coords: Vec<Point>,
#[anon]
pub layer: String,
#[anon]
pub width: f32,
#[anon]
pub coords: Vec<Point>,
}
#[derive(ReadDsn, WriteDsn, Debug)]
pub struct Path {
#[anon] pub layer: String,
#[anon] pub width: f32,
#[anon] pub coords: Vec<Point>,
#[anon]
pub layer: String,
#[anon]
pub width: f32,
#[anon]
pub coords: Vec<Point>,
}
#[derive(ReadDsn, WriteDsn, Debug)]
pub struct Rect {
#[anon] pub layer: String,
#[anon] pub x1: f32,
#[anon] pub y1: f32,
#[anon] pub x2: f32,
#[anon] pub y2: f32,
#[anon]
pub layer: String,
#[anon]
pub x1: f32,
#[anon]
pub y1: f32,
#[anon]
pub x2: f32,
#[anon]
pub y2: f32,
}
#[derive(ReadDsn, WriteDsn, Debug)]
@ -394,6 +430,7 @@ pub struct Rule {
#[derive(ReadDsn, WriteDsn, Debug)]
pub struct Clearance {
#[anon] pub value: f32,
#[anon]
pub value: f32,
pub r#type: Option<String>,
}

View File

@ -83,7 +83,8 @@ impl<W: io::Write> ListWriter<W> {
match token {
ListToken::Start { name } => {
write!(self.writable,
write!(
self.writable,
"\n{}({}",
" ".repeat(self.indent_level),
name
@ -101,10 +102,7 @@ impl<W: io::Write> ListWriter<W> {
if self.indent_level <= self.multiline_level {
self.indent_level -= 1;
self.line_len = 2 * self.indent_level + len;
write!(self.writable,
"\n{})",
" ".repeat(self.indent_level)
)
write!(self.writable, "\n{})", " ".repeat(self.indent_level))
} else {
self.indent_level -= 1;
self.line_len += len;
@ -118,10 +116,7 @@ impl<W: io::Write> ListWriter<W> {
self.write_token(ListToken::Leaf { value })
}
pub fn write_value<T: WriteDsn<W>>(
&mut self,
value: &T,
) -> Result<(), io::Error> {
pub fn write_value<T: WriteDsn<W>>(&mut self, value: &T) -> Result<(), io::Error> {
value.write_dsn(self)
}
@ -129,10 +124,10 @@ impl<W: io::Write> ListWriter<W> {
&mut self,
name: &'static str,
value: &T,
)
-> Result<(), io::Error>
{
self.write_token(ListToken::Start { name: name.to_string() } )?;
) -> Result<(), io::Error> {
self.write_token(ListToken::Start {
name: name.to_string(),
})?;
self.write_value(value)?;
self.write_token(ListToken::End)?;
@ -143,9 +138,7 @@ impl<W: io::Write> ListWriter<W> {
&mut self,
name: &'static str,
optional: &Option<T>,
)
-> Result<(), io::Error>
{
) -> Result<(), io::Error> {
if let Some(value) = optional {
self.write_named(name, value)?;
}
@ -153,12 +146,7 @@ impl<W: io::Write> ListWriter<W> {
Ok(())
}
pub fn write_array<T: WriteDsn<W>>(
&mut self,
array: &Vec<T>,
)
-> Result<(), io::Error>
{
pub fn write_array<T: WriteDsn<W>>(&mut self, array: &Vec<T>) -> Result<(), io::Error> {
for elem in array {
self.write_value(elem)?;
}
@ -170,9 +158,7 @@ impl<W: io::Write> ListWriter<W> {
&mut self,
name: &'static str,
array: &Vec<T>,
)
-> Result<(), io::Error>
{
) -> Result<(), io::Error> {
for elem in array {
self.write_named(name, elem)?;
}

View File

@ -5,17 +5,17 @@ use geo::Point;
use petgraph::{
stable_graph::{NodeIndex, StableDiGraph},
visit::EdgeRef,
Direction::{Incoming, Outgoing},
Direction::Incoming,
};
use crate::{
drawing::{
bend::{BendWeight, FixedBendWeight, LooseBendWeight},
dot::{DotWeight, FixedDotWeight, LooseDotWeight},
bend::BendWeight,
dot::DotWeight,
graph::{PrimitiveWeight, Retag},
primitive::Primitive,
rules::RulesTrait,
seg::{FixedSegWeight, LoneLooseSegWeight, SegWeight, SeqLooseSegWeight},
seg::SegWeight,
},
geometry::{
compound::CompoundManagerTrait,

View File

@ -1,4 +1,3 @@
use enum_dispatch::enum_dispatch;
use geo::{Centroid, Contains, Point, Polygon};
use crate::geometry::shape::ShapeTrait;

View File

@ -1,8 +1,5 @@
use std::collections::HashMap;
use enum_dispatch::enum_dispatch;
use geo::Point;
use petgraph::stable_graph::StableDiGraph;
use rstar::AABB;
use crate::{
@ -10,7 +7,7 @@ use crate::{
band::BandIndex,
bend::LooseBendWeight,
dot::{DotIndex, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
graph::{GetLayer, GetMaybeNet, PrimitiveIndex, PrimitiveWeight, Retag},
graph::{GetMaybeNet, PrimitiveIndex},
primitive::{GetJoints, GetOtherJoint},
rules::RulesTrait,
seg::{
@ -21,17 +18,12 @@ use crate::{
wraparoundable::WraparoundableIndex,
Drawing, Infringement, LayoutException,
},
geometry::{
compound::CompoundManagerTrait, poly::PolyShape, primitive::PrimitiveShapeTrait,
shape::ShapeTrait, BendWeightTrait, DotWeightTrait, GenericNode, Geometry, GeometryLabel,
GetWidth, SegWeightTrait,
},
geometry::{compound::CompoundManagerTrait, primitive::PrimitiveShapeTrait, GenericNode},
graph::{GenericIndex, GetNodeIndex},
layout::{
via::{Via, ViaWeight},
zone::{GetMaybeApex, MakePolyShape, Zone, ZoneWeight},
zone::{Zone, ZoneWeight},
},
math::Circle,
};
#[derive(Debug, Clone, Copy)]
@ -207,9 +199,9 @@ impl<R: RulesTrait> Layout<R> {
pub fn band_length(&self, band: BandIndex) -> f64 {
match band {
BandIndex::Straight(seg) => self.drawing.geometry().seg_shape(seg.into()).length(),
BandIndex::Bended(mut start_seg) => {
BandIndex::Bended(start_seg) => {
let mut length = self.drawing.geometry().seg_shape(start_seg.into()).length();
let mut start_dot = self.drawing.primitive(start_seg).joints().1;
let start_dot = self.drawing.primitive(start_seg).joints().1;
let bend = self.drawing.primitive(start_dot).bend();
length += self.drawing.geometry().bend_shape(bend.into()).length();

View File

@ -1,16 +1,14 @@
use enum_dispatch::enum_dispatch;
use geo::{LineString, Point, Polygon};
use petgraph::stable_graph::NodeIndex;
use crate::{
drawing::{
dot::{DotIndex, FixedDotIndex},
graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex, PrimitiveWeight, Retag},
primitive::{GenericPrimitive, GetLimbs, Primitive},
dot::FixedDotIndex,
graph::{GetLayer, GetMaybeNet, MakePrimitive, PrimitiveIndex},
primitive::GetLimbs,
rules::RulesTrait,
seg::SegIndex,
Drawing,
},
geometry::{compound::CompoundManagerTrait, poly::PolyShape, GetPos},
graph::{GenericIndex, GetNodeIndex},

View File

@ -1,9 +1,5 @@
use std::sync::{Arc, Mutex};
use geo::geometry::Point;
use geo::EuclideanDistance;
use petgraph::visit::EdgeRef;
use spade::InsertionError;
use thiserror::Error;
use crate::{
@ -11,7 +7,6 @@ use crate::{
band::BandIndex,
dot::FixedDotIndex,
graph::{MakePrimitive, PrimitiveIndex},
guide::HeadTrait,
primitive::MakePrimitiveShape,
rules::RulesTrait,
},

View File

@ -1,5 +1,3 @@
use std::sync::{Arc, Mutex};
use contracts::debug_ensures;
use crate::{
@ -13,7 +11,7 @@ use crate::{
layout::Layout,
router::{
draw::{Draw, DrawException},
navmesh::{Navmesh, NavvertexIndex},
navmesh::NavvertexIndex,
},
};

View File

@ -1,24 +1,11 @@
use std::fs::File;
use petgraph::{
unionfind::UnionFind,
visit::{EdgeRef, IntoEdgeReferences, NodeIndexable},
};
use topola::{
autorouter::{
invoker::{Command, Invoker, InvokerError},
Autorouter, AutorouterError,
AutorouterError,
},
drawing::{
graph::{GetLayer, GetMaybeNet},
primitive::GetInnerOuter,
},
dsn::design::DsnDesign,
graph::GetNodeIndex,
layout::{via::ViaWeight, NodeIndex},
layout::via::ViaWeight,
math::Circle,
router::EmptyRouterObserver,
triangulation::GetTrianvertexIndex,
};
mod common;