mirror of https://codeberg.org/topola/topola.git
refactor(drawing/query): Rename collect.rs to query.rs, change trait to direct impl
This commit is contained in:
parent
6cb01dbb2a
commit
ca4a2d1cbf
|
|
@ -33,7 +33,6 @@ allowed_scopes = [
|
||||||
"drawing/band",
|
"drawing/band",
|
||||||
"drawing/bend",
|
"drawing/bend",
|
||||||
"drawing/cane",
|
"drawing/cane",
|
||||||
"drawing/collect",
|
|
||||||
"drawing/dot",
|
"drawing/dot",
|
||||||
"drawing/drawing",
|
"drawing/drawing",
|
||||||
"drawing/gear",
|
"drawing/gear",
|
||||||
|
|
@ -42,6 +41,7 @@ allowed_scopes = [
|
||||||
"drawing/head",
|
"drawing/head",
|
||||||
"drawing/loose",
|
"drawing/loose",
|
||||||
"drawing/primitive",
|
"drawing/primitive",
|
||||||
|
"drawing/query",
|
||||||
"drawing/seg",
|
"drawing/seg",
|
||||||
"geometry/compound",
|
"geometry/compound",
|
||||||
"geometry/edit",
|
"geometry/edit",
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ use crate::{
|
||||||
edit::{BoardDataEdit, BoardEdit},
|
edit::{BoardDataEdit, BoardEdit},
|
||||||
AccessMesadata,
|
AccessMesadata,
|
||||||
},
|
},
|
||||||
drawing::{band::BandTermsegIndex, graph::PrimitiveIndex, Collect},
|
drawing::{band::BandTermsegIndex, graph::PrimitiveIndex},
|
||||||
geometry::{edit::Edit, primitive::PrimitiveShape},
|
geometry::{edit::Edit, primitive::PrimitiveShape},
|
||||||
graph::MakeRef,
|
graph::MakeRef,
|
||||||
layout::LayoutEdit,
|
layout::LayoutEdit,
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,7 @@ use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
board::{AccessMesadata, BandName, Board, ResolvedSelector},
|
board::{AccessMesadata, BandName, Board, ResolvedSelector},
|
||||||
drawing::{
|
drawing::graph::{MakePrimitive, PrimitiveIndex},
|
||||||
graph::{MakePrimitive, PrimitiveIndex},
|
|
||||||
Collect,
|
|
||||||
},
|
|
||||||
geometry::{
|
geometry::{
|
||||||
shape::{AccessShape, Shape},
|
shape::{AccessShape, Shape},
|
||||||
GenericNode, GetLayer,
|
GenericNode, GetLayer,
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ use crate::{
|
||||||
dot::{FixedDotIndex, FixedDotWeight},
|
dot::{FixedDotIndex, FixedDotWeight},
|
||||||
graph::PrimitiveIndex,
|
graph::PrimitiveIndex,
|
||||||
seg::{FixedSegIndex, FixedSegWeight},
|
seg::{FixedSegIndex, FixedSegWeight},
|
||||||
Collect, DrawingException,
|
DrawingException,
|
||||||
},
|
},
|
||||||
geometry::{edit::ApplyGeometryEdit, GenericNode, GetLayer},
|
geometry::{edit::ApplyGeometryEdit, GenericNode, GetLayer},
|
||||||
graph::{GenericIndex, MakeRef},
|
graph::{GenericIndex, MakeRef},
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ use crate::{
|
||||||
band::BandTermsegIndex,
|
band::BandTermsegIndex,
|
||||||
bend::{BendIndex, BendWeight, FixedBendIndex, LooseBendIndex, LooseBendWeight},
|
bend::{BendIndex, BendWeight, FixedBendIndex, LooseBendIndex, LooseBendWeight},
|
||||||
cane::Cane,
|
cane::Cane,
|
||||||
collect::Collect,
|
|
||||||
dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
|
dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight, LooseDotIndex, LooseDotWeight},
|
||||||
gear::GearIndex,
|
gear::GearIndex,
|
||||||
graph::{GetMaybeNet, IsInLayer, MakePrimitive, PrimitiveIndex, PrimitiveWeight},
|
graph::{GetMaybeNet, IsInLayer, MakePrimitive, PrimitiveIndex, PrimitiveWeight},
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ pub mod graph;
|
||||||
pub mod band;
|
pub mod band;
|
||||||
pub mod bend;
|
pub mod bend;
|
||||||
mod cane;
|
mod cane;
|
||||||
mod collect;
|
|
||||||
pub mod dot;
|
pub mod dot;
|
||||||
mod drawing;
|
mod drawing;
|
||||||
pub mod gear;
|
pub mod gear;
|
||||||
|
|
@ -15,9 +14,9 @@ pub mod guide;
|
||||||
pub mod head;
|
pub mod head;
|
||||||
pub mod loose;
|
pub mod loose;
|
||||||
pub mod primitive;
|
pub mod primitive;
|
||||||
|
mod query;
|
||||||
pub use specctra_core::rules;
|
pub use specctra_core::rules;
|
||||||
pub mod seg;
|
pub mod seg;
|
||||||
|
|
||||||
pub use cane::Cane;
|
pub use cane::Cane;
|
||||||
pub use collect::Collect;
|
|
||||||
pub use drawing::*;
|
pub use drawing::*;
|
||||||
|
|
|
||||||
|
|
@ -21,16 +21,10 @@ pub struct BandUidError {
|
||||||
pub maybe_end: Option<BandTermsegIndex>,
|
pub maybe_end: Option<BandTermsegIndex>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Collect {
|
/// Routines implementing various queries on drawing. A query is a routine that
|
||||||
fn loose_band_uid(&self, start_loose: LooseIndex) -> Result<BandUid, BandUidError>;
|
/// returns indices of one or more primitives.
|
||||||
|
impl<CW: Clone, Cel: Copy, R: AccessRules> Drawing<CW, Cel, R> {
|
||||||
fn bend_bow(&self, bend: LooseBendIndex) -> Vec<PrimitiveIndex>;
|
pub fn loose_band_uid(&self, start_loose: LooseIndex) -> Result<BandUid, BandUidError> {
|
||||||
|
|
||||||
fn bend_outward_bows(&self, bend: LooseBendIndex) -> Vec<PrimitiveIndex>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<CW: Clone, Cel: Copy, R: AccessRules> Collect for Drawing<CW, Cel, R> {
|
|
||||||
fn loose_band_uid(&self, start_loose: LooseIndex) -> Result<BandUid, BandUidError> {
|
|
||||||
match (
|
match (
|
||||||
self.loose_band_first_seg(start_loose),
|
self.loose_band_first_seg(start_loose),
|
||||||
self.loose_band_last_seg(start_loose),
|
self.loose_band_last_seg(start_loose),
|
||||||
|
|
@ -41,6 +35,17 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Collect for Drawing<CW, Cel, R> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn bend_outward_bows(&self, bend: LooseBendIndex) -> Vec<PrimitiveIndex> {
|
||||||
|
let mut v = vec![];
|
||||||
|
|
||||||
|
let mut outwards = self.primitive(bend).outwards();
|
||||||
|
while let Some(next) = outwards.walk_next(self) {
|
||||||
|
v.append(&mut self.bend_bow(next));
|
||||||
|
}
|
||||||
|
|
||||||
|
v
|
||||||
|
}
|
||||||
|
|
||||||
fn bend_bow(&self, bend: LooseBendIndex) -> Vec<PrimitiveIndex> {
|
fn bend_bow(&self, bend: LooseBendIndex) -> Vec<PrimitiveIndex> {
|
||||||
let mut v: Vec<PrimitiveIndex> = vec![];
|
let mut v: Vec<PrimitiveIndex> = vec![];
|
||||||
v.push(bend.into());
|
v.push(bend.into());
|
||||||
|
|
@ -60,24 +65,6 @@ impl<CW: Clone, Cel: Copy, R: AccessRules> Collect for Drawing<CW, Cel, R> {
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bend_outward_bows(&self, bend: LooseBendIndex) -> Vec<PrimitiveIndex> {
|
|
||||||
let mut v = vec![];
|
|
||||||
|
|
||||||
let mut outwards = self.primitive(bend).outwards();
|
|
||||||
while let Some(next) = outwards.walk_next(self) {
|
|
||||||
v.append(&mut self.bend_bow(next));
|
|
||||||
}
|
|
||||||
|
|
||||||
v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
trait CollectPrivate {
|
|
||||||
fn loose_band_first_seg(&self, start_loose: LooseIndex) -> Option<BandTermsegIndex>;
|
|
||||||
fn loose_band_last_seg(&self, start_loose: LooseIndex) -> Option<BandTermsegIndex>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<CW: Clone, Cel: Copy, R: AccessRules> CollectPrivate for Drawing<CW, Cel, R> {
|
|
||||||
fn loose_band_first_seg(&self, start_loose: LooseIndex) -> Option<BandTermsegIndex> {
|
fn loose_band_first_seg(&self, start_loose: LooseIndex) -> Option<BandTermsegIndex> {
|
||||||
if let LooseIndex::LoneSeg(seg) = start_loose {
|
if let LooseIndex::LoneSeg(seg) = start_loose {
|
||||||
return Some(BandTermsegIndex::Lone(seg));
|
return Some(BandTermsegIndex::Lone(seg));
|
||||||
|
|
@ -16,7 +16,6 @@ use crate::{
|
||||||
loose::LooseIndex,
|
loose::LooseIndex,
|
||||||
primitive::MakePrimitiveShape,
|
primitive::MakePrimitiveShape,
|
||||||
rules::AccessRules,
|
rules::AccessRules,
|
||||||
Collect,
|
|
||||||
},
|
},
|
||||||
geometry::{
|
geometry::{
|
||||||
compound::ManageCompounds,
|
compound::ManageCompounds,
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ use crate::{
|
||||||
head::{BareHead, GetFace as _, Head},
|
head::{BareHead, GetFace as _, Head},
|
||||||
primitive::MakePrimitiveShape as _,
|
primitive::MakePrimitiveShape as _,
|
||||||
rules::AccessRules,
|
rules::AccessRules,
|
||||||
Collect,
|
|
||||||
},
|
},
|
||||||
geometry::{primitive::PrimitiveShape, shape::AccessShape as _, shape::MeasureLength as _},
|
geometry::{primitive::PrimitiveShape, shape::AccessShape as _, shape::MeasureLength as _},
|
||||||
graph::{GenericIndex, GetPetgraphIndex as _},
|
graph::{GenericIndex, GetPetgraphIndex as _},
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ use crate::{
|
||||||
head::{CaneHead, GetFace as _, Head},
|
head::{CaneHead, GetFace as _, Head},
|
||||||
primitive::MakePrimitiveShape as _,
|
primitive::MakePrimitiveShape as _,
|
||||||
rules::AccessRules,
|
rules::AccessRules,
|
||||||
Collect as _,
|
|
||||||
},
|
},
|
||||||
geometry::{
|
geometry::{
|
||||||
edit::ApplyGeometryEdit as _,
|
edit::ApplyGeometryEdit as _,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue