From 96ec395a33e4b35e888c95a52bb9825dcde85d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20K=C3=B6fferlein?= Date: Fri, 5 Jun 2020 10:57:14 +0200 Subject: [PATCH] Fixed issue #578 (CIF writer issue with arbitrary angle) (#581) * Fixed isse #578 (CIF writer issue with arbitrary angle) * Added missing files. --- .../streamers/cif/db_plugin/dbCIFWriter.cc | 27 +++++++----------- .../streamers/cif/unit_tests/dbCIFReader.cc | 6 ++++ testdata/cif/issue_578.cif | 18 ++++++++++++ testdata/cif/issue_578_au.gds | Bin 0 -> 668 bytes 4 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 testdata/cif/issue_578.cif create mode 100644 testdata/cif/issue_578_au.gds diff --git a/src/plugins/streamers/cif/db_plugin/dbCIFWriter.cc b/src/plugins/streamers/cif/db_plugin/dbCIFWriter.cc index 955eb8569..1b1a98459 100644 --- a/src/plugins/streamers/cif/db_plugin/dbCIFWriter.cc +++ b/src/plugins/streamers/cif/db_plugin/dbCIFWriter.cc @@ -165,23 +165,18 @@ CIFWriter::write (db::Layout &layout, tl::OutputStream &stream, const db::SaveLa } double a = t.angle(); - while (a < 0) { - a += 360.0; - } - double ya = 0.0, xa = 0.0; - if (a < 45 || a > 315) { - xa = 1.0; - ya = tan(a / 180.0 * M_PI); - } else if (a < 135) { - xa = 1.0 / tan(a / 180.0 * M_PI); - ya = 1.0; - } else if (a < 225) { - xa = -1.0; - ya = tan(a / 180.0 * M_PI); + double xa = cos(a / 180.0 * M_PI); + double ya = sin(a / 180.0 * M_PI); + + // normalize xa or ya whichever is better + double n; + if (fabs (xa) >= M_SQRT1_2) { + n = 1.0 / fabs (xa); } else { - xa = 1.0 / tan(a / 180.0 * M_PI); - ya = -1.0; - } + n = 1.0 / fabs (ya); + } + xa *= n; + ya *= n; // TODO: that can be done smarter ... for (int n = 0; n < 20 && (fabs (xa - floor (0.5 + xa)) > 1e-3 || fabs (ya - floor (0.5 + ya)) > 1e-3); ++n) { diff --git a/src/plugins/streamers/cif/unit_tests/dbCIFReader.cc b/src/plugins/streamers/cif/unit_tests/dbCIFReader.cc index e572e9e11..db81e7e0e 100644 --- a/src/plugins/streamers/cif/unit_tests/dbCIFReader.cc +++ b/src/plugins/streamers/cif/unit_tests/dbCIFReader.cc @@ -200,3 +200,9 @@ TEST(rot_instances) { run_test (_this, tl::testsrc (), "issue_568.cif", "issue_568_au.gds"); } + +// Issue #578 +TEST(rot_instances2) +{ + run_test (_this, tl::testsrc (), "issue_578.cif", "issue_578_au.gds"); +} diff --git a/testdata/cif/issue_578.cif b/testdata/cif/issue_578.cif new file mode 100644 index 000000000..54695dcd8 --- /dev/null +++ b/testdata/cif/issue_578.cif @@ -0,0 +1,18 @@ +(CIF file written 2020-06-04 16:17:46 by KLayout); +DS 1 1 10; +9 F; +L L1D0; +P 0,0 0,7000 4000,7000 4000,6000 1000,6000 1000,4000 2000,4000 2000,3000 1000,3000 1000,0; +DF; +DS 2 1 10; +9 ALL; +C1 R1,0 T0,0; +C1 R1,1 T0,0; +C1 R0,1 T0,0; +C1 R-1,-1 T0,0; +C1 R-1,0 T0,0; +C1 R-1,1 T0,0; +C1 R0,-1 T0,0; +C1 R1,-1 T0,0; +DF; +E diff --git a/testdata/cif/issue_578_au.gds b/testdata/cif/issue_578_au.gds new file mode 100644 index 0000000000000000000000000000000000000000..aacd0f06b866161b457a818ef2b6b61aab607ae9 GIT binary patch literal 668 zcma)3Jqp4w7=2BXuSKiY9}qNG5EnsQ#8wf+jt(Lo!dr-EaB*{WaPS1q9>KxE(a}v) zYoH3+eu2C|-d_j^j7=d8W?ewwaMfzX&#)N