From 1f55e920260e6bb94d604b117b8da665e2b1c2b9 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Mon, 25 Nov 2024 22:33:52 +0100 Subject: [PATCH] refactor(geometry): move edit code to its own file --- src/drawing/drawing.rs | 3 +- src/geometry/edit.rs | 50 ++++++++++++++++++++++++++++ src/geometry/mod.rs | 1 + src/geometry/recording_with_rtree.rs | 45 ++----------------------- 4 files changed, 55 insertions(+), 44 deletions(-) create mode 100644 src/geometry/edit.rs diff --git a/src/drawing/drawing.rs b/src/drawing/drawing.rs index e8dacea..434100d 100644 --- a/src/drawing/drawing.rs +++ b/src/drawing/drawing.rs @@ -7,8 +7,9 @@ use rstar::{RTree, AABB}; use thiserror::Error; use crate::geometry::{ + edit::GeometryEdit, primitive::{AccessPrimitiveShape, PrimitiveShape}, - recording_with_rtree::{GeometryEdit, RecordingGeometryWithRtree}, + recording_with_rtree::RecordingGeometryWithRtree, with_rtree::BboxedIndex, AccessBendWeight, AccessDotWeight, AccessSegWeight, GenericNode, Geometry, GeometryLabel, GetOffset, GetPos, GetWidth, diff --git a/src/geometry/edit.rs b/src/geometry/edit.rs new file mode 100644 index 0000000..8ec85f8 --- /dev/null +++ b/src/geometry/edit.rs @@ -0,0 +1,50 @@ +use std::{collections::HashMap, hash::Hash, marker::PhantomData}; + +use crate::{ + drawing::graph::{GetLayer, Retag}, + graph::{GenericIndex, GetPetgraphIndex}, +}; + +use super::{AccessBendWeight, AccessDotWeight, AccessSegWeight, GetWidth}; + +#[derive(Debug)] +pub struct GeometryEdit< + PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, + DW: AccessDotWeight + GetLayer, + SW: AccessSegWeight + GetLayer, + BW: AccessBendWeight + GetLayer, + CW: Copy, + PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Eq + Hash + Copy, + DI: GetPetgraphIndex + Into + Eq + Hash + Copy, + SI: GetPetgraphIndex + Into + Eq + Hash + Copy, + BI: GetPetgraphIndex + Into + Eq + Hash + Copy, +> { + pub(super) dots: HashMap, Option)>, + pub(super) segs: HashMap, Option<((DI, DI), SW)>)>, + pub(super) bends: HashMap, Option<((DI, DI, DI), BW)>)>, + pub(super) compounds: HashMap, (Option<(Vec, CW)>, Option<(Vec, CW)>)>, + primitive_weight_marker: PhantomData, +} + +impl< + PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, + DW: AccessDotWeight + GetLayer, + SW: AccessSegWeight + GetLayer, + BW: AccessBendWeight + GetLayer, + CW: Copy, + PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Eq + Hash + Copy, + DI: GetPetgraphIndex + Into + Eq + Hash + Copy, + SI: GetPetgraphIndex + Into + Eq + Hash + Copy, + BI: GetPetgraphIndex + Into + Eq + Hash + Copy, + > GeometryEdit +{ + pub fn new() -> Self { + Self { + dots: HashMap::new(), + segs: HashMap::new(), + bends: HashMap::new(), + compounds: HashMap::new(), + primitive_weight_marker: PhantomData, + } + } +} diff --git a/src/geometry/mod.rs b/src/geometry/mod.rs index 5913872..d6942e8 100644 --- a/src/geometry/mod.rs +++ b/src/geometry/mod.rs @@ -1,6 +1,7 @@ #[macro_use] mod geometry; pub mod compound; +pub mod edit; pub mod poly; pub mod primitive; pub mod recording_with_rtree; diff --git a/src/geometry/recording_with_rtree.rs b/src/geometry/recording_with_rtree.rs index 7c22e0f..99325f3 100644 --- a/src/geometry/recording_with_rtree.rs +++ b/src/geometry/recording_with_rtree.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, hash::Hash, marker::PhantomData}; +use std::hash::Hash; use geo::Point; use petgraph::stable_graph::StableDiGraph; @@ -11,53 +11,12 @@ use crate::{ use super::{ compound::ManageCompounds, + edit::GeometryEdit, with_rtree::{BboxedIndex, GeometryWithRtree}, AccessBendWeight, AccessDotWeight, AccessSegWeight, GenericNode, Geometry, GeometryLabel, GetWidth, }; -#[derive(Debug)] -pub struct GeometryEdit< - PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, - DW: AccessDotWeight + GetLayer, - SW: AccessSegWeight + GetLayer, - BW: AccessBendWeight + GetLayer, - CW: Copy, - PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Eq + Hash + Copy, - DI: GetPetgraphIndex + Into + Eq + Hash + Copy, - SI: GetPetgraphIndex + Into + Eq + Hash + Copy, - BI: GetPetgraphIndex + Into + Eq + Hash + Copy, -> { - dots: HashMap, Option)>, - segs: HashMap, Option<((DI, DI), SW)>)>, - bends: HashMap, Option<((DI, DI, DI), BW)>)>, - compounds: HashMap, (Option<(Vec, CW)>, Option<(Vec, CW)>)>, - primitive_weight_marker: PhantomData, -} - -impl< - PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy, - DW: AccessDotWeight + GetLayer, - SW: AccessSegWeight + GetLayer, - BW: AccessBendWeight + GetLayer, - CW: Copy, - PI: GetPetgraphIndex + TryInto + TryInto + TryInto + Eq + Hash + Copy, - DI: GetPetgraphIndex + Into + Eq + Hash + Copy, - SI: GetPetgraphIndex + Into + Eq + Hash + Copy, - BI: GetPetgraphIndex + Into + Eq + Hash + Copy, - > GeometryEdit -{ - pub fn new() -> Self { - Self { - dots: HashMap::new(), - segs: HashMap::new(), - bends: HashMap::new(), - compounds: HashMap::new(), - primitive_weight_marker: PhantomData, - } - } -} - #[derive(Debug)] pub struct RecordingGeometryWithRtree< PW: GetWidth + GetLayer + TryInto + TryInto + TryInto + Retag + Copy,