From 38a8fc5be82aad05d9ed7499d09156bc6e5687bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1n=20D=C3=A9nes?= Date: Sun, 12 Dec 2021 14:51:24 +0100 Subject: [PATCH] Anchor affect bugfix, partially fixes #33 The mirroring part still has design inconsistencies because of rectangles being laid out by their bottom left corner, but as a breaking change, this will be addressed separately, later... --- src/anchor.js | 9 +- test/outlines/affect_mirror.yaml | 55 +++ .../affect_mirror___outlines_test_dxf.dxf | 434 ++++++++++++++++++ 3 files changed, 496 insertions(+), 2 deletions(-) create mode 100644 test/outlines/affect_mirror.yaml create mode 100644 test/outlines/affect_mirror___outlines_test_dxf.dxf diff --git a/src/anchor.js b/src/anchor.js index 5f21aec..5f08925 100644 --- a/src/anchor.js +++ b/src/anchor.js @@ -45,7 +45,11 @@ const anchor = exports.parse = (raw, name, points={}, check_unexpected=true, def } } if (raw.orient !== undefined) { - point.r += a.sane(raw.orient, `${name}.orient`, 'number')(units) + let angle = a.sane(raw.orient, `${name}.orient`, 'number')(units) + if (point.meta.mirrored) { + angle = -angle + } + point.r += angle } if (raw.shift !== undefined) { let xyval = a.wh(raw.shift, `${name}.shift`)(units) @@ -62,8 +66,9 @@ const anchor = exports.parse = (raw, name, points={}, check_unexpected=true, def point.r += angle } if (raw.affect !== undefined) { - const candidate = point + const candidate = point.clone() point = default_point.clone() + point.meta = candidate.meta let affect = raw.affect if (a.type(affect)() == 'string') affect = affect.split('') affect = a.strarr(affect, `${name}.affect`) diff --git a/test/outlines/affect_mirror.yaml b/test/outlines/affect_mirror.yaml new file mode 100644 index 0000000..98e9791 --- /dev/null +++ b/test/outlines/affect_mirror.yaml @@ -0,0 +1,55 @@ +points: + zones: + matrix: + columns: + only: + rows: + bottom: + top: + mirror: + ref: matrix_only_top + distance: 30 +outlines: + exports: + test: + keys: + type: keys + side: both + size: 14 + bound: false + rb: + type: rectangle + anchor: + - ref: mirror_matrix_only_bottom + # we do NOT specify `affect: xyr` here + - shift: [-3,-3] + orient: 30 + size: [6,6] + operation: stack + rt: + type: rectangle + anchor: + - ref: mirror_matrix_only_top + affect: xyr + - shift: [-3,-3] + orient: 30 + size: [6,6] + operation: stack + lb: + type: rectangle + anchor: + - ref: matrix_only_bottom + # again, no `affect: xyr` + - shift: [-3,-3] + orient: 30 + size: [6,6] + operation: stack + lt: + type: rectangle + anchor: + - ref: matrix_only_top + affect: xyr + - shift: [-3,-3] + orient: 30 + size: [6,6] + operation: stack \ No newline at end of file diff --git a/test/outlines/affect_mirror___outlines_test_dxf.dxf b/test/outlines/affect_mirror___outlines_test_dxf.dxf new file mode 100644 index 0000000..b251d92 --- /dev/null +++ b/test/outlines/affect_mirror___outlines_test_dxf.dxf @@ -0,0 +1,434 @@ +0 +SECTION +2 +HEADER +9 +$INSUNITS +70 +4 +0 +ENDSEC +0 +SECTION +2 +TABLES +0 +TABLE +2 +LTYPE +0 +LTYPE +72 +65 +70 +64 +2 +CONTINUOUS +3 +______ +73 +0 +40 +0 +0 +ENDTAB +0 +TABLE +2 +LAYER +0 +ENDTAB +0 +ENDSEC +0 +SECTION +2 +ENTITIES +0 +LINE +8 +0 +10 +-7 +20 +-7 +11 +7 +21 +-7 +0 +LINE +8 +0 +10 +7 +20 +-7 +11 +7 +21 +7 +0 +LINE +8 +0 +10 +7 +20 +7 +11 +-7 +21 +7 +0 +LINE +8 +0 +10 +-7 +20 +7 +11 +-7 +21 +-7 +0 +LINE +8 +0 +10 +-7 +20 +12 +11 +7 +21 +12 +0 +LINE +8 +0 +10 +7 +20 +12 +11 +7 +21 +26 +0 +LINE +8 +0 +10 +7 +20 +26 +11 +-7 +21 +26 +0 +LINE +8 +0 +10 +-7 +20 +26 +11 +-7 +21 +12 +0 +LINE +8 +0 +10 +23 +20 +-7 +11 +37 +21 +-7 +0 +LINE +8 +0 +10 +37 +20 +-7 +11 +37 +21 +7 +0 +LINE +8 +0 +10 +37 +20 +7 +11 +23 +21 +7 +0 +LINE +8 +0 +10 +23 +20 +7 +11 +23 +21 +-7 +0 +LINE +8 +0 +10 +23 +20 +12 +11 +37 +21 +12 +0 +LINE +8 +0 +10 +37 +20 +12 +11 +37 +21 +26 +0 +LINE +8 +0 +10 +37 +20 +26 +11 +23 +21 +26 +0 +LINE +8 +0 +10 +23 +20 +26 +11 +23 +21 +12 +0 +LINE +8 +0 +10 +31.0980762 +20 +-4.0980762 +11 +36.2942286 +21 +-7.0980762 +0 +LINE +8 +0 +10 +36.2942286 +20 +-7.0980762 +11 +39.2942286 +21 +-1.9019238 +0 +LINE +8 +0 +10 +39.2942286 +20 +-1.9019238 +11 +34.0980762 +21 +1.0980762 +0 +LINE +8 +0 +10 +34.0980762 +20 +1.0980762 +11 +31.0980762 +21 +-4.0980762 +0 +LINE +8 +0 +10 +31.0980762 +20 +14.9019238 +11 +36.2942286 +21 +11.9019238 +0 +LINE +8 +0 +10 +36.2942286 +20 +11.9019238 +11 +39.2942286 +21 +17.0980762 +0 +LINE +8 +0 +10 +39.2942286 +20 +17.0980762 +11 +34.0980762 +21 +20.0980762 +0 +LINE +8 +0 +10 +34.0980762 +20 +20.0980762 +11 +31.0980762 +21 +14.9019238 +0 +LINE +8 +0 +10 +-1.0980762 +20 +-4.0980762 +11 +4.0980762 +21 +-1.0980762 +0 +LINE +8 +0 +10 +4.0980762 +20 +-1.0980762 +11 +1.0980762 +21 +4.0980762 +0 +LINE +8 +0 +10 +1.0980762 +20 +4.0980762 +11 +-4.0980762 +21 +1.0980762 +0 +LINE +8 +0 +10 +-4.0980762 +20 +1.0980762 +11 +-1.0980762 +21 +-4.0980762 +0 +LINE +8 +0 +10 +-1.0980762 +20 +14.9019238 +11 +4.0980762 +21 +17.9019238 +0 +LINE +8 +0 +10 +4.0980762 +20 +17.9019238 +11 +1.0980762 +21 +23.0980762 +0 +LINE +8 +0 +10 +1.0980762 +20 +23.0980762 +11 +-4.0980762 +21 +20.0980762 +0 +LINE +8 +0 +10 +-4.0980762 +20 +20.0980762 +11 +-1.0980762 +21 +14.9019238 +0 +ENDSEC +0 +EOF \ No newline at end of file