mirror of https://codeberg.org/topola/topola.git
refactor(RecordingWithRtree): undo OurGeometryEdit macro usage
This commit is contained in:
parent
4859887a5d
commit
e76f740563
|
|
@ -33,12 +33,6 @@ pub struct RecordingGeometryWithRtree<
|
|||
geometry_with_rtree: GeometryWithRtree<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||
}
|
||||
|
||||
/// inherent associated types are unstable
|
||||
/// see issue #8995 <https://github.com/rust-lang/rust/issues/8995> for more information
|
||||
macro_rules! OurGeometryEdit {
|
||||
() => { GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI> }
|
||||
}
|
||||
|
||||
impl<
|
||||
PW: GetWidth + GetLayer + TryInto<DW> + TryInto<SW> + TryInto<BW> + Retag<PI> + Copy,
|
||||
DW: AccessDotWeight<PW> + GetLayer,
|
||||
|
|
@ -61,7 +55,7 @@ impl<
|
|||
|
||||
pub fn add_dot<W: AccessDotWeight<PW> + GetLayer>(
|
||||
&mut self,
|
||||
recorder: &mut OurGeometryEdit!(),
|
||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||
weight: W,
|
||||
) -> GenericIndex<W>
|
||||
where
|
||||
|
|
@ -82,7 +76,7 @@ impl<
|
|||
|
||||
pub fn add_seg<W: AccessSegWeight<PW> + GetLayer>(
|
||||
&mut self,
|
||||
recorder: &mut OurGeometryEdit!(),
|
||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||
from: DI,
|
||||
to: DI,
|
||||
weight: W,
|
||||
|
|
@ -108,7 +102,7 @@ impl<
|
|||
|
||||
pub fn add_bend<W: AccessBendWeight<PW> + GetLayer>(
|
||||
&mut self,
|
||||
recorder: &mut OurGeometryEdit!(),
|
||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||
from: DI,
|
||||
to: DI,
|
||||
core: DI,
|
||||
|
|
@ -135,7 +129,7 @@ impl<
|
|||
|
||||
pub fn add_compound(
|
||||
&mut self,
|
||||
recorder: &mut OurGeometryEdit!(),
|
||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||
weight: CW,
|
||||
) -> GenericIndex<CW> {
|
||||
let compound = self.geometry_with_rtree.add_compound(weight);
|
||||
|
|
@ -147,7 +141,7 @@ impl<
|
|||
|
||||
pub fn add_to_compound<W>(
|
||||
&mut self,
|
||||
recorder: &mut OurGeometryEdit!(),
|
||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||
primitive: GenericIndex<W>,
|
||||
compound: GenericIndex<CW>,
|
||||
) {
|
||||
|
|
@ -168,14 +162,22 @@ impl<
|
|||
.1 = Some((new_members, new_weight));
|
||||
}
|
||||
|
||||
pub fn remove_dot(&mut self, recorder: &mut OurGeometryEdit!(), dot: DI) -> Result<(), ()> {
|
||||
pub fn remove_dot(
|
||||
&mut self,
|
||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||
dot: DI,
|
||||
) -> Result<(), ()> {
|
||||
let weight = self.geometry_with_rtree.geometry().dot_weight(dot);
|
||||
self.geometry_with_rtree.remove_dot(dot)?;
|
||||
edit_remove_from_map(&mut recorder.dots, dot, weight);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn remove_seg(&mut self, recorder: &mut OurGeometryEdit!(), seg: SI) {
|
||||
pub fn remove_seg(
|
||||
&mut self,
|
||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||
seg: SI,
|
||||
) {
|
||||
let geometry = self.geometry_with_rtree.geometry();
|
||||
let weight = geometry.seg_weight(seg);
|
||||
let joints = geometry.seg_joints(seg);
|
||||
|
|
@ -183,7 +185,11 @@ impl<
|
|||
edit_remove_from_map(&mut recorder.segs, seg, (joints, weight));
|
||||
}
|
||||
|
||||
pub fn remove_bend(&mut self, recorder: &mut OurGeometryEdit!(), bend: BI) {
|
||||
pub fn remove_bend(
|
||||
&mut self,
|
||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||
bend: BI,
|
||||
) {
|
||||
let geometry = self.geometry_with_rtree.geometry();
|
||||
let weight = geometry.bend_weight(bend);
|
||||
let joints = geometry.bend_joints(bend);
|
||||
|
|
@ -198,7 +204,7 @@ impl<
|
|||
|
||||
pub fn remove_compound(
|
||||
&mut self,
|
||||
recorder: &mut OurGeometryEdit!(),
|
||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||
compound: GenericIndex<CW>,
|
||||
) {
|
||||
let geometry = self.geometry_with_rtree.geometry();
|
||||
|
|
@ -208,7 +214,12 @@ impl<
|
|||
edit_remove_from_map(&mut recorder.compounds, compound, (members, weight));
|
||||
}
|
||||
|
||||
pub fn move_dot(&mut self, recorder: &mut OurGeometryEdit!(), dot: DI, to: Point) {
|
||||
pub fn move_dot(
|
||||
&mut self,
|
||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||
dot: DI,
|
||||
to: Point,
|
||||
) {
|
||||
let old_weight = self.geometry_with_rtree.geometry().dot_weight(dot);
|
||||
self.geometry_with_rtree.move_dot(dot, to);
|
||||
let new_weight = self.geometry_with_rtree.geometry().dot_weight(dot);
|
||||
|
|
@ -220,8 +231,12 @@ impl<
|
|||
.1 = Some(new_weight);
|
||||
}
|
||||
|
||||
fn modify_bend<F>(&mut self, recorder: &mut OurGeometryEdit!(), bend: BI, f: F)
|
||||
where
|
||||
fn modify_bend<F>(
|
||||
&mut self,
|
||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||
bend: BI,
|
||||
f: F,
|
||||
) where
|
||||
F: FnOnce(&mut GeometryWithRtree<PW, DW, SW, BW, CW, PI, DI, SI, BI>, BI),
|
||||
{
|
||||
let geometry = self.geometry_with_rtree.geometry();
|
||||
|
|
@ -246,13 +261,22 @@ impl<
|
|||
.1 = Some(((new_joints.0, new_joints.1, new_core), new_weight));
|
||||
}
|
||||
|
||||
pub fn shift_bend(&mut self, recorder: &mut OurGeometryEdit!(), bend: BI, offset: f64) {
|
||||
pub fn shift_bend(
|
||||
&mut self,
|
||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||
bend: BI,
|
||||
offset: f64,
|
||||
) {
|
||||
self.modify_bend(recorder, bend, |geometry_with_rtree, bend| {
|
||||
geometry_with_rtree.shift_bend(bend, offset)
|
||||
});
|
||||
}
|
||||
|
||||
pub fn flip_bend(&mut self, recorder: &mut OurGeometryEdit!(), bend: BI) {
|
||||
pub fn flip_bend(
|
||||
&mut self,
|
||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||
bend: BI,
|
||||
) {
|
||||
self.modify_bend(recorder, bend, |geometry_with_rtree, bend| {
|
||||
geometry_with_rtree.flip_bend(bend)
|
||||
});
|
||||
|
|
@ -260,7 +284,7 @@ impl<
|
|||
|
||||
pub fn reattach_bend(
|
||||
&mut self,
|
||||
recorder: &mut OurGeometryEdit!(),
|
||||
recorder: &mut GeometryEdit<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
|
||||
bend: BI,
|
||||
maybe_new_inner: Option<BI>,
|
||||
) {
|
||||
|
|
@ -332,7 +356,7 @@ impl<
|
|||
> ApplyGeometryEdit<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: &OurGeometryEdit!()) {
|
||||
fn apply(&mut self, edit: &GeometryEdit<PW, 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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue