diff --git a/engines/vendor/jagua-rs/src/probs/spp/entities/mod.rs b/engines/vendor/jagua-rs/src/probs/spp/entities/mod.rs index 70de49c..cddbc29 100644 --- a/engines/vendor/jagua-rs/src/probs/spp/entities/mod.rs +++ b/engines/vendor/jagua-rs/src/probs/spp/entities/mod.rs @@ -13,3 +13,4 @@ pub use problem::SPProblem; pub use solution::SPSolution; #[doc(inline)] pub use strip::Strip; +pub use strip::Walls; diff --git a/engines/vendor/jagua-rs/src/probs/spp/entities/strip.rs b/engines/vendor/jagua-rs/src/probs/spp/entities/strip.rs index df2a2ba..c59416c 100644 --- a/engines/vendor/jagua-rs/src/probs/spp/entities/strip.rs +++ b/engines/vendor/jagua-rs/src/probs/spp/entities/strip.rs @@ -1,5 +1,5 @@ use crate::collision_detection::CDEConfig; -use crate::entities::Container; +use crate::entities::{Container, InferiorQualityZone}; use crate::geometry::primitives::{Rect, SPolygon}; use crate::geometry::shape_modification::{ShapeModifyConfig, ShapeModifyMode}; use crate::geometry::{DTransformation, OriginalShape}; @@ -12,6 +12,36 @@ pub struct Strip { pub cde_config: CDEConfig, pub shape_modify_config: ShapeModifyConfig, pub width: f32, + /// CutNest patch: bars across the strip that no item may overlap, + /// dividing it into segments (sheets laid end to end). + pub walls: Option, +} + +/// CutNest patch: bars across a [`Strip`], at regular intervals. +/// Bar `k` (for `k ≥ 1`) spans `[k·period − thickness, k·period]` along the +/// width, so segment `k` spans `[k·period, (k + 1)·period − thickness]`. +/// Bars are inflated by the strip's separation offset like the strip's edges +/// are deflated by it, so items keep the same distance to both. +#[derive(Clone, Debug, Copy, PartialEq)] +pub struct Walls { + pub period: f32, + pub thickness: f32, +} + +impl Walls { + /// The bars that lie (partly) within a strip of `width`, as `(start, end)`. + pub fn within(&self, width: f32) -> impl Iterator + '_ { + (1..) + .map(|k| k as f32 * self.period) + .map(|end| (end - self.thickness, end)) + .take_while(move |(start, _)| *start < width) + .map(move |(start, end)| (start, end.min(width))) + } + + /// Where the last segment of a strip of `width` starts. + pub fn last_segment_start(&self, width: f32) -> f32 { + self.within(width).map(|(_, end)| end).last().unwrap_or(0.0) + } } impl Strip { @@ -28,6 +58,7 @@ impl Strip { cde_config, shape_modify_config, width, + walls: None, }) } @@ -35,12 +66,44 @@ impl Strip { assert!(width > 0.0, "strip width must be positive"); self.width = width; } + + /// CutNest patch: where shrinking or growing the strip should shift + /// items from. With walls, the start of the last segment, so only the + /// last segment changes; otherwise the middle. + pub fn split_position(&self) -> f32 { + match self.walls { + Some(w) => w.last_segment_start(self.width), + None => self.width / 2.0, + } + } } impl TryFrom for Container { type Error = anyhow::Error; fn try_from(s: Strip) -> Result { + // CutNest patch: walls become a quality-0 zone, which every item + // must stay clear of. + let mut zones = vec![]; + if let Some(walls) = s.walls { + let bars = walls + .within(s.width) + // A sliver of a bar at the strip's end is left out: too thin + // for the collision engine, and no item fits in it anyway. + .filter(|(start, end)| end - start > walls.thickness * 0.25) + .map(|(start, end)| { + Ok(OriginalShape { + shape: SPolygon::from(Rect::try_new(start, 0.0, end, s.fixed_height)?), + pre_transform: DTransformation::empty(), + modify_mode: ShapeModifyMode::Inflate, + modify_config: s.shape_modify_config, + }) + }) + .collect::>>()?; + if !bars.is_empty() { + zones.push(InferiorQualityZone::new(0, bars, s.cde_config.item_surrogate_config)?); + } + } Container::new( OriginalShape { shape: SPolygon::from(Rect::try_new(0.0, 0.0, s.width, s.fixed_height)?), @@ -48,7 +111,7 @@ impl TryFrom for Container { modify_mode: ShapeModifyMode::Deflate, modify_config: s.shape_modify_config, }, - vec![], + zones, s.cde_config, ) }