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