Skip to main content

jagua_rs/io/
export.rs

1use crate::entities::LayoutSnapshot;
2use crate::geometry::{DTransformation, Transformation};
3use crate::io::ext_repr::{ExtLayout, ExtPlacedItem};
4
5/// Exports a layout to an external representation.
6/// The caller supplies the external bin/sheet ID; geometry carries no identity.
7#[must_use]
8pub fn export_layout_snapshot(layout: &LayoutSnapshot, container_id: u64) -> ExtLayout {
9    let ext_placed_items = layout
10        .placed_items
11        .values()
12        .map(|pi| {
13            let item = &pi.item;
14
15            let abs_transf =
16                int_to_ext_transformation(&pi.d_transf, &item.shape_orig.pre_transform);
17
18            ExtPlacedItem {
19                item_id: item.external_id,
20                transformation: abs_transf.into(),
21            }
22        })
23        .collect();
24
25    ExtLayout {
26        container_id,
27        placed_items: ext_placed_items,
28        density: layout.density(),
29    }
30}
31
32/// Converts an internal (used within `jagua-rs`) transformation to an external transformation (applicable to the original shapes).
33///
34/// * `int_transf` - The internal transformation.
35/// * `pre_transf` - The transformation that was applied to the original shape to derive the internal representation.
36#[must_use]
37pub fn int_to_ext_transformation(
38    int_transf: &DTransformation,
39    pre_transf: &DTransformation,
40) -> DTransformation {
41    //1. apply the pre-transform
42    //2. apply the internal transformation
43
44    Transformation::empty()
45        .transform_from_decomposed(pre_transf)
46        .transform_from_decomposed(int_transf)
47        .decompose()
48}