mirror of https://codeberg.org/topola/topola.git
chore: trivial fixes of clippy warnings
This commit is contained in:
parent
49d7b3306b
commit
f653a96eb0
|
|
@ -124,13 +124,10 @@ impl<M: AccessMesadata> Autorouter<M> {
|
|||
options: AutorouterOptions,
|
||||
) -> Result<CompareDetoursExecutionStepper, AutorouterError> {
|
||||
let ratlines = self.selected_ratlines(selection);
|
||||
let ratline1 = *ratlines
|
||||
.get(0)
|
||||
.ok_or(AutorouterError::NeedExactlyTwoRatlines)?;
|
||||
let ratline2 = *ratlines
|
||||
.get(1)
|
||||
.ok_or(AutorouterError::NeedExactlyTwoRatlines)?;
|
||||
self.compare_detours_ratlines(ratline1, ratline2, options)
|
||||
if ratlines.len() < 2 {
|
||||
return Err(AutorouterError::NeedExactlyTwoRatlines);
|
||||
}
|
||||
self.compare_detours_ratlines(ratlines[0], ratlines[1], options)
|
||||
}
|
||||
|
||||
pub(super) fn compare_detours_ratlines(
|
||||
|
|
|
|||
|
|
@ -39,47 +39,43 @@ impl ExecutionStepper {
|
|||
&mut self,
|
||||
invoker: &mut Invoker<M>,
|
||||
) -> Result<InvokerStatus, InvokerError> {
|
||||
match self {
|
||||
Ok(match self {
|
||||
ExecutionStepper::Autoroute(autoroute) => {
|
||||
match autoroute.step(&mut invoker.autorouter)? {
|
||||
AutorouteStatus::Running => Ok(InvokerStatus::Running),
|
||||
AutorouteStatus::Routed(..) => Ok(InvokerStatus::Running),
|
||||
AutorouteStatus::Finished => Ok(InvokerStatus::Finished(String::from(
|
||||
"finished autorouting",
|
||||
))),
|
||||
AutorouteStatus::Running => InvokerStatus::Running,
|
||||
AutorouteStatus::Routed(..) => InvokerStatus::Running,
|
||||
AutorouteStatus::Finished => InvokerStatus::Finished(
|
||||
"finished autorouting".to_string(),
|
||||
),
|
||||
}
|
||||
}
|
||||
ExecutionStepper::PlaceVia(place_via) => {
|
||||
place_via.doit(&mut invoker.autorouter)?;
|
||||
Ok(InvokerStatus::Finished(String::from(
|
||||
"finished placing via",
|
||||
)))
|
||||
InvokerStatus::Finished("finished placing via".to_string())
|
||||
}
|
||||
ExecutionStepper::RemoveBands(remove_bands) => {
|
||||
remove_bands.doit(&mut invoker.autorouter)?;
|
||||
Ok(InvokerStatus::Finished(String::from(
|
||||
"finished removing bands",
|
||||
)))
|
||||
InvokerStatus::Finished("finished removing bands".to_string())
|
||||
}
|
||||
ExecutionStepper::CompareDetours(compare_detours) => {
|
||||
match compare_detours.step(&mut invoker.autorouter)? {
|
||||
CompareDetoursStatus::Running => Ok(InvokerStatus::Running),
|
||||
CompareDetoursStatus::Running => InvokerStatus::Running,
|
||||
CompareDetoursStatus::Finished(total_length1, total_length2) => {
|
||||
Ok(InvokerStatus::Finished(String::from(format!(
|
||||
InvokerStatus::Finished(format!(
|
||||
"total detour lengths are {} and {}",
|
||||
total_length1, total_length2
|
||||
))))
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
ExecutionStepper::MeasureLength(measure_length) => {
|
||||
let length = measure_length.doit(&mut invoker.autorouter)?;
|
||||
Ok(InvokerStatus::Finished(format!(
|
||||
InvokerStatus::Finished(format!(
|
||||
"Total length of selected bands: {}",
|
||||
length
|
||||
)))
|
||||
}
|
||||
))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ pub enum HistoryError {
|
|||
NoNextCommand,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
||||
pub struct History {
|
||||
done: Vec<Command>,
|
||||
undone: Vec<Command>,
|
||||
|
|
@ -19,10 +19,7 @@ pub struct History {
|
|||
|
||||
impl History {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
done: vec![],
|
||||
undone: vec![],
|
||||
}
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn destruct(self) -> (Vec<Command>, Vec<Command>) {
|
||||
|
|
|
|||
|
|
@ -84,52 +84,36 @@ impl Ratsnest {
|
|||
};
|
||||
|
||||
let mut triangulations = HashMap::new();
|
||||
let node_bound = layout.drawing().geometry().graph().node_bound();
|
||||
|
||||
for layer in 0..layout.drawing().layer_count() {
|
||||
for node in layout.drawing().layer_primitive_nodes(layer) {
|
||||
match node {
|
||||
PrimitiveIndex::FixedDot(dot) => {
|
||||
if layout.polys(dot).next().is_none() {
|
||||
if let Some(net) = layout.drawing().primitive(dot).maybe_net() {
|
||||
if !triangulations.contains_key(&(layer, net)) {
|
||||
triangulations.insert(
|
||||
(layer, net),
|
||||
Triangulation::new(
|
||||
layout.drawing().geometry().graph().node_bound(),
|
||||
),
|
||||
);
|
||||
let mut handle_rvw = |maybe_net: Option<usize>, vertex: RatvertexIndex, pos: Point| {
|
||||
if let Some(net) = maybe_net {
|
||||
triangulations.entry((layer, net))
|
||||
.or_insert_with(|| Triangulation::new(node_bound))
|
||||
.add_vertex(RatvertexWeight { vertex, pos })?;
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
|
||||
triangulations.get_mut(&(layer, net)).unwrap().add_vertex(
|
||||
RatvertexWeight {
|
||||
vertex: RatvertexIndex::FixedDot(dot),
|
||||
pos: node.primitive(layout.drawing()).shape().center(),
|
||||
},
|
||||
for node in layout.drawing().layer_primitive_nodes(layer) {
|
||||
if let PrimitiveIndex::FixedDot(dot) = node {
|
||||
if layout.polys(dot).next().is_none() {
|
||||
handle_rvw(
|
||||
layout.drawing().primitive(dot).maybe_net(),
|
||||
RatvertexIndex::FixedDot(dot),
|
||||
node.primitive(layout.drawing()).shape().center(),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
for poly in layout.layer_poly_nodes(layer) {
|
||||
if let Some(net) = layout.drawing().compound_weight(poly.into()).maybe_net() {
|
||||
if !triangulations.contains_key(&(layer, net)) {
|
||||
triangulations.insert(
|
||||
(layer, net),
|
||||
Triangulation::new(layout.drawing().geometry().graph().node_bound()),
|
||||
);
|
||||
}
|
||||
|
||||
triangulations
|
||||
.get_mut(&(layer, net))
|
||||
.unwrap()
|
||||
.add_vertex(RatvertexWeight {
|
||||
vertex: RatvertexIndex::Poly(poly),
|
||||
pos: layout.poly(poly).shape().center(),
|
||||
})?
|
||||
}
|
||||
handle_rvw(
|
||||
layout.drawing().compound_weight(poly.into()).maybe_net(),
|
||||
RatvertexIndex::Poly(poly),
|
||||
layout.poly(poly).shape().center(),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,16 +16,14 @@ pub struct PinSelector {
|
|||
pub layer: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
||||
pub struct PinSelection {
|
||||
selectors: HashSet<PinSelector>,
|
||||
}
|
||||
|
||||
impl PinSelection {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
selectors: HashSet::new(),
|
||||
}
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn new_select_layer(board: &Board<impl AccessMesadata>, layer: usize) -> Self {
|
||||
|
|
@ -100,16 +98,14 @@ pub struct BandSelector {
|
|||
pub band: BandName,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
||||
pub struct BandSelection {
|
||||
selectors: HashSet<BandSelector>,
|
||||
}
|
||||
|
||||
impl BandSelection {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
selectors: HashSet::new(),
|
||||
}
|
||||
Self::default()
|
||||
}
|
||||
|
||||
fn node_selector(
|
||||
|
|
@ -141,7 +137,7 @@ impl BandSelection {
|
|||
}
|
||||
|
||||
fn deselect(&mut self, selector: &BandSelector) {
|
||||
self.selectors.remove(&selector);
|
||||
self.selectors.remove(selector);
|
||||
}
|
||||
|
||||
pub fn contains_node(&self, board: &Board<impl AccessMesadata>, node: NodeIndex) -> bool {
|
||||
|
|
@ -154,7 +150,7 @@ impl BandSelection {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
||||
pub struct Selection {
|
||||
pub pin_selection: PinSelection,
|
||||
pub band_selection: BandSelection,
|
||||
|
|
@ -162,10 +158,7 @@ pub struct Selection {
|
|||
|
||||
impl Selection {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
pin_selection: PinSelection::new(),
|
||||
band_selection: BandSelection::new(),
|
||||
}
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn toggle_at_node(&mut self, board: &Board<impl AccessMesadata>, node: NodeIndex) {
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ impl<'a, CW: Copy, R: AccessRules> Collect<'a, CW, R> {
|
|||
let mut gear = bend;
|
||||
|
||||
while let Some(outer) = self.drawing.primitive(gear).outer() {
|
||||
v.append(&mut self.bend_bow(outer.into()));
|
||||
v.append(&mut self.bend_bow(outer));
|
||||
gear = outer;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -357,7 +357,7 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
|||
GeometryLabel::Core
|
||||
)
|
||||
})
|
||||
.map(|ni| FixedDotIndex::new(ni))
|
||||
.map(FixedDotIndex::new)
|
||||
.collect::<Vec<FixedDotIndex>>()
|
||||
.first()
|
||||
.unwrap();
|
||||
|
|
@ -418,7 +418,7 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
|||
if let Some(outer) = self.primitive(cane.bend).outer() {
|
||||
self.update_this_and_outward_bows(outer).map_err(|err| {
|
||||
let joint = self.primitive(cane.bend).other_joint(cane.dot);
|
||||
self.remove_cane(&cane, joint.into());
|
||||
self.remove_cane(&cane, joint);
|
||||
err
|
||||
})?;
|
||||
}
|
||||
|
|
@ -426,12 +426,12 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
|||
// Segs must not cross.
|
||||
if let Some(collision) = self.detect_collision(cane.seg.into()) {
|
||||
let joint = self.primitive(cane.bend).other_joint(cane.dot);
|
||||
self.remove_cane(&cane, joint.into());
|
||||
return Err(collision.into());
|
||||
}
|
||||
|
||||
self.remove_cane(&cane, joint);
|
||||
Err(collision.into())
|
||||
} else {
|
||||
Ok(cane)
|
||||
}
|
||||
}
|
||||
|
||||
#[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))]
|
||||
#[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
|
||||
|
|
@ -453,7 +453,7 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
|||
if let Some(inner) = rail_primitive.inner() {
|
||||
let from = guide
|
||||
.head_around_bend_segment(
|
||||
&from_head.into(),
|
||||
&from_head,
|
||||
inner.into(),
|
||||
true,
|
||||
self.primitive(rail).width(),
|
||||
|
|
@ -461,14 +461,14 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
|||
.end_point();
|
||||
let to = guide
|
||||
.head_around_bend_segment(
|
||||
&to_head.into(),
|
||||
&to_head,
|
||||
inner.into(),
|
||||
false,
|
||||
self.primitive(rail).width(),
|
||||
)?
|
||||
.end_point();
|
||||
let offset = guide.head_around_bend_offset(
|
||||
&from_head.into(),
|
||||
&from_head,
|
||||
inner.into(),
|
||||
self.primitive(rail).width(),
|
||||
);
|
||||
|
|
@ -495,7 +495,7 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
|||
let core = rail_primitive.core();
|
||||
let from = guide
|
||||
.head_around_dot_segment(
|
||||
&from_head.into(),
|
||||
&from_head,
|
||||
core.into(),
|
||||
true,
|
||||
self.primitive(rail).width(),
|
||||
|
|
@ -503,14 +503,14 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
|||
.end_point();
|
||||
let to = guide
|
||||
.head_around_dot_segment(
|
||||
&to_head.into(),
|
||||
&to_head,
|
||||
core.into(),
|
||||
false,
|
||||
self.primitive(rail).width(),
|
||||
)?
|
||||
.end_point();
|
||||
let offset = guide.head_around_dot_offset(
|
||||
&from_head.into(),
|
||||
&from_head,
|
||||
core.into(),
|
||||
self.primitive(rail).width(),
|
||||
);
|
||||
|
|
@ -659,7 +659,7 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
|||
self.geometry_with_rtree.move_dot(dot, to);
|
||||
|
||||
for limb in dot.primitive(self).limbs() {
|
||||
if let Some(infringement) = self.detect_infringement_except(limb.into(), infringables) {
|
||||
if let Some(infringement) = self.detect_infringement_except(limb, infringables) {
|
||||
// Restore original state.
|
||||
self.geometry_with_rtree.move_dot(dot, old_pos);
|
||||
return Err(infringement);
|
||||
|
|
@ -713,10 +713,8 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
|||
}
|
||||
})
|
||||
.filter(|primitive_node| !self.are_connectable(node, *primitive_node))
|
||||
.filter(|primitive_node| shape.intersects(&primitive_node.primitive(self).shape()))
|
||||
.map(|primitive_node| primitive_node)
|
||||
.next()
|
||||
.and_then(|collidee| Some(Collision(shape, collidee)))
|
||||
.find(|primitive_node| shape.intersects(&primitive_node.primitive(self).shape()))
|
||||
.map(|collidee| Collision(shape, collidee))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -784,7 +782,7 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
|||
}
|
||||
})
|
||||
.filter(|primitive_node| {
|
||||
maybe_except.is_some_and(|except| !except.contains(&primitive_node))
|
||||
maybe_except.is_some_and(|except| !except.contains(primitive_node))
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
|
@ -796,7 +794,7 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
|||
let limiting_shape = node.primitive(self).shape().inflate(
|
||||
node.primitive(self)
|
||||
.maybe_net()
|
||||
.and_then(|net| Some(self.rules.largest_clearance(Some(net))))
|
||||
.map(|net| self.rules.largest_clearance(Some(net)))
|
||||
.unwrap_or(0.0),
|
||||
);
|
||||
|
||||
|
|
@ -929,13 +927,12 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
|||
fn test_if_looses_dont_infringe_each_other(&self) -> bool {
|
||||
!self
|
||||
.primitive_nodes()
|
||||
.filter(|node| match node {
|
||||
.filter(|node| matches!(node,
|
||||
PrimitiveIndex::LooseDot(..)
|
||||
| PrimitiveIndex::LoneLooseSeg(..)
|
||||
| PrimitiveIndex::SeqLooseSeg(..)
|
||||
| PrimitiveIndex::LooseBend(..) => true,
|
||||
_ => false,
|
||||
})
|
||||
| PrimitiveIndex::LooseBend(..)
|
||||
))
|
||||
.any(|node| {
|
||||
self.find_infringement(
|
||||
node,
|
||||
|
|
@ -947,13 +944,12 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
|||
None
|
||||
}
|
||||
})
|
||||
.filter(|primitive_node| match primitive_node {
|
||||
.filter(|primitive_node| matches!(primitive_node,
|
||||
PrimitiveIndex::LooseDot(..)
|
||||
| PrimitiveIndex::LoneLooseSeg(..)
|
||||
| PrimitiveIndex::SeqLooseSeg(..)
|
||||
| PrimitiveIndex::LooseBend(..) => true,
|
||||
_ => false,
|
||||
}),
|
||||
| PrimitiveIndex::LooseBend(..)
|
||||
)),
|
||||
)
|
||||
.is_some()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ impl<'a, W, CW: Copy, R: AccessRules> GenericPrimitive<'a, W, CW, R> {
|
|||
}
|
||||
|
||||
fn primitive<WW>(&self, index: GenericIndex<WW>) -> GenericPrimitive<WW, CW, R> {
|
||||
GenericPrimitive::new(index, &self.drawing)
|
||||
GenericPrimitive::new(index, self.drawing)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -379,7 +379,7 @@ impl<'a, CW: Copy, R: AccessRules> GetJoints<DotIndex, LooseDotIndex> for SeqLoo
|
|||
if let DotWeight::Fixed(..) = self.drawing.geometry().dot_weight(joints.0) {
|
||||
(
|
||||
FixedDotIndex::new(joints.0.petgraph_index()).into(),
|
||||
LooseDotIndex::new(joints.1.petgraph_index()).into(),
|
||||
LooseDotIndex::new(joints.1.petgraph_index()),
|
||||
)
|
||||
} else if let DotWeight::Fixed(..) = self.drawing.geometry().dot_weight(joints.1) {
|
||||
(
|
||||
|
|
@ -389,7 +389,7 @@ impl<'a, CW: Copy, R: AccessRules> GetJoints<DotIndex, LooseDotIndex> for SeqLoo
|
|||
} else {
|
||||
(
|
||||
LooseDotIndex::new(joints.0.petgraph_index()).into(),
|
||||
LooseDotIndex::new(joints.1.petgraph_index()).into(),
|
||||
LooseDotIndex::new(joints.1.petgraph_index()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -221,8 +221,7 @@ impl<
|
|||
if let Some(old_inner_edge) = self
|
||||
.graph
|
||||
.edges_directed(bend.petgraph_index(), Incoming)
|
||||
.filter(|edge| *edge.weight() == GeometryLabel::Outer)
|
||||
.next()
|
||||
.find(|edge| *edge.weight() == GeometryLabel::Outer)
|
||||
{
|
||||
self.graph.remove_edge(old_inner_edge.id());
|
||||
}
|
||||
|
|
@ -274,10 +273,7 @@ impl<
|
|||
let mut rail = bend;
|
||||
|
||||
while let Some(inner) = self.inner(rail) {
|
||||
let weight: BW = self
|
||||
.bend_weight(inner)
|
||||
.try_into()
|
||||
.unwrap_or_else(|_| unreachable!());
|
||||
let weight: BW = self.bend_weight(inner);
|
||||
r += weight.width() + weight.offset();
|
||||
rail = inner;
|
||||
}
|
||||
|
|
@ -441,8 +437,6 @@ impl<
|
|||
.map(|ni| {
|
||||
self.primitive_weight(ni)
|
||||
.retag(ni)
|
||||
.try_into()
|
||||
.unwrap_or_else(|_| unreachable!())
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -485,12 +479,7 @@ impl<
|
|||
GeometryLabel::Compound
|
||||
)
|
||||
})
|
||||
.map(|ni| {
|
||||
self.primitive_weight(ni)
|
||||
.retag(ni)
|
||||
.try_into()
|
||||
.unwrap_or_else(|_| unreachable!())
|
||||
})
|
||||
.map(|ni| self.primitive_weight(ni).retag(ni))
|
||||
}
|
||||
|
||||
pub fn graph(&self) -> &StableDiGraph<GenericNode<PW, CW>, GeometryLabel, usize> {
|
||||
|
|
|
|||
|
|
@ -37,13 +37,12 @@ impl<'a, R: AccessRules> Poly<'a, R> {
|
|||
}
|
||||
|
||||
fn is_apex(&self, dot: FixedDotIndex) -> bool {
|
||||
self.layout
|
||||
!self.layout
|
||||
.drawing()
|
||||
.primitive(dot)
|
||||
.segs()
|
||||
.iter()
|
||||
.find(|seg| matches!(seg, SegIndex::Fixed(..)))
|
||||
.is_none()
|
||||
.any(|seg| matches!(seg, SegIndex::Fixed(..)))
|
||||
&& self.layout.drawing().primitive(dot).bends().is_empty()
|
||||
}
|
||||
}
|
||||
|
|
@ -84,7 +83,7 @@ impl<'a, R: AccessRules> MakePolyShape for Poly<'a, R> {
|
|||
};
|
||||
|
||||
if self.is_apex(dot) {
|
||||
return None;
|
||||
None
|
||||
} else {
|
||||
Some(
|
||||
self.layout
|
||||
|
|
@ -164,13 +163,13 @@ pub struct PourPolyWeight {
|
|||
pub maybe_net: Option<usize>,
|
||||
}
|
||||
|
||||
impl<'a> GetLayer for PourPolyWeight {
|
||||
impl GetLayer for PourPolyWeight {
|
||||
fn layer(&self) -> usize {
|
||||
self.layer
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetMaybeNet for PourPolyWeight {
|
||||
impl GetMaybeNet for PourPolyWeight {
|
||||
fn maybe_net(&self) -> Option<usize> {
|
||||
self.maybe_net
|
||||
}
|
||||
|
|
|
|||
18
src/math.rs
18
src/math.rs
|
|
@ -81,13 +81,12 @@ fn _tangents(circle1: Circle, circle2: Circle) -> Result<[CanonicalLine; 4], ()>
|
|||
}
|
||||
|
||||
fn cast_point_to_canonical_line(pt: Point, line: CanonicalLine) -> Point {
|
||||
return (
|
||||
(
|
||||
(line.b * (line.b * pt.x() - line.a * pt.y()) - line.a * line.c)
|
||||
/ (line.a * line.a + line.b * line.b),
|
||||
(line.a * (-line.b * pt.x() + line.a * pt.y()) - line.b * line.c)
|
||||
/ (line.a * line.a + line.b * line.b),
|
||||
)
|
||||
.into();
|
||||
).into()
|
||||
}
|
||||
|
||||
fn tangent_point_pairs(
|
||||
|
|
@ -193,6 +192,7 @@ pub fn intersect_circle_segment(circle: &Circle, segment: &Line) -> Vec<Point> {
|
|||
let from = segment.start_point();
|
||||
let to = segment.end_point();
|
||||
let epsilon = 1e-9;
|
||||
let interval01 = 0.0..=1.0;
|
||||
|
||||
let a = delta.dot(delta);
|
||||
let b =
|
||||
|
|
@ -209,24 +209,24 @@ pub fn intersect_circle_segment(circle: &Circle, segment: &Line) -> Vec<Point> {
|
|||
if discriminant == 0.0 {
|
||||
let u = -b / (2.0 * a);
|
||||
|
||||
if u >= 0.0 && u <= 1.0 {
|
||||
return [from + (to - from) * -b / (2.0 * a)].into();
|
||||
return if interval01.contains(&u) {
|
||||
vec![from + (to - from) * -b / (2.0 * a)]
|
||||
} else {
|
||||
return [].into();
|
||||
}
|
||||
vec![]
|
||||
};
|
||||
}
|
||||
|
||||
let mut v = vec![];
|
||||
|
||||
let u1 = (-b + discriminant.sqrt()) / (2.0 * a);
|
||||
|
||||
if u1 >= 0.0 && u1 <= 1.0 {
|
||||
if interval01.contains(&u1) {
|
||||
v.push(from + (to - from) * u1);
|
||||
}
|
||||
|
||||
let u2 = (-b - discriminant.sqrt()) / (2.0 * a);
|
||||
|
||||
if u2 >= 0.0 && u2 <= 1.0 {
|
||||
if interval01.contains(&u2) {
|
||||
v.push(from + (to - from) * u2);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ where
|
|||
graph: &'a G,
|
||||
edge: <&'a G as IntoEdgeReferences>::EdgeRef,
|
||||
) -> Option<K>;
|
||||
fn remove_probe<'a>(&mut self, graph: &'a G);
|
||||
fn remove_probe(&mut self, graph: &G);
|
||||
fn estimate_cost(&mut self, graph: &G, node: G::NodeId) -> K;
|
||||
}
|
||||
|
||||
|
|
@ -198,7 +198,7 @@ where
|
|||
let zero_score = K::default();
|
||||
this.scores.insert(start, zero_score);
|
||||
this.visit_next.push(MinScored(
|
||||
strategy.estimate_cost(&&this.graph, start),
|
||||
strategy.estimate_cost(&this.graph, start),
|
||||
start,
|
||||
));
|
||||
this
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ impl<'a, R: AccessRules> Draw<'a, R> {
|
|||
self.layout
|
||||
.add_lone_loose_seg(
|
||||
dot,
|
||||
into.into(),
|
||||
into,
|
||||
LoneLooseSegWeight {
|
||||
width,
|
||||
layer,
|
||||
|
|
@ -130,10 +130,10 @@ impl<'a, R: AccessRules> Draw<'a, R> {
|
|||
) -> Result<CaneHead, DrawException> {
|
||||
let tangent = self
|
||||
.guide()
|
||||
.head_around_bend_segment(&head, around.into(), cw, width)?;
|
||||
.head_around_bend_segment(&head, around, cw, width)?;
|
||||
let offset = self
|
||||
.guide()
|
||||
.head_around_bend_offset(&head, around.into(), width);
|
||||
.head_around_bend_offset(&head, around, width);
|
||||
|
||||
self.cane_around(
|
||||
head,
|
||||
|
|
|
|||
|
|
@ -367,7 +367,7 @@ impl<'a> IntoNeighbors for &'a Navmesh {
|
|||
Box::new(
|
||||
self.graph
|
||||
.neighbors(vertex.petgraph_index())
|
||||
.map(|ni| NavvertexIndex(ni)),
|
||||
.map(NavvertexIndex),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,11 +109,11 @@ impl<'a, R: AccessRules> AstarStrategy<Navmesh, f64, BandTermsegIndex>
|
|||
let width = self.trace.width;
|
||||
|
||||
self.tracer
|
||||
.rework_path(navmesh, &mut self.trace, &new_path[..], width)
|
||||
.rework_path(navmesh, self.trace, &new_path[..], width)
|
||||
.unwrap();
|
||||
|
||||
self.tracer
|
||||
.finish(navmesh, &mut self.trace, self.target, width)
|
||||
.finish(navmesh, self.trace, self.target, width)
|
||||
.ok()
|
||||
}
|
||||
|
||||
|
|
@ -205,11 +205,11 @@ impl<'a, R: AccessRules> Router<'a, R> {
|
|||
}
|
||||
|
||||
pub fn layout_mut(&mut self) -> &mut Layout<R> {
|
||||
&mut self.layout
|
||||
self.layout
|
||||
}
|
||||
|
||||
pub fn layout(&self) -> &Layout<R> {
|
||||
&self.layout
|
||||
self.layout
|
||||
}
|
||||
|
||||
pub fn options(&self) -> RouterOptions {
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ impl TraceStepper {
|
|||
cw: bool,
|
||||
width: f64,
|
||||
) -> Result<CaneHead, TracerException> {
|
||||
Ok(Draw::new(tracer.layout).cane_around_dot(head, around.into(), cw, width)?)
|
||||
Ok(Draw::new(tracer.layout).cane_around_dot(head, around, cw, width)?)
|
||||
}
|
||||
|
||||
fn wrap_around_loose_bend(
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ impl<'a, R: AccessRules> Tracer<'a, R> {
|
|||
width,
|
||||
}) {
|
||||
self.undo_path(trace, i);
|
||||
return Err(err.into());
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -193,12 +193,12 @@ impl SpecctraDesign {
|
|||
)));
|
||||
|
||||
// mapping of pin -> net prepared for adding pins
|
||||
let pin_nets = HashMap::<String, usize>::from_iter(
|
||||
self.pcb
|
||||
let pin_nets = self.pcb
|
||||
.network
|
||||
.nets
|
||||
.iter()
|
||||
.map(|net_pin_assignments| {
|
||||
// flatten the nested iters into a single stream of tuples
|
||||
.flat_map(|net_pin_assignments| {
|
||||
// resolve the id so we don't work with strings
|
||||
let net = board
|
||||
.layout()
|
||||
|
|
@ -215,9 +215,7 @@ impl SpecctraDesign {
|
|||
.iter()
|
||||
.map(move |pinname| (pinname.clone(), net))
|
||||
})
|
||||
// flatten the nested iters into a single stream of tuples
|
||||
.flatten(),
|
||||
);
|
||||
.collect::<HashMap<String, usize>>();
|
||||
|
||||
// add pins from components
|
||||
for component in &self.pcb.placement.components {
|
||||
|
|
@ -416,7 +414,7 @@ impl SpecctraDesign {
|
|||
|
||||
fn layer(
|
||||
board: &Board<SpecctraMesadata>,
|
||||
layers: &Vec<Layer>,
|
||||
layers: &[Layer],
|
||||
layername: &str,
|
||||
front: bool,
|
||||
) -> usize {
|
||||
|
|
@ -571,7 +569,7 @@ impl SpecctraDesign {
|
|||
board: &mut Board<SpecctraMesadata>,
|
||||
place: PointWithRotation,
|
||||
pin: PointWithRotation,
|
||||
coords: &Vec<structure::Point>,
|
||||
coords: &[structure::Point],
|
||||
width: f64,
|
||||
layer: usize,
|
||||
net: usize,
|
||||
|
|
@ -632,7 +630,7 @@ impl SpecctraDesign {
|
|||
board: &mut Board<SpecctraMesadata>,
|
||||
place: PointWithRotation,
|
||||
pin: PointWithRotation,
|
||||
coords: &Vec<structure::Point>,
|
||||
coords: &[structure::Point],
|
||||
width: f64,
|
||||
layer: usize,
|
||||
net: usize,
|
||||
|
|
@ -667,7 +665,7 @@ impl SpecctraDesign {
|
|||
let index = board.add_poly_fixed_dot_infringably(
|
||||
FixedDotWeight {
|
||||
circle: Circle {
|
||||
pos: Self::pos(place, pin, coord.x, coord.y).into(),
|
||||
pos: Self::pos(place, pin, coord.x, coord.y),
|
||||
r: width / 2.0,
|
||||
},
|
||||
layer,
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ 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, ParseErrorContext> {
|
||||
Ok(tokenizer.consume_token()?.expect_leaf()?)
|
||||
tokenizer.consume_token()?.expect_leaf()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -109,51 +109,51 @@ impl<R: std::io::BufRead> ReadDsn<R> for bool {
|
|||
|
||||
impl<R: std::io::BufRead> ReadDsn<R> for i32 {
|
||||
fn read_dsn(tokenizer: &mut ListTokenizer<R>) -> Result<Self, ParseErrorContext> {
|
||||
Ok(tokenizer
|
||||
tokenizer
|
||||
.consume_token()?
|
||||
.expect_leaf()?
|
||||
.parse()
|
||||
.map_err(|_| tokenizer.add_context(ParseError::Expected("i32")))?)
|
||||
.map_err(|_| tokenizer.add_context(ParseError::Expected("i32")))
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: std::io::BufRead> ReadDsn<R> for u32 {
|
||||
fn read_dsn(tokenizer: &mut ListTokenizer<R>) -> Result<Self, ParseErrorContext> {
|
||||
Ok(tokenizer
|
||||
tokenizer
|
||||
.consume_token()?
|
||||
.expect_leaf()?
|
||||
.parse()
|
||||
.map_err(|_| tokenizer.add_context(ParseError::Expected("u32")))?)
|
||||
.map_err(|_| tokenizer.add_context(ParseError::Expected("u32")))
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: std::io::BufRead> ReadDsn<R> for usize {
|
||||
fn read_dsn(tokenizer: &mut ListTokenizer<R>) -> Result<Self, ParseErrorContext> {
|
||||
Ok(tokenizer
|
||||
tokenizer
|
||||
.consume_token()?
|
||||
.expect_leaf()?
|
||||
.parse()
|
||||
.map_err(|_| tokenizer.add_context(ParseError::Expected("usize")))?)
|
||||
.map_err(|_| tokenizer.add_context(ParseError::Expected("usize")))
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: std::io::BufRead> ReadDsn<R> for f32 {
|
||||
fn read_dsn(tokenizer: &mut ListTokenizer<R>) -> Result<Self, ParseErrorContext> {
|
||||
Ok(tokenizer
|
||||
tokenizer
|
||||
.consume_token()?
|
||||
.expect_leaf()?
|
||||
.parse()
|
||||
.map_err(|_| tokenizer.add_context(ParseError::Expected("f32")))?)
|
||||
.map_err(|_| tokenizer.add_context(ParseError::Expected("f32")))
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: std::io::BufRead> ReadDsn<R> for f64 {
|
||||
fn read_dsn(tokenizer: &mut ListTokenizer<R>) -> Result<Self, ParseErrorContext> {
|
||||
Ok(tokenizer
|
||||
tokenizer
|
||||
.consume_token()?
|
||||
.expect_leaf()?
|
||||
.parse()
|
||||
.map_err(|_| tokenizer.add_context(ParseError::Expected("f64")))?)
|
||||
.map_err(|_| tokenizer.add_context(ParseError::Expected("f64")))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -170,7 +170,7 @@ pub struct ListTokenizer<R: std::io::BufRead> {
|
|||
impl<R: std::io::BufRead> ListTokenizer<R> {
|
||||
pub fn new(reader: R) -> Self {
|
||||
Self {
|
||||
reader: reader,
|
||||
reader,
|
||||
peeked_char: None,
|
||||
cached_token: None,
|
||||
space_in_quoted: false,
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ pub struct Library {
|
|||
|
||||
impl Library {
|
||||
pub fn find_padstack_by_name(&self, name: &str) -> Option<&Padstack> {
|
||||
self.padstacks.iter().find(|padstack| &padstack.name == name)
|
||||
self.padstacks.iter().find(|padstack| padstack.name == name)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,13 +13,9 @@ impl<W: io::Write> WriteSes<W> for char {
|
|||
|
||||
impl<W: io::Write> WriteSes<W> for String {
|
||||
fn write_dsn(&self, writer: &mut ListWriter<W>) -> Result<(), io::Error> {
|
||||
let string = if self.len() == 0 {
|
||||
let string = if self.is_empty() {
|
||||
"\"\"".to_string()
|
||||
} else if self.contains(" ")
|
||||
|| self.contains("(")
|
||||
|| self.contains(")")
|
||||
|| self.contains("\n")
|
||||
{
|
||||
} else if self.contains(|i: char| i == ' ' || i == '(' || i == ')' || i == '\n') {
|
||||
format!("\"{}\"", self)
|
||||
} else {
|
||||
self.to_string()
|
||||
|
|
|
|||
Loading…
Reference in New Issue