diff options
author | Marius Kintel <marius@kintel.net> | 2014-02-01 16:47:15 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2014-02-01 16:47:15 (GMT) |
commit | fa829a137eeed238f9e3cf454010c6f22681ab42 (patch) | |
tree | 62298b439743ae81c1cf1b392404c8e6f1303d97 | |
parent | 41f457584dff4c11612ba8d9e3ccf265341169a0 (diff) | |
parent | 111a935540a73a688dfde03fc10f9af191e050be (diff) |
Merge branch 'issue593' of git://github.com/tim-caper/openscad
-rw-r--r-- | src/dxfdata.cc | 32 | ||||
-rw-r--r-- | testdata/dxf/nothing-decimal-comma-separated.dxf | 140 | ||||
-rw-r--r-- | testdata/scad/dxf/nothing-decimal-comma-separated.scad | 2 | ||||
-rw-r--r-- | tests/regression/cgalpngtest/nothing-decimal-comma-separated-expected.png | bin | 0 -> 1947 bytes | |||
-rw-r--r-- | tests/regression/opencsgtest/nothing-decimal-comma-separated-expected.png | bin | 0 -> 1947 bytes | |||
-rw-r--r-- | tests/regression/throwntogethertest/nothing-decimal-comma-separated-expected.png | bin | 0 -> 1947 bytes |
6 files changed, 160 insertions, 14 deletions
diff --git a/src/dxfdata.cc b/src/dxfdata.cc index 9b61b93..ffea169 100644 --- a/src/dxfdata.cc +++ b/src/dxfdata.cc @@ -175,22 +175,23 @@ DxfData::DxfData(double fn, double fs, double fa, in_blocks_section = iddata == "BLOCKS"; } else if (mode == "LINE") { - ADD_LINE(xverts[0], yverts[0], xverts[1], yverts[1]); + ADD_LINE(xverts.at(0), yverts.at(0), xverts.at(1), yverts.at(1)); } else if (mode == "LWPOLYLINE") { - assert(xverts.size() == yverts.size()); - // polyline flag is stored in 'dimtype' - int numverts = xverts.size(); + // assert(xverts.size() == yverts.size()); + // Get maximum to enforce managed exception if xverts.size() != yverts.size() + int numverts = std::max(xverts.size(), yverts.size()); for (int i=1;i<numverts;i++) { - ADD_LINE(xverts[i-1], yverts[i-1], xverts[i%numverts], yverts[i%numverts]); + ADD_LINE(xverts.at(i-1), yverts.at(i-1), xverts.at(i%numverts), yverts.at(i%numverts)); } + // polyline flag is stored in 'dimtype' if (dimtype & 0x01) { // closed polyline - ADD_LINE(xverts[numverts-1], yverts[numverts-1], xverts[0], yverts[0]); + ADD_LINE(xverts.at(numverts-1), yverts.at(numverts-1), xverts.at(0), yverts.at(0)); } } else if (mode == "CIRCLE") { int n = Calc::get_fragments_from_r(radius, fn, fs, fa); - Vector2d center(xverts[0], yverts[0]); + Vector2d center(xverts.at(0), yverts.at(0)); for (int i = 0; i < n; i++) { double a1 = (2*M_PI*i)/n; double a2 = (2*M_PI*(i+1))/n; @@ -199,7 +200,7 @@ DxfData::DxfData(double fn, double fs, double fa, } } else if (mode == "ARC") { - Vector2d center(xverts[0], yverts[0]); + Vector2d center(xverts.at(0), yverts.at(0)); int n = Calc::get_fragments_from_r(radius, fn, fs, fa); while (arc_start_angle > arc_stop_angle) arc_stop_angle += 360.0; @@ -217,9 +218,9 @@ DxfData::DxfData(double fn, double fs, double fa, // Commented code is meant as documentation of vector math while (ellipse_start_angle > ellipse_stop_angle) ellipse_stop_angle += 2 * M_PI; // Vector2d center(xverts[0], yverts[0]); - Vector2d center(xverts[0], yverts[0]); + Vector2d center(xverts.at(0), yverts.at(0)); // Vector2d ce(xverts[1], yverts[1]); - Vector2d ce(xverts[1], yverts[1]); + Vector2d ce(xverts.at(1), yverts.at(1)); // double r_major = ce.length(); double r_major = sqrt(ce[0]*ce[0] + ce[1]*ce[1]); // double rot_angle = ce.angle(); @@ -270,10 +271,10 @@ DxfData::DxfData(double fn, double fs, double fa, double ly1 = this->points[blockdata[iddata][i].idx[0]][1] * ellipse_stop_angle; double lx2 = this->points[blockdata[iddata][i].idx[1]][0] * ellipse_start_angle; double ly2 = this->points[blockdata[iddata][i].idx[1]][1] * ellipse_stop_angle; - double px1 = (cos(a)*lx1 - sin(a)*ly1) * scale + xverts[0]; - double py1 = (sin(a)*lx1 + cos(a)*ly1) * scale + yverts[0]; - double px2 = (cos(a)*lx2 - sin(a)*ly2) * scale + xverts[0]; - double py2 = (sin(a)*lx2 + cos(a)*ly2) * scale + yverts[0]; + double px1 = (cos(a)*lx1 - sin(a)*ly1) * scale + xverts.at(0); + double py1 = (sin(a)*lx1 + cos(a)*ly1) * scale + yverts.at(0); + double px2 = (cos(a)*lx2 - sin(a)*ly2) * scale + xverts.at(0); + double py2 = (sin(a)*lx2 + cos(a)*ly2) * scale + yverts.at(0); ADD_LINE(px1, py1, px2, py2); } } @@ -385,6 +386,9 @@ DxfData::DxfData(double fn, double fs, double fa, catch (boost::bad_lexical_cast &blc) { PRINTB("WARNING: Illegal value %s in '%s'", data % filename); } + catch (const std::out_of_range& oor) { + PRINTB("WARNING: not enough input values for %s in '%s'", data % filename); + } } BOOST_FOREACH(const EntityList::value_type &i, unsupported_entities_list) { diff --git a/testdata/dxf/nothing-decimal-comma-separated.dxf b/testdata/dxf/nothing-decimal-comma-separated.dxf new file mode 100644 index 0000000..d7ef27e --- /dev/null +++ b/testdata/dxf/nothing-decimal-comma-separated.dxf @@ -0,0 +1,140 @@ +999 +This tests should not crash but produce no visible result, see former issue 593. +0 +SECTION +2 +HEADER +9 +$EXTMIN +10 +-6,63671875 +20 +-0,0244140625 +30 +0,5 +9 +$EXTMAX +10 +7,1357421875 +20 +0,921875 +30 +0,5 +0 +ENDSEC +0 +SECTION +2 +TABLES +0 +TABLE +2 +VPORT +0 +VPORT +2 +*ACTIVE +41 + 1.000000 +0 +ENDTAB +0 +TABLE +2 +LAYER +0 +LAYER +2 +0 +62 +0 +0 +ENDTAB +0 +ENDSEC +0 +SECTION +2 +BLOCKS +0 +ENDSEC +0 +SECTION +2 +ENTITIES +0 +LINE +8 +0 +62 +0 +10 +0,1 +20 +0,1 +30 +0 +11 +2,5 +21 +0 +31 +0 +0 +LINE +8 +0 +62 +0 +10 +2,5 +20 +0 +30 +0 +11 +2,5 +21 +2,5 +31 +0 +0 +LINE +8 +0 +62 +0 +10 +2,5 +20 +2,5 +30 +0 +11 +0 +21 +2,5 +31 +0 +0 +LINE +8 +0 +62 +0 +10 +0 +20 +2,5 +30 +0 +11 +0,1 +21 +0,1 +31 +0 +0 +ENDSEC +0 +EOF diff --git a/testdata/scad/dxf/nothing-decimal-comma-separated.scad b/testdata/scad/dxf/nothing-decimal-comma-separated.scad new file mode 100644 index 0000000..83219cd --- /dev/null +++ b/testdata/scad/dxf/nothing-decimal-comma-separated.scad @@ -0,0 +1,2 @@ +// This tests should not crash but produce no visible result, see former issue 593. +import("../../dxf/nothing-decimal-comma-separated.dxf"); diff --git a/tests/regression/cgalpngtest/nothing-decimal-comma-separated-expected.png b/tests/regression/cgalpngtest/nothing-decimal-comma-separated-expected.png Binary files differnew file mode 100644 index 0000000..5c4279e --- /dev/null +++ b/tests/regression/cgalpngtest/nothing-decimal-comma-separated-expected.png diff --git a/tests/regression/opencsgtest/nothing-decimal-comma-separated-expected.png b/tests/regression/opencsgtest/nothing-decimal-comma-separated-expected.png Binary files differnew file mode 100644 index 0000000..5c4279e --- /dev/null +++ b/tests/regression/opencsgtest/nothing-decimal-comma-separated-expected.png diff --git a/tests/regression/throwntogethertest/nothing-decimal-comma-separated-expected.png b/tests/regression/throwntogethertest/nothing-decimal-comma-separated-expected.png Binary files differnew file mode 100644 index 0000000..5c4279e --- /dev/null +++ b/tests/regression/throwntogethertest/nothing-decimal-comma-separated-expected.png |