feat(board/edit): Edit structures should implement Default trait

This commit is contained in:
Ellen Emilia Anna Zscheile 2025-08-09 22:44:23 +02:00
parent 791291b82e
commit 6f7586227c
2 changed files with 15 additions and 22 deletions

View File

@ -6,16 +6,14 @@ use std::collections::BTreeMap;
use crate::{board::BandName, drawing::band::BandUid, geometry::edit::Edit, layout::LayoutEdit}; use crate::{board::BandName, drawing::band::BandUid, geometry::edit::Edit, layout::LayoutEdit};
#[derive(Debug, Clone)] #[derive(Debug, Clone, Default)]
pub struct BoardDataEdit { pub struct BoardDataEdit {
pub(super) bands: BTreeMap<BandName, (Option<BandUid>, Option<BandUid>)>, pub(super) bands: BTreeMap<BandName, (Option<BandUid>, Option<BandUid>)>,
} }
impl BoardDataEdit { impl BoardDataEdit {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self::default()
bands: BTreeMap::new(),
}
} }
} }
@ -29,7 +27,7 @@ impl Edit for BoardDataEdit {
} }
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone, Default)]
pub struct BoardEdit { pub struct BoardEdit {
pub data_edit: BoardDataEdit, pub data_edit: BoardDataEdit,
pub layout_edit: LayoutEdit, pub layout_edit: LayoutEdit,
@ -37,10 +35,7 @@ pub struct BoardEdit {
impl BoardEdit { impl BoardEdit {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self::default()
data_edit: BoardDataEdit::new(),
layout_edit: LayoutEdit::new(),
}
} }
pub fn new_from_edits(data_edit: BoardDataEdit, layout_edit: LayoutEdit) -> Self { pub fn new_from_edits(data_edit: BoardDataEdit, layout_edit: LayoutEdit) -> Self {

View File

@ -38,7 +38,7 @@ pub trait ApplyGeometryEdit<
fn apply(&mut self, edit: &GeometryEdit<DW, SW, BW, CW, Cel, PI, DI, SI, BI>); fn apply(&mut self, edit: &GeometryEdit<DW, SW, BW, CW, Cel, PI, DI, SI, BI>);
} }
#[derive(Debug, Clone)] #[derive(Clone, Debug)]
pub struct GeometryEdit<DW, SW, BW, CW, Cel, PI, DI, SI, BI> { pub struct GeometryEdit<DW, SW, BW, CW, Cel, PI, DI, SI, BI> {
pub(super) dots: BTreeMap<DI, (Option<DW>, Option<DW>)>, pub(super) dots: BTreeMap<DI, (Option<DW>, Option<DW>)>,
pub(super) segs: BTreeMap<SI, (Option<((DI, DI), SW)>, Option<((DI, DI), SW)>)>, pub(super) segs: BTreeMap<SI, (Option<((DI, DI), SW)>, Option<((DI, DI), SW)>)>,
@ -53,19 +53,10 @@ pub struct GeometryEdit<DW, SW, BW, CW, Cel, PI, DI, SI, BI> {
BTreeMap<GenericIndex<CW>, (Option<(Vec<(Cel, PI)>, CW)>, Option<(Vec<(Cel, PI)>, CW)>)>, BTreeMap<GenericIndex<CW>, (Option<(Vec<(Cel, PI)>, CW)>, Option<(Vec<(Cel, PI)>, CW)>)>,
} }
impl< impl<DW, SW, BW, CW, Cel, PI, DI, SI, BI> Default
DW: AccessDotWeight + GetLayer, for GeometryEdit<DW, SW, BW, CW, Cel, PI, DI, SI, BI>
SW: AccessSegWeight + GetLayer,
BW: AccessBendWeight + GetLayer,
CW: Clone,
Cel: Copy,
PI: GetPetgraphIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Ord + Copy,
DI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
SI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
BI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
> GeometryEdit<DW, SW, BW, CW, Cel, PI, DI, SI, BI>
{ {
pub fn new() -> Self { fn default() -> Self {
Self { Self {
dots: BTreeMap::new(), dots: BTreeMap::new(),
segs: BTreeMap::new(), segs: BTreeMap::new(),
@ -75,6 +66,13 @@ impl<
} }
} }
impl<DW, SW, BW, CW, Cel, PI, DI, SI, BI> GeometryEdit<DW, SW, BW, CW, Cel, PI, DI, SI, BI> {
#[inline(always)]
pub fn new() -> Self {
Self::default()
}
}
impl< impl<
DW: AccessDotWeight + GetLayer, DW: AccessDotWeight + GetLayer,
SW: AccessSegWeight + GetLayer, SW: AccessSegWeight + GetLayer,