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