layout: don't fail on infringement when adding fixed primitives

This commit is contained in:
Mikolaj Wielgus 2024-03-15 21:21:29 +00:00
parent 74d10f4a9e
commit 5a3ed6adab
1 changed files with 26 additions and 26 deletions

View File

@ -171,7 +171,7 @@ impl<R: RulesTrait> Layout<R> {
#[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))] #[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))]
#[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))] #[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
pub fn add_fixed_dot(&mut self, weight: FixedDotWeight) -> Result<FixedDotIndex, Infringement> { pub fn add_fixed_dot(&mut self, weight: FixedDotWeight) -> Result<FixedDotIndex, Infringement> {
self.add_dot_infringably(weight, &[]) self.add_dot_infringably(weight, None)
} }
#[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))] #[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))]
@ -179,7 +179,7 @@ impl<R: RulesTrait> Layout<R> {
fn add_dot_infringably<W: DotWeightTrait<GeometryWeight> + GetLayer>( fn add_dot_infringably<W: DotWeightTrait<GeometryWeight> + GetLayer>(
&mut self, &mut self,
weight: W, weight: W,
infringables: &[GeometryIndex], infringables: Option<&[GeometryIndex]>,
) -> Result<GenericIndex<W>, Infringement> ) -> Result<GenericIndex<W>, Infringement>
where where
GenericIndex<W>: Into<GeometryIndex> + Copy, GenericIndex<W>: Into<GeometryIndex> + Copy,
@ -200,7 +200,7 @@ impl<R: RulesTrait> Layout<R> {
to: FixedDotIndex, to: FixedDotIndex,
weight: FixedSegWeight, weight: FixedSegWeight,
) -> Result<FixedSegIndex, Infringement> { ) -> Result<FixedSegIndex, Infringement> {
self.add_seg_infringably(from.into(), to.into(), weight, &[]) self.add_seg_infringably(from.into(), to.into(), weight, None)
} }
#[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 4))] #[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 4))]
@ -226,7 +226,7 @@ impl<R: RulesTrait> Layout<R> {
seg_weight, seg_weight,
bend_weight, bend_weight,
cw, cw,
&infringables, Some(&infringables),
)?; )?;
if let Some(wraparound) = maybe_wraparound { if let Some(wraparound) = maybe_wraparound {
@ -303,18 +303,18 @@ impl<R: RulesTrait> Layout<R> {
self.move_dot_infringably( self.move_dot_infringably(
joints.0.into(), joints.0.into(),
from, from,
&self.collect().bend_outer_bows(rail), Some(&self.collect().bend_outer_bows(rail)),
)?; )?;
self.move_dot_infringably( self.move_dot_infringably(
joints.1.into(), joints.1.into(),
to, to,
&self.collect().bend_outer_bows(rail), Some(&self.collect().bend_outer_bows(rail)),
)?; )?;
self.shift_bend_infringably( self.shift_bend_infringably(
rail.into(), rail.into(),
offset, offset,
&self.collect().bend_outer_bows(rail), Some(&self.collect().bend_outer_bows(rail)),
)?; )?;
// Update offsets in case the rule conditions changed. // Update offsets in case the rule conditions changed.
@ -345,18 +345,18 @@ impl<R: RulesTrait> Layout<R> {
self.move_dot_infringably( self.move_dot_infringably(
joints.0.into(), joints.0.into(),
from, from,
&self.collect().bend_outer_bows(rail), Some(&self.collect().bend_outer_bows(rail)),
)?; )?;
self.move_dot_infringably( self.move_dot_infringably(
joints.1.into(), joints.1.into(),
to, to,
&self.collect().bend_outer_bows(rail), Some(&self.collect().bend_outer_bows(rail)),
)?; )?;
self.shift_bend_infringably( self.shift_bend_infringably(
rail.into(), rail.into(),
offset, offset,
&self.collect().bend_outer_bows(rail), Some(&self.collect().bend_outer_bows(rail)),
)?; )?;
} }
@ -386,7 +386,7 @@ impl<R: RulesTrait> Layout<R> {
seg_weight, seg_weight,
bend_weight, bend_weight,
cw, cw,
&self.collect().wraparounded_bows(around), Some(&self.collect().wraparounded_bows(around)),
) )
} }
@ -402,7 +402,7 @@ impl<R: RulesTrait> Layout<R> {
seg_weight: SeqLooseSegWeight, seg_weight: SeqLooseSegWeight,
bend_weight: LooseBendWeight, bend_weight: LooseBendWeight,
cw: bool, cw: bool,
infringables: &[GeometryIndex], infringables: Option<&[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
@ -448,7 +448,7 @@ impl<R: RulesTrait> Layout<R> {
to: FixedDotIndex, to: FixedDotIndex,
weight: LoneLooseSegWeight, weight: LoneLooseSegWeight,
) -> Result<LoneLooseSegIndex, Infringement> { ) -> Result<LoneLooseSegIndex, Infringement> {
let seg = self.add_seg_infringably(from.into(), to.into(), weight, &[])?; let seg = self.add_seg_infringably(from.into(), to.into(), weight, Some(&[]))?;
Ok(seg) Ok(seg)
} }
@ -462,7 +462,7 @@ impl<R: RulesTrait> Layout<R> {
to: LooseDotIndex, to: LooseDotIndex,
weight: SeqLooseSegWeight, weight: SeqLooseSegWeight,
) -> Result<SeqLooseSegIndex, Infringement> { ) -> Result<SeqLooseSegIndex, Infringement> {
let seg = self.add_seg_infringably(from, to.into(), weight, &[])?; let seg = self.add_seg_infringably(from, to.into(), weight, Some(&[]))?;
Ok(seg) Ok(seg)
} }
@ -475,7 +475,7 @@ impl<R: RulesTrait> Layout<R> {
from: DotIndex, from: DotIndex,
to: DotIndex, to: DotIndex,
weight: W, weight: W,
infringables: &[GeometryIndex], infringables: Option<&[GeometryIndex]>,
) -> Result<GenericIndex<W>, Infringement> ) -> Result<GenericIndex<W>, Infringement>
where where
GenericIndex<W>: Into<GeometryIndex> + Copy, GenericIndex<W>: Into<GeometryIndex> + Copy,
@ -497,7 +497,7 @@ impl<R: RulesTrait> Layout<R> {
to: LooseDotIndex, to: LooseDotIndex,
around: WraparoundableIndex, around: WraparoundableIndex,
weight: LooseBendWeight, weight: LooseBendWeight,
infringables: &[GeometryIndex], infringables: Option<&[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.
// //
@ -534,7 +534,7 @@ impl<R: RulesTrait> Layout<R> {
to: DotIndex, to: DotIndex,
core: FixedDotIndex, core: FixedDotIndex,
weight: W, weight: W,
infringables: &[GeometryIndex], infringables: Option<&[GeometryIndex]>,
) -> Result<GenericIndex<W>, Infringement> ) -> Result<GenericIndex<W>, Infringement>
where where
GenericIndex<W>: Into<GeometryIndex> + Copy, GenericIndex<W>: Into<GeometryIndex> + Copy,
@ -557,7 +557,7 @@ impl<R: RulesTrait> Layout<R> {
to: LooseDotIndex, to: LooseDotIndex,
inner: BendIndex, inner: BendIndex,
weight: LooseBendWeight, weight: LooseBendWeight,
infringables: &[GeometryIndex], infringables: Option<&[GeometryIndex]>,
) -> Result<GenericIndex<LooseBendWeight>, Infringement> { ) -> Result<GenericIndex<LooseBendWeight>, Infringement> {
let core = *self let core = *self
.geometry_with_rtree .geometry_with_rtree
@ -608,9 +608,9 @@ impl<R: RulesTrait> Layout<R> {
fn fail_and_remove_if_infringes_except( fn fail_and_remove_if_infringes_except(
&mut self, &mut self,
node: GeometryIndex, node: GeometryIndex,
except: &[GeometryIndex], maybe_except: Option<&[GeometryIndex]>,
) -> Result<(), Infringement> { ) -> Result<(), Infringement> {
if let Some(infringement) = self.detect_infringement_except(node, except) { if let Some(infringement) = self.detect_infringement_except(node, maybe_except) {
if let Ok(dot) = node.try_into() { if let Ok(dot) = node.try_into() {
self.geometry_with_rtree.remove_dot(dot); self.geometry_with_rtree.remove_dot(dot);
} else if let Ok(seg) = node.try_into() { } else if let Ok(seg) = node.try_into() {
@ -650,8 +650,8 @@ impl<R: RulesTrait> Layout<R> {
#[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))] #[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
pub fn move_dot(&mut self, dot: DotIndex, to: Point) -> Result<(), Infringement> { pub fn move_dot(&mut self, dot: DotIndex, to: Point) -> Result<(), Infringement> {
match dot { match dot {
DotIndex::Fixed(..) => self.move_dot_infringably(dot, to, &[]), DotIndex::Fixed(..) => self.move_dot_infringably(dot, to, Some(&[])),
DotIndex::Loose(..) => self.move_dot_infringably(dot, to, &[]), DotIndex::Loose(..) => self.move_dot_infringably(dot, to, Some(&[])),
} }
} }
@ -661,7 +661,7 @@ impl<R: RulesTrait> Layout<R> {
&mut self, &mut self,
dot: DotIndex, dot: DotIndex,
to: Point, to: Point,
infringables: &[GeometryIndex], infringables: Option<&[GeometryIndex]>,
) -> Result<(), Infringement> { ) -> Result<(), Infringement> {
let old_pos = self.geometry_with_rtree.geometry().dot_weight(dot).pos(); let old_pos = self.geometry_with_rtree.geometry().dot_weight(dot).pos();
self.geometry_with_rtree.move_dot(dot, to); self.geometry_with_rtree.move_dot(dot, to);
@ -689,7 +689,7 @@ impl<R: RulesTrait> Layout<R> {
&mut self, &mut self,
bend: BendIndex, bend: BendIndex,
offset: f64, offset: f64,
infringables: &[GeometryIndex], infringables: Option<&[GeometryIndex]>,
) -> Result<(), Infringement> { ) -> Result<(), Infringement> {
let old_offset = self let old_offset = self
.geometry_with_rtree .geometry_with_rtree
@ -712,7 +712,7 @@ impl<R: RulesTrait> Layout<R> {
fn detect_infringement_except( fn detect_infringement_except(
&self, &self,
node: GeometryIndex, node: GeometryIndex,
except: &[GeometryIndex], maybe_except: Option<&[GeometryIndex]>,
) -> Option<Infringement> { ) -> Option<Infringement> {
let limiting_shape = node let limiting_shape = node
.primitive(self) .primitive(self)
@ -724,8 +724,8 @@ impl<R: RulesTrait> Layout<R> {
self.geometry_with_rtree self.geometry_with_rtree
.rtree() .rtree()
.locate_in_envelope_intersecting(&limiting_shape.full_height_envelope_3d(0.0, 2)) .locate_in_envelope_intersecting(&limiting_shape.full_height_envelope_3d(0.0, 2))
.filter(|wrapper| maybe_except.is_some_and(|except| !except.contains(&wrapper.data)))
.filter(|wrapper| !self.are_connectable(node, wrapper.data)) .filter(|wrapper| !self.are_connectable(node, wrapper.data))
.filter(|wrapper| !except.contains(&wrapper.data))
.filter(|wrapper| { .filter(|wrapper| {
let infringee_conditions = wrapper.data.primitive(self).conditions(); let infringee_conditions = wrapper.data.primitive(self).conditions();