mirror of https://codeberg.org/topola/topola.git
refactor: autogenerate getters with `derive-getters` crate
This commit is contained in:
parent
bdc021cb6e
commit
6104e761d2
|
|
@ -1,3 +1,4 @@
|
|||
use derive_getters::Getters;
|
||||
use petgraph::graph::EdgeIndex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use spade::InsertionError;
|
||||
|
|
@ -43,6 +44,7 @@ pub enum AutorouterError {
|
|||
NeedExactlyTwoRatlines,
|
||||
}
|
||||
|
||||
#[derive(Getters)]
|
||||
pub struct Autorouter<M: AccessMesadata> {
|
||||
pub(super) board: Board<M>,
|
||||
pub(super) ratsnest: Ratsnest,
|
||||
|
|
@ -201,12 +203,4 @@ impl<M: AccessMesadata> Autorouter<M> {
|
|||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn board(&self) -> &Board<M> {
|
||||
&self.board
|
||||
}
|
||||
|
||||
pub fn ratsnest(&self) -> &Ratsnest {
|
||||
&self.ratsnest
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
//! Handles error scenarios related to command history, maintaining lists of executed
|
||||
//! and undone commands for easy navigation.
|
||||
|
||||
use derive_getters::Dissolve;
|
||||
use derive_getters::{Dissolve, Getters};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ pub enum HistoryError {
|
|||
NoNextCommand,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Dissolve, Serialize, Deserialize)]
|
||||
#[derive(Debug, Default, Clone, Getters, Dissolve, Serialize, Deserialize)]
|
||||
pub struct History {
|
||||
done: Vec<Command>,
|
||||
undone: Vec<Command>,
|
||||
|
|
@ -60,12 +60,4 @@ impl History {
|
|||
pub fn last_undone(&self) -> Result<&Command, HistoryError> {
|
||||
self.undone.last().ok_or(HistoryError::NoNextCommand)
|
||||
}
|
||||
|
||||
pub fn done(&self) -> &[Command] {
|
||||
&self.done
|
||||
}
|
||||
|
||||
pub fn undone(&self) -> &[Command] {
|
||||
&self.undone
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
use std::cmp::Ordering;
|
||||
|
||||
use contracts_try::debug_requires;
|
||||
use derive_getters::Dissolve;
|
||||
use derive_getters::{Dissolve, Getters};
|
||||
use enum_dispatch::enum_dispatch;
|
||||
use thiserror::Error;
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ impl TryInto<()> for InvokerStatus {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Dissolve)]
|
||||
#[derive(Getters, Dissolve)]
|
||||
pub struct Invoker<M: AccessMesadata> {
|
||||
pub(super) autorouter: Autorouter<M>,
|
||||
pub(super) history: History,
|
||||
|
|
@ -199,12 +199,4 @@ impl<M: AccessMesadata> Invoker<M> {
|
|||
|
||||
self.history.set_undone(undone.into_iter());
|
||||
}
|
||||
|
||||
pub fn autorouter(&self) -> &Autorouter<M> {
|
||||
&self.autorouter
|
||||
}
|
||||
|
||||
pub fn history(&self) -> &History {
|
||||
&self.history
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use std::{cmp::Ordering, collections::HashMap};
|
||||
|
||||
use bimap::BiHashMap;
|
||||
use derive_getters::Getters;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
|
|
@ -41,10 +42,13 @@ impl BandName {
|
|||
///
|
||||
/// The struct manages the relationships between board's layout,
|
||||
/// and its compounds, as well as provides methods to manipulate them.
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Getters)]
|
||||
pub struct Board<M: AccessMesadata> {
|
||||
layout: Layout<M>,
|
||||
// TODO: Simplify access logic to these members so that `#[getter(skip)]`s can be removed.
|
||||
#[getter(skip)]
|
||||
node_to_pinname: HashMap<NodeIndex, String>,
|
||||
#[getter(skip)]
|
||||
band_bandname: BiHashMap<BandUid, BandName>,
|
||||
}
|
||||
|
||||
|
|
@ -231,11 +235,6 @@ impl<M: AccessMesadata> Board<M> {
|
|||
self.layout.drawing().rules()
|
||||
}
|
||||
|
||||
/// Returns the layout managed by this board.
|
||||
pub fn layout(&self) -> &Layout<M> {
|
||||
&self.layout
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the layout, allowing modifications.
|
||||
pub fn layout_mut(&mut self) -> &mut Layout<M> {
|
||||
&mut self.layout
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use contracts_try::{debug_ensures, debug_invariant};
|
||||
use derive_getters::Getters;
|
||||
use enum_dispatch::enum_dispatch;
|
||||
use geo::Point;
|
||||
|
||||
|
|
@ -64,7 +65,7 @@ pub struct Collision(pub PrimitiveShape, pub PrimitiveIndex);
|
|||
#[error("{1:?} is already connected to net {0}")]
|
||||
pub struct AlreadyConnected(pub usize, pub PrimitiveIndex);
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Getters)]
|
||||
pub struct Drawing<CW: Copy, R: AccessRules> {
|
||||
geometry_with_rtree: GeometryWithRtree<
|
||||
PrimitiveWeight,
|
||||
|
|
@ -890,10 +891,6 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
|||
self.geometry_with_rtree.rtree()
|
||||
}
|
||||
|
||||
pub fn rules(&self) -> &R {
|
||||
&self.rules
|
||||
}
|
||||
|
||||
#[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()))]
|
||||
pub fn rules_mut(&mut self) -> &mut R {
|
||||
|
|
@ -917,7 +914,7 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
|||
}
|
||||
|
||||
pub fn layer_count(&self) -> usize {
|
||||
self.geometry_with_rtree.layer_count()
|
||||
*self.geometry_with_rtree.layer_count()
|
||||
}
|
||||
|
||||
pub fn node_count(&self) -> usize {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use derive_getters::Getters;
|
||||
use enum_dispatch::enum_dispatch;
|
||||
use geo::Point;
|
||||
use petgraph::{
|
||||
|
|
@ -68,7 +69,7 @@ pub trait AccessDotWeight<CW>: GetPos + SetPos + GetWidth + Into<CW> + Copy {}
|
|||
pub trait AccessSegWeight<CW>: GetWidth + Into<CW> + Copy {}
|
||||
pub trait AccessBendWeight<CW>: GetOffset + SetOffset + GetWidth + Into<CW> + Copy {}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Getters)]
|
||||
pub struct Geometry<
|
||||
PW: GetWidth + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<PI> + Copy,
|
||||
DW: AccessDotWeight<PW>,
|
||||
|
|
@ -478,10 +479,6 @@ impl<
|
|||
})
|
||||
.map(|ni| self.primitive_weight(ni).retag(ni))
|
||||
}
|
||||
|
||||
pub fn graph(&self) -> &StableDiGraph<GenericNode<PW, CW>, GeometryLabel, usize> {
|
||||
&self.graph
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use contracts_try::debug_invariant;
|
||||
use derive_getters::Getters;
|
||||
use geo::Point;
|
||||
use petgraph::stable_graph::StableDiGraph;
|
||||
use rstar::{primitives::GeomWithData, Envelope, RTree, RTreeObject, AABB};
|
||||
|
|
@ -36,7 +37,7 @@ impl RTreeObject for Bbox {
|
|||
|
||||
pub type BboxedIndex<I> = GeomWithData<Bbox, I>;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Getters)]
|
||||
pub struct GeometryWithRtree<
|
||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<PI> + Copy,
|
||||
DW: AccessDotWeight<PW> + GetLayer,
|
||||
|
|
@ -347,19 +348,6 @@ impl<
|
|||
}
|
||||
}
|
||||
|
||||
pub fn layer_count(&self) -> usize {
|
||||
self.layer_count
|
||||
}
|
||||
|
||||
pub fn geometry(&self) -> &Geometry<PW, DW, SW, BW, CW, PI, DI, SI, BI> {
|
||||
&self.geometry
|
||||
}
|
||||
|
||||
// XXX: The type appears wrong? I don't think it should contain CW?
|
||||
pub fn rtree(&self) -> &RTree<BboxedIndex<GenericNode<PI, GenericIndex<CW>>>> {
|
||||
&self.rtree
|
||||
}
|
||||
|
||||
pub fn graph(&self) -> &StableDiGraph<GenericNode<PW, CW>, GeometryLabel, usize> {
|
||||
self.geometry.graph()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use contracts_try::debug_ensures;
|
||||
use derive_getters::Getters;
|
||||
use enum_dispatch::enum_dispatch;
|
||||
use geo::Point;
|
||||
use rstar::AABB;
|
||||
|
|
@ -35,7 +36,7 @@ pub enum CompoundWeight {
|
|||
|
||||
pub type NodeIndex = GenericNode<PrimitiveIndex, GenericIndex<CompoundWeight>>;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Getters)]
|
||||
pub struct Layout<R: AccessRules> {
|
||||
drawing: Drawing<CompoundWeight, R>,
|
||||
}
|
||||
|
|
@ -256,10 +257,6 @@ impl<R: AccessRules> Layout<R> {
|
|||
.compound_members(GenericIndex::new(poly.petgraph_index()))
|
||||
}
|
||||
|
||||
pub fn drawing(&self) -> &Drawing<CompoundWeight, R> {
|
||||
&self.drawing
|
||||
}
|
||||
|
||||
pub fn rules(&self) -> &R {
|
||||
self.drawing.rules()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ impl RouteStepper {
|
|||
to: FixedDotIndex,
|
||||
width: f64,
|
||||
) -> Result<Self, NavmeshError> {
|
||||
let navmesh = Navmesh::new(router.layout(), from, to, router.options())?;
|
||||
let navmesh = Navmesh::new(router.layout(), from, to, router.options().clone())?;
|
||||
Ok(Self::new_from_navmesh(router, navmesh, width))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use derive_getters::Getters;
|
||||
use geo::EuclideanDistance;
|
||||
use petgraph::{data::DataMap, visit::EdgeRef};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -182,8 +183,9 @@ impl<'a, R: AccessRules> AstarStrategy<Navmesh, f64, BandTermsegIndex>
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Getters)]
|
||||
pub struct Router<'a, R: AccessRules> {
|
||||
#[getter(skip)]
|
||||
layout: &'a mut Layout<R>,
|
||||
options: RouterOptions,
|
||||
}
|
||||
|
|
@ -209,8 +211,4 @@ impl<'a, R: AccessRules> Router<'a, R> {
|
|||
pub fn layout(&self) -> &Layout<R> {
|
||||
self.layout
|
||||
}
|
||||
|
||||
pub fn options(&self) -> RouterOptions {
|
||||
self.options
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue