mirror of https://codeberg.org/topola/topola.git
refactor(geometry/edit): GeometryEdit shouldn't know about PrimitiveIndex
This commit is contained in:
parent
cdee22d63e
commit
77969952ff
|
|
@ -17,7 +17,7 @@ use crate::{
|
||||||
band::BandUid,
|
band::BandUid,
|
||||||
bend::{BendIndex, BendWeight},
|
bend::{BendIndex, BendWeight},
|
||||||
dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight, GeneralDotWeight},
|
dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight, GeneralDotWeight},
|
||||||
graph::{GetMaybeNet, PrimitiveIndex, PrimitiveWeight},
|
graph::{GetMaybeNet, PrimitiveIndex},
|
||||||
seg::{FixedSegIndex, FixedSegWeight, SegIndex, SegWeight},
|
seg::{FixedSegIndex, FixedSegWeight, SegIndex, SegWeight},
|
||||||
Collect,
|
Collect,
|
||||||
},
|
},
|
||||||
|
|
@ -288,7 +288,6 @@ impl<M: AccessMesadata> Board<M> {
|
||||||
|
|
||||||
impl<M: AccessMesadata>
|
impl<M: AccessMesadata>
|
||||||
ApplyGeometryEdit<
|
ApplyGeometryEdit<
|
||||||
PrimitiveWeight,
|
|
||||||
DotWeight,
|
DotWeight,
|
||||||
SegWeight,
|
SegWeight,
|
||||||
BendWeight,
|
BendWeight,
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,6 @@ pub struct Collision(pub PrimitiveShape, pub PrimitiveIndex);
|
||||||
pub struct AlreadyConnected(pub usize, pub PrimitiveIndex);
|
pub struct AlreadyConnected(pub usize, pub PrimitiveIndex);
|
||||||
|
|
||||||
pub type DrawingEdit<CW> = GeometryEdit<
|
pub type DrawingEdit<CW> = GeometryEdit<
|
||||||
PrimitiveWeight,
|
|
||||||
DotWeight,
|
DotWeight,
|
||||||
SegWeight,
|
SegWeight,
|
||||||
BendWeight,
|
BendWeight,
|
||||||
|
|
@ -1120,7 +1119,6 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
||||||
|
|
||||||
impl<CW: Copy, R: AccessRules>
|
impl<CW: Copy, R: AccessRules>
|
||||||
ApplyGeometryEdit<
|
ApplyGeometryEdit<
|
||||||
PrimitiveWeight,
|
|
||||||
DotWeight,
|
DotWeight,
|
||||||
SegWeight,
|
SegWeight,
|
||||||
BendWeight,
|
BendWeight,
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,16 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
use std::{collections::BTreeMap, marker::PhantomData};
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
use crate::graph::{GenericIndex, GetPetgraphIndex};
|
use crate::graph::{GenericIndex, GetPetgraphIndex};
|
||||||
|
|
||||||
use super::{AccessBendWeight, AccessDotWeight, AccessSegWeight, GetLayer, GetWidth, Retag};
|
use super::{AccessBendWeight, AccessDotWeight, AccessSegWeight, GetLayer};
|
||||||
|
|
||||||
pub trait ApplyGeometryEdit<
|
pub trait ApplyGeometryEdit<
|
||||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<Index = PI> + Copy,
|
DW: AccessDotWeight + GetLayer,
|
||||||
DW: AccessDotWeight + Into<PW> + GetLayer,
|
SW: AccessSegWeight + GetLayer,
|
||||||
SW: AccessSegWeight + Into<PW> + GetLayer,
|
BW: AccessBendWeight + GetLayer,
|
||||||
BW: AccessBendWeight + Into<PW> + GetLayer,
|
|
||||||
CW: Copy,
|
CW: Copy,
|
||||||
PI: GetPetgraphIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Ord + Copy,
|
PI: GetPetgraphIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Ord + Copy,
|
||||||
DI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
DI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
||||||
|
|
@ -20,17 +19,16 @@ pub trait ApplyGeometryEdit<
|
||||||
BI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
BI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
fn apply(&mut self, edit: &GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>);
|
fn apply(&mut self, edit: &GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI> {
|
pub struct GeometryEdit<DW, SW, BW, CW, 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)>)>,
|
||||||
pub(super) bends: BTreeMap<BI, (Option<((DI, DI, DI), BW)>, Option<((DI, DI, DI), BW)>)>,
|
pub(super) bends: BTreeMap<BI, (Option<((DI, DI, DI), BW)>, Option<((DI, DI, DI), BW)>)>,
|
||||||
pub(super) compounds:
|
pub(super) compounds:
|
||||||
BTreeMap<GenericIndex<CW>, (Option<(Vec<PI>, CW)>, Option<(Vec<PI>, CW)>)>,
|
BTreeMap<GenericIndex<CW>, (Option<(Vec<PI>, CW)>, Option<(Vec<PI>, CW)>)>,
|
||||||
primitive_weight_marker: PhantomData<PW>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn swap_tuple_inplace<D>(x: &mut (D, D)) {
|
fn swap_tuple_inplace<D>(x: &mut (D, D)) {
|
||||||
|
|
@ -38,16 +36,15 @@ fn swap_tuple_inplace<D>(x: &mut (D, D)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<Index = PI> + Copy,
|
DW: AccessDotWeight + GetLayer,
|
||||||
DW: AccessDotWeight + Into<PW> + GetLayer,
|
SW: AccessSegWeight + GetLayer,
|
||||||
SW: AccessSegWeight + Into<PW> + GetLayer,
|
BW: AccessBendWeight + GetLayer,
|
||||||
BW: AccessBendWeight + Into<PW> + GetLayer,
|
|
||||||
CW: Copy,
|
CW: Copy,
|
||||||
PI: GetPetgraphIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Ord + Copy,
|
PI: GetPetgraphIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Ord + Copy,
|
||||||
DI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
DI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
||||||
SI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
SI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
||||||
BI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
BI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
||||||
> GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>
|
> GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>
|
||||||
{
|
{
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
@ -55,7 +52,6 @@ impl<
|
||||||
segs: BTreeMap::new(),
|
segs: BTreeMap::new(),
|
||||||
bends: BTreeMap::new(),
|
bends: BTreeMap::new(),
|
||||||
compounds: BTreeMap::new(),
|
compounds: BTreeMap::new(),
|
||||||
primitive_weight_marker: PhantomData,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,19 +87,18 @@ fn apply_btmap<I: Copy + Eq + Ord, D: Clone>(
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<
|
impl<
|
||||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<Index = PI> + Copy,
|
DW: AccessDotWeight + GetLayer,
|
||||||
DW: AccessDotWeight + Into<PW> + GetLayer,
|
SW: AccessSegWeight + GetLayer,
|
||||||
SW: AccessSegWeight + Into<PW> + GetLayer,
|
BW: AccessBendWeight + GetLayer,
|
||||||
BW: AccessBendWeight + Into<PW> + GetLayer,
|
|
||||||
CW: Copy,
|
CW: Copy,
|
||||||
PI: GetPetgraphIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Ord + Copy,
|
PI: GetPetgraphIndex + TryInto<DI> + TryInto<SI> + TryInto<BI> + Eq + Ord + Copy,
|
||||||
DI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
DI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
||||||
SI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
SI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
||||||
BI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
BI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
||||||
> ApplyGeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>
|
> ApplyGeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>
|
||||||
for GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>
|
for GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>
|
||||||
{
|
{
|
||||||
fn apply(&mut self, edit: &GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>) {
|
fn apply(&mut self, edit: &GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>) {
|
||||||
apply_btmap(&mut self.dots, &edit.dots);
|
apply_btmap(&mut self.dots, &edit.dots);
|
||||||
apply_btmap(&mut self.segs, &edit.segs);
|
apply_btmap(&mut self.segs, &edit.segs);
|
||||||
apply_btmap(&mut self.bends, &edit.bends);
|
apply_btmap(&mut self.bends, &edit.bends);
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ impl<
|
||||||
|
|
||||||
pub fn add_dot<W: AccessDotWeight + Into<PW> + GetLayer>(
|
pub fn add_dot<W: AccessDotWeight + Into<PW> + GetLayer>(
|
||||||
&mut self,
|
&mut self,
|
||||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
recorder: &mut GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||||
weight: W,
|
weight: W,
|
||||||
) -> GenericIndex<W>
|
) -> GenericIndex<W>
|
||||||
where
|
where
|
||||||
|
|
@ -76,7 +76,7 @@ impl<
|
||||||
|
|
||||||
pub fn add_seg<W: AccessSegWeight + Into<PW> + GetLayer>(
|
pub fn add_seg<W: AccessSegWeight + Into<PW> + GetLayer>(
|
||||||
&mut self,
|
&mut self,
|
||||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
recorder: &mut GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||||
from: DI,
|
from: DI,
|
||||||
to: DI,
|
to: DI,
|
||||||
weight: W,
|
weight: W,
|
||||||
|
|
@ -102,7 +102,7 @@ impl<
|
||||||
|
|
||||||
pub fn add_bend<W: AccessBendWeight + Into<PW> + GetLayer>(
|
pub fn add_bend<W: AccessBendWeight + Into<PW> + GetLayer>(
|
||||||
&mut self,
|
&mut self,
|
||||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
recorder: &mut GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||||
from: DI,
|
from: DI,
|
||||||
to: DI,
|
to: DI,
|
||||||
core: DI,
|
core: DI,
|
||||||
|
|
@ -129,7 +129,7 @@ impl<
|
||||||
|
|
||||||
pub fn add_compound(
|
pub fn add_compound(
|
||||||
&mut self,
|
&mut self,
|
||||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
recorder: &mut GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||||
weight: CW,
|
weight: CW,
|
||||||
) -> GenericIndex<CW> {
|
) -> GenericIndex<CW> {
|
||||||
let compound = self.geometry_with_rtree.add_compound(weight);
|
let compound = self.geometry_with_rtree.add_compound(weight);
|
||||||
|
|
@ -141,7 +141,7 @@ impl<
|
||||||
|
|
||||||
pub fn add_to_compound<W>(
|
pub fn add_to_compound<W>(
|
||||||
&mut self,
|
&mut self,
|
||||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
recorder: &mut GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||||
primitive: GenericIndex<W>,
|
primitive: GenericIndex<W>,
|
||||||
compound: GenericIndex<CW>,
|
compound: GenericIndex<CW>,
|
||||||
) {
|
) {
|
||||||
|
|
@ -165,7 +165,7 @@ impl<
|
||||||
|
|
||||||
pub fn remove_dot(
|
pub fn remove_dot(
|
||||||
&mut self,
|
&mut self,
|
||||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
recorder: &mut GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||||
dot: DI,
|
dot: DI,
|
||||||
) -> Result<(), ()> {
|
) -> Result<(), ()> {
|
||||||
let weight = self.geometry_with_rtree.geometry().dot_weight(dot);
|
let weight = self.geometry_with_rtree.geometry().dot_weight(dot);
|
||||||
|
|
@ -176,7 +176,7 @@ impl<
|
||||||
|
|
||||||
pub fn remove_seg(
|
pub fn remove_seg(
|
||||||
&mut self,
|
&mut self,
|
||||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
recorder: &mut GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||||
seg: SI,
|
seg: SI,
|
||||||
) {
|
) {
|
||||||
let geometry = self.geometry_with_rtree.geometry();
|
let geometry = self.geometry_with_rtree.geometry();
|
||||||
|
|
@ -188,7 +188,7 @@ impl<
|
||||||
|
|
||||||
pub fn remove_bend(
|
pub fn remove_bend(
|
||||||
&mut self,
|
&mut self,
|
||||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
recorder: &mut GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||||
bend: BI,
|
bend: BI,
|
||||||
) {
|
) {
|
||||||
let geometry = self.geometry_with_rtree.geometry();
|
let geometry = self.geometry_with_rtree.geometry();
|
||||||
|
|
@ -205,7 +205,7 @@ impl<
|
||||||
|
|
||||||
pub fn remove_compound(
|
pub fn remove_compound(
|
||||||
&mut self,
|
&mut self,
|
||||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
recorder: &mut GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||||
compound: GenericIndex<CW>,
|
compound: GenericIndex<CW>,
|
||||||
) {
|
) {
|
||||||
let geometry = self.geometry_with_rtree.geometry();
|
let geometry = self.geometry_with_rtree.geometry();
|
||||||
|
|
@ -217,7 +217,7 @@ impl<
|
||||||
|
|
||||||
pub fn move_dot(
|
pub fn move_dot(
|
||||||
&mut self,
|
&mut self,
|
||||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
recorder: &mut GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||||
dot: DI,
|
dot: DI,
|
||||||
to: Point,
|
to: Point,
|
||||||
) {
|
) {
|
||||||
|
|
@ -234,7 +234,7 @@ impl<
|
||||||
|
|
||||||
fn modify_bend<F>(
|
fn modify_bend<F>(
|
||||||
&mut self,
|
&mut self,
|
||||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
recorder: &mut GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||||
bend: BI,
|
bend: BI,
|
||||||
f: F,
|
f: F,
|
||||||
) where
|
) where
|
||||||
|
|
@ -264,7 +264,7 @@ impl<
|
||||||
|
|
||||||
pub fn shift_bend(
|
pub fn shift_bend(
|
||||||
&mut self,
|
&mut self,
|
||||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
recorder: &mut GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||||
bend: BI,
|
bend: BI,
|
||||||
offset: f64,
|
offset: f64,
|
||||||
) {
|
) {
|
||||||
|
|
@ -275,7 +275,7 @@ impl<
|
||||||
|
|
||||||
pub fn flip_bend(
|
pub fn flip_bend(
|
||||||
&mut self,
|
&mut self,
|
||||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
recorder: &mut GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||||
bend: BI,
|
bend: BI,
|
||||||
) {
|
) {
|
||||||
self.modify_bend(recorder, bend, |geometry_with_rtree, bend| {
|
self.modify_bend(recorder, bend, |geometry_with_rtree, bend| {
|
||||||
|
|
@ -285,7 +285,7 @@ impl<
|
||||||
|
|
||||||
pub fn reattach_bend(
|
pub fn reattach_bend(
|
||||||
&mut self,
|
&mut self,
|
||||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
recorder: &mut GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||||
bend: BI,
|
bend: BI,
|
||||||
maybe_new_inner: Option<BI>,
|
maybe_new_inner: Option<BI>,
|
||||||
) {
|
) {
|
||||||
|
|
@ -352,10 +352,10 @@ impl<
|
||||||
DI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
DI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
||||||
SI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
SI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
||||||
BI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
BI: GetPetgraphIndex + Into<PI> + Eq + Ord + Copy,
|
||||||
> ApplyGeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>
|
> ApplyGeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>
|
||||||
for RecordingGeometryWithRtree<PW, DW, SW, BW, CW, PI, DI, SI, BI>
|
for RecordingGeometryWithRtree<PW, DW, SW, BW, CW, PI, DI, SI, BI>
|
||||||
{
|
{
|
||||||
fn apply(&mut self, edit: &GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>) {
|
fn apply(&mut self, edit: &GeometryEdit<DW, SW, BW, CW, PI, DI, SI, BI>) {
|
||||||
for (compound, (maybe_old_data, ..)) in &edit.compounds {
|
for (compound, (maybe_old_data, ..)) in &edit.compounds {
|
||||||
if maybe_old_data.is_some() {
|
if maybe_old_data.is_some() {
|
||||||
self.geometry_with_rtree.remove_compound(*compound);
|
self.geometry_with_rtree.remove_compound(*compound);
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ use crate::{
|
||||||
LooseDotWeight,
|
LooseDotWeight,
|
||||||
},
|
},
|
||||||
gear::GearIndex,
|
gear::GearIndex,
|
||||||
graph::{GetMaybeNet, IsInLayer, MakePrimitive, PrimitiveIndex, PrimitiveWeight},
|
graph::{GetMaybeNet, IsInLayer, MakePrimitive, PrimitiveIndex},
|
||||||
loose::LooseIndex,
|
loose::LooseIndex,
|
||||||
primitive::{GetWeight, MakePrimitiveShape, Primitive},
|
primitive::{GetWeight, MakePrimitiveShape, Primitive},
|
||||||
rules::AccessRules,
|
rules::AccessRules,
|
||||||
|
|
@ -476,7 +476,6 @@ impl<R: AccessRules> Layout<R> {
|
||||||
|
|
||||||
impl<R: AccessRules>
|
impl<R: AccessRules>
|
||||||
ApplyGeometryEdit<
|
ApplyGeometryEdit<
|
||||||
PrimitiveWeight,
|
|
||||||
DotWeight,
|
DotWeight,
|
||||||
SegWeight,
|
SegWeight,
|
||||||
BendWeight,
|
BendWeight,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue