From 8dbbf95d05b60a9f0c231a9e0c877c538123458b Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 12 Jan 2021 00:54:59 +0000 Subject: [PATCH] otterlib: wip preview, reorg a bit nfc Signed-off-by: Ian Jackson --- src/bin/otterlib.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/bin/otterlib.rs b/src/bin/otterlib.rs index 200c412b..193fdd77 100644 --- a/src/bin/otterlib.rs +++ b/src/bin/otterlib.rs @@ -33,22 +33,32 @@ pub type ItemForOutput = (String, ItemEnquiryData); #[throws(AE)] fn preview(items: Vec) { - let pieces = items.into_iter().map(|it| { + const BORDER: f64 = 1.; + + struct Prep { + spec: ItemSpec, + pc: Box, + uos: Vec + }; + + let pieces : Vec = items.into_iter().map(|it| { let spec = ItemSpec { lib: it.0, item: it.1.itemname }; (||{ let pc = spec.clone().load().context("load")?; let mut uos = vec![]; pc.add_ui_operations(&mut uos).context("add uos")?; let uos = uos.into_iter().map(|uo| uo.opname).collect::>(); - Ok::<_,AE>((spec.clone(), pc, uos)) + let spec = spec.clone(); + + Ok::<_,AE>(Prep { spec, pc, uos }) })().with_context(|| format!("{:?}", &spec)) }).collect::,_>>()?; - let max_faces = pieces.iter().map(|(_,p,_)| p.nfaces()).max().unwrap_or(1); - let max_uos = pieces.iter().map(|(..,uos)| uos.len()).max().unwrap_or(0); + let max_faces = pieces.iter().map(|s| s.pc.nfaces()).max().unwrap_or(1); + let max_uos = pieces.iter().map(|s| s.uos.len()).max().unwrap_or(0); println!(r#""#); - for (spec, pc, uos) in &pieces { + for Prep { spec, pc, uos } in &pieces { println!(r#""#); println!(r#"
{}"#, &spec.lib); println!(r#"{}"#, &spec.item); @@ -59,7 +69,7 @@ fn preview(items: Vec) { angle: VisiblePieceAngle(default()), face }; - const BORDER: f64 = 1.; + let bbox = pc .bbox_approx(); let mut bbox = bbox @@ -71,6 +81,7 @@ fn preview(items: Vec) { let size = izip!(&bbox[0], &bbox[1]) .map(|(min,max)| max-min) .collect::>(); + for face in 0..(if only1 { 1 } else { max_faces }) { print!(r#"