mirror of https://codeberg.org/topola/topola.git
geometry: rename `Index` to `GeometryIndex`
This commit is contained in:
parent
d9b94742e4
commit
9007b850c4
|
|
@ -3,16 +3,14 @@ use geo::{EuclideanLength, Point};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
connectivity::{ComponentIndex, GetNet},
|
|
||||||
geometry::{
|
geometry::{
|
||||||
BendIndex, DotIndex, FixedDotIndex, FixedSegWeight, GetBandIndex, GetComponentIndex,
|
BendIndex, DotIndex, FixedDotIndex, GetBandIndex, LoneLooseSegWeight, LooseBendWeight,
|
||||||
LoneLooseSegWeight, LooseBendWeight, LooseDotIndex, LooseDotWeight, MakePrimitive,
|
LooseDotIndex, LooseDotWeight, MakePrimitive, SeqLooseSegWeight, WraparoundableIndex,
|
||||||
SeqLooseSegWeight, WraparoundableIndex,
|
|
||||||
},
|
},
|
||||||
guide::{Guide, Head, HeadTrait, SegbendHead},
|
guide::{Guide, Head, HeadTrait, SegbendHead},
|
||||||
layout::{Infringement, Layout, LayoutException},
|
layout::{Infringement, Layout, LayoutException},
|
||||||
math::{Circle, NoTangents},
|
math::{Circle, NoTangents},
|
||||||
primitive::{GetOtherEnd, GetWeight},
|
primitive::GetOtherEnd,
|
||||||
rules::{Conditions, Rules},
|
rules::{Conditions, Rules},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use enum_dispatch::enum_dispatch;
|
||||||
use petgraph::stable_graph::{NodeIndex, StableDiGraph};
|
use petgraph::stable_graph::{NodeIndex, StableDiGraph};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
connectivity::{BandIndex, BandWeight, ComponentIndex, ComponentWeight, ConnectivityWeight},
|
connectivity::{BandIndex, ComponentIndex},
|
||||||
graph::GenericIndex,
|
graph::GenericIndex,
|
||||||
layout::Layout,
|
layout::Layout,
|
||||||
math::Circle,
|
math::Circle,
|
||||||
|
|
@ -11,7 +11,7 @@ use crate::{
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
pub trait Retag {
|
pub trait Retag {
|
||||||
fn retag(&self, index: NodeIndex<usize>) -> Index;
|
fn retag(&self, index: NodeIndex<usize>) -> GeometryIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
|
|
@ -39,8 +39,8 @@ pub trait GetOffset {
|
||||||
macro_rules! impl_weight {
|
macro_rules! impl_weight {
|
||||||
($weight_struct:ident, $weight_variant:ident, $index_struct:ident) => {
|
($weight_struct:ident, $weight_variant:ident, $index_struct:ident) => {
|
||||||
impl Retag for $weight_struct {
|
impl Retag for $weight_struct {
|
||||||
fn retag(&self, index: NodeIndex<usize>) -> Index {
|
fn retag(&self, index: NodeIndex<usize>) -> GeometryIndex {
|
||||||
Index::$weight_variant($index_struct::new(index))
|
GeometryIndex::$weight_variant($index_struct::new(index))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,7 +100,7 @@ pub enum GeometryWeight {
|
||||||
|
|
||||||
#[enum_dispatch(GetNodeIndex, MakePrimitive)]
|
#[enum_dispatch(GetNodeIndex, MakePrimitive)]
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum Index {
|
pub enum GeometryIndex {
|
||||||
FixedDot(FixedDotIndex),
|
FixedDot(FixedDotIndex),
|
||||||
LooseDot(LooseDotIndex),
|
LooseDot(LooseDotIndex),
|
||||||
FixedSeg(FixedSegIndex),
|
FixedSeg(FixedSegIndex),
|
||||||
|
|
@ -117,11 +117,11 @@ pub enum DotIndex {
|
||||||
Loose(LooseDotIndex),
|
Loose(LooseDotIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<DotIndex> for Index {
|
impl From<DotIndex> for GeometryIndex {
|
||||||
fn from(dot: DotIndex) -> Self {
|
fn from(dot: DotIndex) -> Self {
|
||||||
match dot {
|
match dot {
|
||||||
DotIndex::Fixed(fixed) => Index::FixedDot(fixed),
|
DotIndex::Fixed(fixed) => GeometryIndex::FixedDot(fixed),
|
||||||
DotIndex::Loose(loose) => Index::LooseDot(loose),
|
DotIndex::Loose(loose) => GeometryIndex::LooseDot(loose),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -134,12 +134,12 @@ pub enum SegIndex {
|
||||||
SeqLoose(SeqLooseSegIndex),
|
SeqLoose(SeqLooseSegIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SegIndex> for Index {
|
impl From<SegIndex> for GeometryIndex {
|
||||||
fn from(seg: SegIndex) -> Self {
|
fn from(seg: SegIndex) -> Self {
|
||||||
match seg {
|
match seg {
|
||||||
SegIndex::Fixed(seg) => Index::FixedSeg(seg),
|
SegIndex::Fixed(seg) => GeometryIndex::FixedSeg(seg),
|
||||||
SegIndex::LoneLoose(seg) => Index::LoneLooseSeg(seg),
|
SegIndex::LoneLoose(seg) => GeometryIndex::LoneLooseSeg(seg),
|
||||||
SegIndex::SeqLoose(seg) => Index::SeqLooseSeg(seg),
|
SegIndex::SeqLoose(seg) => GeometryIndex::SeqLooseSeg(seg),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -151,11 +151,11 @@ pub enum BendIndex {
|
||||||
Loose(LooseBendIndex),
|
Loose(LooseBendIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<BendIndex> for Index {
|
impl From<BendIndex> for GeometryIndex {
|
||||||
fn from(bend: BendIndex) -> Self {
|
fn from(bend: BendIndex) -> Self {
|
||||||
match bend {
|
match bend {
|
||||||
BendIndex::Fixed(bend) => Index::FixedBend(bend),
|
BendIndex::Fixed(bend) => GeometryIndex::FixedBend(bend),
|
||||||
BendIndex::Loose(bend) => Index::LooseBend(bend),
|
BendIndex::Loose(bend) => GeometryIndex::LooseBend(bend),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -177,12 +177,12 @@ pub enum WraparoundableIndex {
|
||||||
LooseBend(LooseBendIndex),
|
LooseBend(LooseBendIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<WraparoundableIndex> for Index {
|
impl From<WraparoundableIndex> for GeometryIndex {
|
||||||
fn from(wraparoundable: WraparoundableIndex) -> Self {
|
fn from(wraparoundable: WraparoundableIndex) -> Self {
|
||||||
match wraparoundable {
|
match wraparoundable {
|
||||||
WraparoundableIndex::FixedDot(dot) => Index::FixedDot(dot),
|
WraparoundableIndex::FixedDot(dot) => GeometryIndex::FixedDot(dot),
|
||||||
WraparoundableIndex::FixedBend(bend) => Index::FixedBend(bend),
|
WraparoundableIndex::FixedBend(bend) => GeometryIndex::FixedBend(bend),
|
||||||
WraparoundableIndex::LooseBend(bend) => Index::LooseBend(bend),
|
WraparoundableIndex::LooseBend(bend) => GeometryIndex::LooseBend(bend),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use petgraph::stable_graph::NodeIndex;
|
||||||
|
|
||||||
// Due to apparent limitations of enum_dispatch we're forced to import some types backwards.
|
// Due to apparent limitations of enum_dispatch we're forced to import some types backwards.
|
||||||
|
|
||||||
use crate::geometry::{BendIndex, DotIndex, Index, SegIndex, WraparoundableIndex};
|
use crate::geometry::{BendIndex, DotIndex, GeometryIndex, SegIndex, WraparoundableIndex};
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
pub trait GetNodeIndex {
|
pub trait GetNodeIndex {
|
||||||
|
|
|
||||||
111
src/layout.rs
111
src/layout.rs
|
|
@ -14,10 +14,9 @@ use crate::connectivity::{
|
||||||
};
|
};
|
||||||
use crate::geometry::{
|
use crate::geometry::{
|
||||||
BendWeight, DotIndex, DotWeight, FixedBendIndex, FixedDotIndex, FixedDotWeight, FixedSegIndex,
|
BendWeight, DotIndex, DotWeight, FixedBendIndex, FixedDotIndex, FixedDotWeight, FixedSegIndex,
|
||||||
FixedSegWeight, GeometryGraph, GeometryLabel, GeometryWeight, GetComponentIndex, Index,
|
FixedSegWeight, GeometryGraph, GeometryIndex, GeometryLabel, GeometryWeight, LoneLooseSegIndex,
|
||||||
LoneLooseSegIndex, LoneLooseSegWeight, LooseBendIndex, LooseBendWeight, LooseDotIndex,
|
LoneLooseSegWeight, LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight,
|
||||||
LooseDotWeight, MakePrimitive, Retag, SegWeight, SeqLooseSegIndex, SeqLooseSegWeight,
|
MakePrimitive, Retag, SegWeight, SeqLooseSegIndex, SeqLooseSegWeight, WraparoundableIndex,
|
||||||
WraparoundableIndex,
|
|
||||||
};
|
};
|
||||||
use crate::graph::{GenericIndex, GetNodeIndex};
|
use crate::graph::{GenericIndex, GetNodeIndex};
|
||||||
use crate::guide::Guide;
|
use crate::guide::Guide;
|
||||||
|
|
@ -29,7 +28,7 @@ use crate::primitive::{
|
||||||
use crate::segbend::Segbend;
|
use crate::segbend::Segbend;
|
||||||
use crate::shape::{Shape, ShapeTrait};
|
use crate::shape::{Shape, ShapeTrait};
|
||||||
|
|
||||||
pub type RTreeWrapper = GeomWithData<Shape, Index>;
|
pub type RTreeWrapper = GeomWithData<Shape, GeometryIndex>;
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
#[derive(Error, Debug, Clone, Copy)]
|
#[derive(Error, Debug, Clone, Copy)]
|
||||||
|
|
@ -47,15 +46,15 @@ pub enum LayoutException {
|
||||||
// TODO add real error messages + these should eventually use Display
|
// TODO add real error messages + these should eventually use Display
|
||||||
#[derive(Error, Debug, Clone, Copy)]
|
#[derive(Error, Debug, Clone, Copy)]
|
||||||
#[error("{0:?} infringes on {1:?}")]
|
#[error("{0:?} infringes on {1:?}")]
|
||||||
pub struct Infringement(pub Shape, pub Index);
|
pub struct Infringement(pub Shape, pub GeometryIndex);
|
||||||
|
|
||||||
#[derive(Error, Debug, Clone, Copy)]
|
#[derive(Error, Debug, Clone, Copy)]
|
||||||
#[error("{0:?} collides with {1:?}")]
|
#[error("{0:?} collides with {1:?}")]
|
||||||
pub struct Collision(pub Shape, pub Index);
|
pub struct Collision(pub Shape, pub GeometryIndex);
|
||||||
|
|
||||||
#[derive(Error, Debug, Clone, Copy)]
|
#[derive(Error, Debug, Clone, Copy)]
|
||||||
#[error("{1:?} is already connected to net {0}")]
|
#[error("{1:?} is already connected to net {0}")]
|
||||||
pub struct AlreadyConnected(pub i64, pub Index);
|
pub struct AlreadyConnected(pub i64, pub GeometryIndex);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Layout {
|
pub struct Layout {
|
||||||
|
|
@ -99,12 +98,12 @@ impl Layout {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count() - 1))]
|
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count() - 1))]
|
||||||
fn remove(&mut self, index: Index) {
|
fn remove(&mut self, node: GeometryIndex) {
|
||||||
// Unnecessary retag. It should be possible to elide it.
|
// Unnecessary retag. It should be possible to elide it.
|
||||||
let weight = *self.geometry.node_weight(index.node_index()).unwrap();
|
let weight = *self.geometry.node_weight(node.node_index()).unwrap();
|
||||||
|
|
||||||
self.remove_from_rtree(weight.retag(index.node_index()));
|
self.remove_from_rtree(weight.retag(node.node_index()));
|
||||||
self.geometry.remove_node(index.node_index());
|
self.geometry.remove_node(node.node_index());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This method shouldn't be public.
|
// TODO: This method shouldn't be public.
|
||||||
|
|
@ -149,10 +148,10 @@ impl Layout {
|
||||||
fn add_dot_infringably<W: DotWeight>(
|
fn add_dot_infringably<W: DotWeight>(
|
||||||
&mut self,
|
&mut self,
|
||||||
weight: W,
|
weight: W,
|
||||||
infringables: &[Index],
|
infringables: &[GeometryIndex],
|
||||||
) -> Result<GenericIndex<W>, Infringement>
|
) -> Result<GenericIndex<W>, Infringement>
|
||||||
where
|
where
|
||||||
GenericIndex<W>: Into<Index> + Copy,
|
GenericIndex<W>: Into<GeometryIndex> + Copy,
|
||||||
{
|
{
|
||||||
let dot = GenericIndex::<W>::new(self.geometry.add_node(weight.into()));
|
let dot = GenericIndex::<W>::new(self.geometry.add_node(weight.into()));
|
||||||
|
|
||||||
|
|
@ -228,7 +227,7 @@ impl Layout {
|
||||||
|
|
||||||
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||||
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||||
fn inner_bow_and_outer_bow(&self, bend: LooseBendIndex) -> Vec<Index> {
|
fn inner_bow_and_outer_bow(&self, bend: LooseBendIndex) -> Vec<GeometryIndex> {
|
||||||
let bend_primitive = self.primitive(bend);
|
let bend_primitive = self.primitive(bend);
|
||||||
let mut v = vec![];
|
let mut v = vec![];
|
||||||
|
|
||||||
|
|
@ -248,7 +247,7 @@ impl Layout {
|
||||||
|
|
||||||
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||||
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||||
fn inner_bow_and_outer_bows(&self, bend: LooseBendIndex) -> Vec<Index> {
|
fn inner_bow_and_outer_bows(&self, bend: LooseBendIndex) -> Vec<GeometryIndex> {
|
||||||
let bend_primitive = self.primitive(bend);
|
let bend_primitive = self.primitive(bend);
|
||||||
let mut v = vec![];
|
let mut v = vec![];
|
||||||
|
|
||||||
|
|
@ -271,7 +270,7 @@ impl Layout {
|
||||||
|
|
||||||
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||||
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||||
fn this_and_wraparound_bow(&self, around: WraparoundableIndex) -> Vec<Index> {
|
fn this_and_wraparound_bow(&self, around: WraparoundableIndex) -> Vec<GeometryIndex> {
|
||||||
match around {
|
match around {
|
||||||
WraparoundableIndex::FixedDot(dot) => {
|
WraparoundableIndex::FixedDot(dot) => {
|
||||||
let mut v = vec![around.into()];
|
let mut v = vec![around.into()];
|
||||||
|
|
@ -300,8 +299,8 @@ impl Layout {
|
||||||
// XXX: Move this to primitives?
|
// XXX: Move this to primitives?
|
||||||
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||||
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||||
fn bow(&self, bend: LooseBendIndex) -> Vec<Index> {
|
fn bow(&self, bend: LooseBendIndex) -> Vec<GeometryIndex> {
|
||||||
let mut bow: Vec<Index> = vec![];
|
let mut bow: Vec<GeometryIndex> = vec![];
|
||||||
bow.push(bend.into());
|
bow.push(bend.into());
|
||||||
|
|
||||||
let ends = self.primitive(bend).ends();
|
let ends = self.primitive(bend).ends();
|
||||||
|
|
@ -321,7 +320,7 @@ impl Layout {
|
||||||
|
|
||||||
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||||
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||||
fn outer_bows(&self, bend: LooseBendIndex) -> Vec<Index> {
|
fn outer_bows(&self, bend: LooseBendIndex) -> Vec<GeometryIndex> {
|
||||||
let mut outer_bows = vec![];
|
let mut outer_bows = vec![];
|
||||||
let mut rail = bend;
|
let mut rail = bend;
|
||||||
|
|
||||||
|
|
@ -473,7 +472,7 @@ impl Layout {
|
||||||
dot_weight: LooseDotWeight,
|
dot_weight: LooseDotWeight,
|
||||||
seg_weight: SeqLooseSegWeight,
|
seg_weight: SeqLooseSegWeight,
|
||||||
bend_weight: LooseBendWeight,
|
bend_weight: LooseBendWeight,
|
||||||
infringables: &[Index],
|
infringables: &[GeometryIndex],
|
||||||
) -> Result<Segbend, LayoutException> {
|
) -> Result<Segbend, LayoutException> {
|
||||||
let seg_to = self.add_dot_infringably(dot_weight, infringables)?;
|
let seg_to = self.add_dot_infringably(dot_weight, infringables)?;
|
||||||
let seg = self
|
let seg = self
|
||||||
|
|
@ -541,10 +540,10 @@ impl Layout {
|
||||||
from: impl GetNodeIndex,
|
from: impl GetNodeIndex,
|
||||||
to: impl GetNodeIndex,
|
to: impl GetNodeIndex,
|
||||||
weight: W,
|
weight: W,
|
||||||
infringables: &[Index],
|
infringables: &[GeometryIndex],
|
||||||
) -> Result<GenericIndex<W>, Infringement>
|
) -> Result<GenericIndex<W>, Infringement>
|
||||||
where
|
where
|
||||||
GenericIndex<W>: Into<Index> + Copy,
|
GenericIndex<W>: Into<GeometryIndex> + Copy,
|
||||||
{
|
{
|
||||||
let seg = GenericIndex::<W>::new(self.geometry.add_node(weight.into()));
|
let seg = GenericIndex::<W>::new(self.geometry.add_node(weight.into()));
|
||||||
|
|
||||||
|
|
@ -565,12 +564,12 @@ impl Layout {
|
||||||
&mut self,
|
&mut self,
|
||||||
from: FixedDotIndex,
|
from: FixedDotIndex,
|
||||||
to: FixedDotIndex,
|
to: FixedDotIndex,
|
||||||
around: Index,
|
around: GeometryIndex,
|
||||||
weight: FixedBendWeight,
|
weight: FixedBendWeight,
|
||||||
) -> Result<FixedBendIndex, ()> {
|
) -> Result<FixedBendIndex, ()> {
|
||||||
match around {
|
match around {
|
||||||
Index::FixedDot(core) => self.add_core_bend(from, to, core, weight),
|
GeometryIndex::FixedDot(core) => self.add_core_bend(from, to, core, weight),
|
||||||
Index::FixedBend(around) => self.add_outer_bend(from, to, around, weight),
|
GeometryIndex::FixedBend(around) => self.add_outer_bend(from, to, around, weight),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
@ -586,7 +585,7 @@ impl Layout {
|
||||||
to: LooseDotIndex,
|
to: LooseDotIndex,
|
||||||
around: WraparoundableIndex,
|
around: WraparoundableIndex,
|
||||||
weight: LooseBendWeight,
|
weight: LooseBendWeight,
|
||||||
infringables: &[Index],
|
infringables: &[GeometryIndex],
|
||||||
) -> Result<LooseBendIndex, LayoutException> {
|
) -> Result<LooseBendIndex, LayoutException> {
|
||||||
// It makes no sense to wrap something around or under one of its connectables.
|
// It makes no sense to wrap something around or under one of its connectables.
|
||||||
let net = self
|
let net = self
|
||||||
|
|
@ -632,10 +631,10 @@ impl Layout {
|
||||||
to: impl GetNodeIndex,
|
to: impl GetNodeIndex,
|
||||||
core: FixedDotIndex,
|
core: FixedDotIndex,
|
||||||
weight: W,
|
weight: W,
|
||||||
infringables: &[Index],
|
infringables: &[GeometryIndex],
|
||||||
) -> Result<LooseBendIndex, Infringement>
|
) -> Result<LooseBendIndex, Infringement>
|
||||||
where
|
where
|
||||||
GenericIndex<W>: Into<Index> + Copy,
|
GenericIndex<W>: Into<GeometryIndex> + Copy,
|
||||||
{
|
{
|
||||||
let bend = LooseBendIndex::new(self.geometry.add_node(weight.into()));
|
let bend = LooseBendIndex::new(self.geometry.add_node(weight.into()));
|
||||||
|
|
||||||
|
|
@ -664,7 +663,7 @@ impl Layout {
|
||||||
to: impl GetNodeIndex,
|
to: impl GetNodeIndex,
|
||||||
inner: impl GetNodeIndex,
|
inner: impl GetNodeIndex,
|
||||||
weight: W,
|
weight: W,
|
||||||
infringables: &[Index],
|
infringables: &[GeometryIndex],
|
||||||
) -> Result<LooseBendIndex, Infringement> {
|
) -> Result<LooseBendIndex, Infringement> {
|
||||||
let core = *self
|
let core = *self
|
||||||
.geometry
|
.geometry
|
||||||
|
|
@ -730,17 +729,17 @@ impl Layout {
|
||||||
#[debug_ensures(ret.is_err() -> self.geometry.node_count() == old(self.geometry.node_count() - 1))]
|
#[debug_ensures(ret.is_err() -> self.geometry.node_count() == old(self.geometry.node_count() - 1))]
|
||||||
fn fail_and_remove_if_infringes_except(
|
fn fail_and_remove_if_infringes_except(
|
||||||
&mut self,
|
&mut self,
|
||||||
index: Index,
|
node: GeometryIndex,
|
||||||
except: &[Index],
|
except: &[GeometryIndex],
|
||||||
) -> Result<(), Infringement> {
|
) -> Result<(), Infringement> {
|
||||||
if let Some(infringement) = self.detect_infringement_except(index, except) {
|
if let Some(infringement) = self.detect_infringement_except(node, except) {
|
||||||
self.remove(index);
|
self.remove(node);
|
||||||
return Err(infringement);
|
return Err(infringement);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nodes(&self) -> impl Iterator<Item = Index> + '_ {
|
pub fn nodes(&self) -> impl Iterator<Item = GeometryIndex> + '_ {
|
||||||
self.rtree.iter().map(|wrapper| wrapper.data)
|
self.rtree.iter().map(|wrapper| wrapper.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -752,7 +751,7 @@ impl Layout {
|
||||||
self.geometry.node_count()
|
self.geometry.node_count()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn node_indices(&self) -> impl Iterator<Item = Index> + '_ {
|
fn node_indices(&self) -> impl Iterator<Item = GeometryIndex> + '_ {
|
||||||
self.rtree.iter().map(|wrapper| wrapper.data)
|
self.rtree.iter().map(|wrapper| wrapper.data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -773,7 +772,7 @@ impl Layout {
|
||||||
&mut self,
|
&mut self,
|
||||||
dot: LooseDotIndex,
|
dot: LooseDotIndex,
|
||||||
to: Point,
|
to: Point,
|
||||||
infringables: &[Index],
|
infringables: &[GeometryIndex],
|
||||||
) -> Result<(), Infringement> {
|
) -> Result<(), Infringement> {
|
||||||
self.primitive(dot)
|
self.primitive(dot)
|
||||||
.seg()
|
.seg()
|
||||||
|
|
@ -812,14 +811,18 @@ impl Layout {
|
||||||
|
|
||||||
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||||
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||||
fn detect_infringement_except(&self, index: Index, except: &[Index]) -> Option<Infringement> {
|
fn detect_infringement_except(
|
||||||
let shape = index.primitive(self).shape();
|
&self,
|
||||||
|
node: GeometryIndex,
|
||||||
|
except: &[GeometryIndex],
|
||||||
|
) -> Option<Infringement> {
|
||||||
|
let shape = node.primitive(self).shape();
|
||||||
|
|
||||||
self.rtree
|
self.rtree
|
||||||
.locate_in_envelope_intersecting(&RTreeObject::envelope(&shape))
|
.locate_in_envelope_intersecting(&RTreeObject::envelope(&shape))
|
||||||
.filter(|wrapper| {
|
.filter(|wrapper| {
|
||||||
let other_index = wrapper.data;
|
let other_index = wrapper.data;
|
||||||
!index.primitive(self).connectable(other_index)
|
!node.primitive(self).connectable(other_index)
|
||||||
})
|
})
|
||||||
.filter(|wrapper| !except.contains(&wrapper.data))
|
.filter(|wrapper| !except.contains(&wrapper.data))
|
||||||
.filter(|wrapper| shape.intersects(wrapper.geom()))
|
.filter(|wrapper| shape.intersects(wrapper.geom()))
|
||||||
|
|
@ -831,14 +834,14 @@ impl Layout {
|
||||||
// TODO: Collision and infringement are the same for now. Change this.
|
// TODO: Collision and infringement are the same for now. Change this.
|
||||||
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||||
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||||
fn detect_collision(&self, index: Index) -> Option<Collision> {
|
fn detect_collision(&self, node: GeometryIndex) -> Option<Collision> {
|
||||||
let shape = index.primitive(self).shape();
|
let shape = node.primitive(self).shape();
|
||||||
|
|
||||||
self.rtree
|
self.rtree
|
||||||
.locate_in_envelope_intersecting(&RTreeObject::envelope(&shape))
|
.locate_in_envelope_intersecting(&RTreeObject::envelope(&shape))
|
||||||
.filter(|wrapper| {
|
.filter(|wrapper| {
|
||||||
let other_index = wrapper.data;
|
let other_index = wrapper.data;
|
||||||
!index.primitive(self).connectable(other_index)
|
!node.primitive(self).connectable(other_index)
|
||||||
})
|
})
|
||||||
.filter(|wrapper| shape.intersects(wrapper.geom()))
|
.filter(|wrapper| shape.intersects(wrapper.geom()))
|
||||||
.map(|wrapper| wrapper.data)
|
.map(|wrapper| wrapper.data)
|
||||||
|
|
@ -848,16 +851,16 @@ impl Layout {
|
||||||
|
|
||||||
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||||
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||||
fn insert_into_rtree(&mut self, index: Index) {
|
fn insert_into_rtree(&mut self, node: GeometryIndex) {
|
||||||
let shape = index.primitive(self).shape();
|
let shape = node.primitive(self).shape();
|
||||||
self.rtree.insert(RTreeWrapper::new(shape, index));
|
self.rtree.insert(RTreeWrapper::new(shape, node));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||||
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||||
fn remove_from_rtree(&mut self, index: Index) {
|
fn remove_from_rtree(&mut self, node: GeometryIndex) {
|
||||||
let shape = index.primitive(self).shape();
|
let shape = node.primitive(self).shape();
|
||||||
let removed_element = self.rtree.remove(&RTreeWrapper::new(shape, index));
|
let removed_element = self.rtree.remove(&RTreeWrapper::new(shape, node));
|
||||||
debug_assert!(removed_element.is_some());
|
debug_assert!(removed_element.is_some());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -877,15 +880,15 @@ impl Layout {
|
||||||
|
|
||||||
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||||
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||||
pub fn primitive<W>(&self, index: GenericIndex<W>) -> GenericPrimitive<W> {
|
pub fn primitive<W>(&self, node: GenericIndex<W>) -> GenericPrimitive<W> {
|
||||||
GenericPrimitive::new(index, self)
|
GenericPrimitive::new(node, self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_envelopes(&self) -> bool {
|
fn test_envelopes(&self) -> bool {
|
||||||
!self.rtree.iter().any(|wrapper| {
|
!self.rtree.iter().any(|wrapper| {
|
||||||
let index = wrapper.data;
|
let node = wrapper.data;
|
||||||
let shape = index.primitive(self).shape();
|
let shape = node.primitive(self).shape();
|
||||||
let wrapper = RTreeWrapper::new(shape, index);
|
let wrapper = RTreeWrapper::new(shape, node);
|
||||||
!self
|
!self
|
||||||
.rtree
|
.rtree
|
||||||
.locate_in_envelope(&RTreeObject::envelope(&shape))
|
.locate_in_envelope(&RTreeObject::envelope(&shape))
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ mod triangulation;
|
||||||
|
|
||||||
use draw::DrawException;
|
use draw::DrawException;
|
||||||
use geo::point;
|
use geo::point;
|
||||||
use geometry::{FixedDotIndex, FixedSegWeight, Index, LooseDotIndex, MakePrimitive};
|
use geometry::{FixedDotIndex, FixedSegWeight, GeometryIndex, LooseDotIndex, MakePrimitive};
|
||||||
use layout::{Infringement, Layout, LayoutException};
|
use layout::{Infringement, Layout, LayoutException};
|
||||||
use mesh::{Mesh, MeshEdgeReference, VertexIndex};
|
use mesh::{Mesh, MeshEdgeReference, VertexIndex};
|
||||||
use petgraph::visit::{EdgeRef, IntoEdgeReferences};
|
use petgraph::visit::{EdgeRef, IntoEdgeReferences};
|
||||||
|
|
@ -582,7 +582,7 @@ fn render_times(
|
||||||
mut mesh: Option<Mesh>,
|
mut mesh: Option<Mesh>,
|
||||||
path: &[VertexIndex],
|
path: &[VertexIndex],
|
||||||
ghosts: &[Shape],
|
ghosts: &[Shape],
|
||||||
highlighteds: &[Index],
|
highlighteds: &[GeometryIndex],
|
||||||
times: i64,
|
times: i64,
|
||||||
) {
|
) {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use spade::{HasPosition, InsertionError, Point2};
|
||||||
use crate::primitive::{GetCore, Primitive};
|
use crate::primitive::{GetCore, Primitive};
|
||||||
use crate::triangulation::TriangulationEdgeReference;
|
use crate::triangulation::TriangulationEdgeReference;
|
||||||
use crate::{
|
use crate::{
|
||||||
geometry::{FixedBendIndex, FixedDotIndex, Index, LooseBendIndex, MakePrimitive},
|
geometry::{FixedBendIndex, FixedDotIndex, GeometryIndex, LooseBendIndex, MakePrimitive},
|
||||||
graph::GetNodeIndex,
|
graph::GetNodeIndex,
|
||||||
layout::Layout,
|
layout::Layout,
|
||||||
primitive::MakeShape,
|
primitive::MakeShape,
|
||||||
|
|
@ -84,14 +84,14 @@ impl Mesh {
|
||||||
let center = node.primitive(layout).shape().center();
|
let center = node.primitive(layout).shape().center();
|
||||||
|
|
||||||
match node {
|
match node {
|
||||||
Index::FixedDot(dot) => {
|
GeometryIndex::FixedDot(dot) => {
|
||||||
self.triangulation.add_vertex(TriangulationWeight {
|
self.triangulation.add_vertex(TriangulationWeight {
|
||||||
vertex: dot.into(),
|
vertex: dot.into(),
|
||||||
rails: vec![],
|
rails: vec![],
|
||||||
pos: center,
|
pos: center,
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
Index::FixedBend(bend) => {
|
GeometryIndex::FixedBend(bend) => {
|
||||||
self.triangulation.add_vertex(TriangulationWeight {
|
self.triangulation.add_vertex(TriangulationWeight {
|
||||||
vertex: bend.into(),
|
vertex: bend.into(),
|
||||||
rails: vec![],
|
rails: vec![],
|
||||||
|
|
@ -105,7 +105,7 @@ impl Mesh {
|
||||||
for node in layout.nodes() {
|
for node in layout.nodes() {
|
||||||
// Add rails as vertices. This is how the mesh differs from the triangulation.
|
// Add rails as vertices. This is how the mesh differs from the triangulation.
|
||||||
match node {
|
match node {
|
||||||
Index::LooseBend(bend) => {
|
GeometryIndex::LooseBend(bend) => {
|
||||||
self.triangulation
|
self.triangulation
|
||||||
.weight_mut(layout.primitive(bend).core().into())
|
.weight_mut(layout.primitive(bend).core().into())
|
||||||
.rails
|
.rails
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ use petgraph::Direction::{Incoming, Outgoing};
|
||||||
|
|
||||||
use crate::connectivity::GetNet;
|
use crate::connectivity::GetNet;
|
||||||
use crate::geometry::{
|
use crate::geometry::{
|
||||||
DotIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight, FixedSegWeight, GeometryLabel,
|
DotIndex, FixedBendWeight, FixedDotIndex, FixedDotWeight, FixedSegWeight, GeometryIndex,
|
||||||
GeometryWeight, GetBandIndex, GetComponentIndex, GetOffset, GetWidth, Index,
|
GeometryLabel, GeometryWeight, GetBandIndex, GetComponentIndex, GetOffset, GetWidth,
|
||||||
LoneLooseSegWeight, LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight,
|
LoneLooseSegWeight, LooseBendIndex, LooseBendWeight, LooseDotIndex, LooseDotWeight,
|
||||||
MakePrimitive, Retag, SeqLooseSegIndex, SeqLooseSegWeight,
|
MakePrimitive, Retag, SeqLooseSegIndex, SeqLooseSegWeight,
|
||||||
};
|
};
|
||||||
|
|
@ -23,9 +23,9 @@ pub trait GetLayout {
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
pub trait GetConnectable: GetNet + GetLayout {
|
pub trait GetConnectable: GetNet + GetLayout {
|
||||||
fn connectable(&self, index: Index) -> bool {
|
fn connectable(&self, node: GeometryIndex) -> bool {
|
||||||
let this = self.net();
|
let this = self.net();
|
||||||
let other = index.primitive(self.layout()).net();
|
let other = node.primitive(self.layout()).net();
|
||||||
|
|
||||||
(this == other) || this == -1 || other == -1
|
(this == other) || this == -1 || other == -1
|
||||||
}
|
}
|
||||||
|
|
@ -262,8 +262,8 @@ impl<'a, W> GenericPrimitive<'a, W> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, W> GetInterior<Index> for GenericPrimitive<'a, W> {
|
impl<'a, W> GetInterior<GeometryIndex> for GenericPrimitive<'a, W> {
|
||||||
fn interior(&self) -> Vec<Index> {
|
fn interior(&self) -> Vec<GeometryIndex> {
|
||||||
vec![self.tagged_weight().retag(self.index.node_index())]
|
vec![self.tagged_weight().retag(self.index.node_index())]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
geometry::{Index, LooseBendIndex, LooseDotIndex, SeqLooseSegIndex},
|
geometry::{GeometryIndex, LooseBendIndex, LooseDotIndex, SeqLooseSegIndex},
|
||||||
layout::Layout,
|
layout::Layout,
|
||||||
primitive::{GetEnds, GetInterior, GetOtherEnd, LooseBend, LooseDot},
|
primitive::{GetEnds, GetInterior, GetOtherEnd, LooseBend, LooseDot},
|
||||||
};
|
};
|
||||||
|
|
@ -20,8 +20,8 @@ impl Segbend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GetInterior<Index> for Segbend {
|
impl GetInterior<GeometryIndex> for Segbend {
|
||||||
fn interior(&self) -> Vec<Index> {
|
fn interior(&self) -> Vec<GeometryIndex> {
|
||||||
vec![self.bend.into(), self.dot.into(), self.seg.into()]
|
vec![self.bend.into(), self.dot.into(), self.seg.into()]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue