DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Keep at least four wrap passes for a story with few anchored objects
Brandon Thomasa9256308e32e
diff --git a/crates/compose/src/wrap.rs b/crates/compose/src/wrap.rsindex 7d38f0ef8..724310b00 100644--- a/crates/compose/src/wrap.rs+++ b/crates/compose/src/wrap.rs@@ -15,7 +15,8 @@//! moving. An object's wrap can push the anchors of the objects after it, so a chain of n such//! objects needs n + 1 more compositions: the k-th pass places the (k + 1)-th object where the//! wraps before it leave its anchor, and the last pass wraps around the last object. The story-//! is composed at most that many more times, and never more than [`MAX_PASSES`].+//! is composed at most that many more times (at least [`MIN_PASSES`]), and never more than+//! [`MAX_PASSES`].use designcraft_doc::{AnchorPosition, AnchoredObject, Document, Item, OBJECT_MARK, PageSide, SpreadRef, Story, StoryId, WrapMode};use designcraft_geom::Affine;@@ -24,9 +25,13 @@ use crate::{ComposeOptions, ComposedStory, Exclusion, FrameSpec};/// Most extra compositions of a story with its own anchored objects' wrap, however many objects/// it has; a layout that keeps moving its objects (keep options, vertical justification) stops-/// sooner, after one per object and one more.+/// sooner, after one per object and one more (but never fewer than [`MIN_PASSES`]).pub(crate) const MAX_PASSES: usize = 64;+/// Fewest extra compositions allowed before giving up on a layout that keeps moving: a single+/// object that keep options or vertical justification move still gets the room it had before.+const MIN_PASSES: usize = 4;+/// How far an obstacle may move between passes and still count as settled (points).const SETTLED: f64 = 0.01;@@ -205,7 +210,7 @@ pub(crate) fn compose_among(doc: &Document, sid: StoryId, opts: &ComposeOptions,}let own = st.objects.iter().filter(|o| wraps(o) && !matches!(o.position, AnchorPosition::Inline { .. })).count();let mut prev = vec![Vec::new(); specs.len()];- for _ in 0..(own + 1).min(MAX_PASSES) {+ for _ in 0..(own + 1).max(MIN_PASSES).min(MAX_PASSES) {let added = exclusions(doc, &specs, &obstacles(doc, st, &out, true));if settled(&added, &prev) {break;