From 5a25c1c423b84e2aad8b2fe80bf77fca11d2991d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1n=20D=C3=A9nes?= Date: Sun, 29 May 2022 14:12:11 +0200 Subject: [PATCH] Make within-column layout cumulative as well --- src/points.js | 22 +++++++++++-------- test/cli/big/reference/points/points.yaml | 2 +- test/cli/minimal/reference/points/points.yaml | 2 +- test/points/adjustments___demo_dxf.dxf | 16 +++++++------- test/points/adjustments___points.json | 6 ++--- test/points/basic_2x2___points.json | 4 ++-- test/points/default___points.json | 4 ++-- test/points/overrides___points.json | 4 ++-- 8 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/points.js b/src/points.js index def23a5..2fd72f7 100644 --- a/src/points.js +++ b/src/points.js @@ -86,7 +86,7 @@ const render_zone = exports._render_zone = (zone_name, zone, anchor, global_key, const keys = [] const default_key = { stagger: units.$default_stagger, - spread: first_col ? 0 : units.$default_spread, + spread: units.$default_spread, splay: units.$default_splay, origin: [0, 0], orient: 0, @@ -141,7 +141,9 @@ const render_zone = exports._render_zone = (zone_name, zone, anchor, global_key, } // setting up column-level anchor - zone_anchor.x += keys[0].spread + if (!first_col) { + zone_anchor.x += keys[0].spread + } zone_anchor.y += keys[0].stagger const col_anchor = zone_anchor.clone() @@ -156,16 +158,17 @@ const render_zone = exports._render_zone = (zone_name, zone, anchor, global_key, } // actually laying out keys + let running_anchor = col_anchor.clone() + for (const r of rotations) { + running_anchor.rotate(r.angle, r.origin) + } for (const key of keys) { // copy the current column anchor - let point = col_anchor.clone() + let point = running_anchor.clone() - // apply transformations - for (const r of rotations) { - point.rotate(r.angle, r.origin) - } + // apply per-key adjustments point.r += key.orient point.shift(key.shift) point.r += key.rotate @@ -178,8 +181,9 @@ const render_zone = exports._render_zone = (zone_name, zone, anchor, global_key, col_minmax[col_name].min = Math.min(col_minmax[col_name].min, point.y) col_minmax[col_name].max = Math.max(col_minmax[col_name].max, point.y) - // advance the column anchor to the next position - col_anchor.y += key.padding + // advance the running anchor to the next position + running_anchor = point.clone() + running_anchor.shift([0, key.padding]) } first_col = false diff --git a/test/cli/big/reference/points/points.yaml b/test/cli/big/reference/points/points.yaml index f744193..911c06d 100644 --- a/test/cli/big/reference/points/points.yaml +++ b/test/cli/big/reference/points/points.yaml @@ -4,7 +4,7 @@ matrix: r: 0 meta: stagger: 0 - spread: 0 + spread: 19 splay: 0 origin: - 0 diff --git a/test/cli/minimal/reference/points/points.yaml b/test/cli/minimal/reference/points/points.yaml index 0ec0976..63b3d11 100644 --- a/test/cli/minimal/reference/points/points.yaml +++ b/test/cli/minimal/reference/points/points.yaml @@ -4,7 +4,7 @@ matrix_col_row: r: 0 meta: stagger: 0 - spread: 0 + spread: 19 splay: 0 origin: - 0 diff --git a/test/points/adjustments___demo_dxf.dxf b/test/points/adjustments___demo_dxf.dxf index d953dbe..6f18f2b 100644 --- a/test/points/adjustments___demo_dxf.dxf +++ b/test/points/adjustments___demo_dxf.dxf @@ -195,11 +195,11 @@ LINE 10 22.7371845 20 -33.7307612 +33.7307613 11 40.6686891 21 -35.2995646 +35.2995647 0 LINE 8 @@ -207,11 +207,11 @@ LINE 10 40.6686891 20 -35.2995646 +35.2995647 11 42.2374925 21 -17.36806 +17.3680601 0 LINE 8 @@ -219,11 +219,11 @@ LINE 10 42.2374925 20 -17.36806 +17.3680601 11 24.3059879 21 -15.7992566 +15.7992567 0 LINE 8 @@ -231,11 +231,11 @@ LINE 10 24.3059879 20 -15.7992566 +15.7992567 11 22.7371845 21 -33.7307612 +33.7307613 0 ENDSEC 0 diff --git a/test/points/adjustments___points.json b/test/points/adjustments___points.json index ab5e160..92f7b09 100644 --- a/test/points/adjustments___points.json +++ b/test/points/adjustments___points.json @@ -5,7 +5,7 @@ "r": 0, "meta": { "stagger": 0, - "spread": 0, + "spread": 19, "splay": 0, "origin": [ 0, @@ -77,7 +77,7 @@ "r": 0, "meta": { "stagger": 0, - "spread": 0, + "spread": 19, "splay": 0, "origin": [ 0, @@ -234,7 +234,7 @@ }, "matrix_right_top": { "x": 32.4873385, - "y": 25.5494106, + "y": 25.549410700000003, "r": 5, "meta": { "stagger": 5, diff --git a/test/points/basic_2x2___points.json b/test/points/basic_2x2___points.json index ab42f3d..61d9968 100644 --- a/test/points/basic_2x2___points.json +++ b/test/points/basic_2x2___points.json @@ -5,7 +5,7 @@ "r": 0, "meta": { "stagger": 0, - "spread": 0, + "spread": 19, "splay": 0, "origin": [ 0, @@ -56,7 +56,7 @@ "r": 0, "meta": { "stagger": 0, - "spread": 0, + "spread": 19, "splay": 0, "origin": [ 0, diff --git a/test/points/default___points.json b/test/points/default___points.json index c4ad48d..60e486d 100644 --- a/test/points/default___points.json +++ b/test/points/default___points.json @@ -5,7 +5,7 @@ "r": 0, "meta": { "stagger": 0, - "spread": 0, + "spread": 19, "splay": 0, "origin": [ 0, @@ -48,7 +48,7 @@ "r": 0, "meta": { "stagger": 0, - "spread": 0, + "spread": 19, "splay": 0, "origin": [ 0, diff --git a/test/points/overrides___points.json b/test/points/overrides___points.json index 9094335..2a763b7 100644 --- a/test/points/overrides___points.json +++ b/test/points/overrides___points.json @@ -5,7 +5,7 @@ "r": 0, "meta": { "stagger": 0, - "spread": 0, + "spread": 19, "splay": 0, "origin": [ 0, @@ -73,7 +73,7 @@ "r": 0, "meta": { "stagger": 0, - "spread": 0, + "spread": 19, "splay": 0, "origin": [ 0,