@@ -8,9 +8,9 @@ using namespace packingsolver::irregular;
88
99bool ItemShape::check () const
1010{
11- if (!shape_orig.check ())
11+ if (!shape_orig.shape . check ())
1212 return false ;
13- for (const Shape& hole: holes_orig )
13+ for (const Shape& hole: shape_orig. holes )
1414 if (!hole.check ())
1515 return false ;
1616 return true ;
@@ -22,13 +22,6 @@ std::string ItemShape::to_string(
2222 std::string s = " \n " ;
2323 std::string indent = std::string (indentation, ' ' );
2424 s += indent + " - shape: " + shape_orig.to_string (indentation + 2 ) + " \n " ;
25- if (holes_orig.size () == 1 ) {
26- s += indent + " - holes: " + holes_orig.front ().to_string (indentation + 2 ) + " \n " ;
27- } else if (holes_orig.size () >= 2 ) {
28- s += indent + " - holes\n " ;
29- for (const Shape& hole: holes_orig)
30- s += indent + " - " + hole.to_string (indentation + 4 ) + " \n " ;
31- }
3225 s += " - quality rule: " + std::to_string (quality_rule);
3326 return s;
3427}
@@ -51,38 +44,38 @@ ShapeType ItemType::shape_type() const
5144{
5245 // Circle.
5346 if (shapes.size () == 1
54- && shapes.front ().shape_scaled .is_circle ()
55- && shapes.front ().holes_scaled .empty ())
47+ && shapes.front ().shape_scaled .shape . is_circle ()
48+ && shapes.front ().shape_scaled . holes .empty ())
5649 return ShapeType::Circle;
5750 // Square.
5851 if (shapes.size () == 1
59- && shapes.front ().shape_scaled .is_square ()
60- && shapes.front ().holes_scaled .empty ())
52+ && shapes.front ().shape_scaled .shape . is_square ()
53+ && shapes.front ().shape_scaled . holes .empty ())
6154 return ShapeType::Square;
6255 // Rectangle.
6356 if (shapes.size () == 1
64- && shapes.front ().shape_scaled .is_rectangle ()
65- && shapes.front ().holes_scaled .empty ())
57+ && shapes.front ().shape_scaled .shape . is_rectangle ()
58+ && shapes.front ().shape_scaled . holes .empty ())
6659 return ShapeType::Rectangle;
6760 // Polygon.
6861 if (shapes.size () == 1
69- && shapes.front ().shape_scaled .is_polygon ()
70- && shapes.front ().holes_scaled .empty ())
62+ && shapes.front ().shape_scaled .shape . is_polygon ()
63+ && shapes.front ().shape_scaled . holes .empty ())
7164 return ShapeType::Polygon;
7265 // MultiPolygon.
7366 bool is_multi_polygon = true ;
7467 for (const ItemShape& item_shape: shapes)
75- if (!item_shape.shape_scaled .is_polygon ()
76- || !item_shape.holes_scaled .empty ())
68+ if (!item_shape.shape_scaled .shape . is_polygon ()
69+ || !item_shape.shape_scaled . holes .empty ())
7770 is_multi_polygon = false ;
7871 if (is_multi_polygon)
7972 return ShapeType::MultiPolygon;
8073 // PolygonWithHoles.
8174 if (shapes.size () == 1 ) {
8275 bool is_polygon_with_holes = true ;
83- if (!shapes.front ().shape_scaled .is_polygon ())
76+ if (!shapes.front ().shape_scaled .shape . is_polygon ())
8477 is_polygon_with_holes = false ;
85- for (const Shape& hole: shapes.front ().holes_scaled )
78+ for (const Shape& hole: shapes.front ().shape_scaled . holes )
8679 if (!hole.is_polygon ())
8780 is_polygon_with_holes = false ;
8881 if (is_polygon_with_holes)
@@ -91,9 +84,9 @@ ShapeType ItemType::shape_type() const
9184 // MultiPolygonWithHoles.
9285 bool is_multi_polygon_with_holes = true ;
9386 for (const ItemShape& item_shape: shapes) {
94- if (!item_shape.shape_scaled .is_polygon ())
87+ if (!item_shape.shape_scaled .shape . is_polygon ())
9588 is_multi_polygon_with_holes = false ;
96- for (const Shape& hole: item_shape.holes_scaled )
89+ for (const Shape& hole: item_shape.shape_scaled . holes )
9790 if (!hole.is_polygon ())
9891 is_multi_polygon_with_holes = false ;
9992 }
@@ -114,9 +107,9 @@ std::pair<Point, Point> ItemType::compute_min_max(
114107 LengthDbl y_max = -std::numeric_limits<LengthDbl>::infinity ();
115108 for (const ItemShape& item_shape: shapes) {
116109 auto points =
117- (type == 0 )? item_shape.shape_orig .compute_min_max (angle, mirror):
118- (type == 1 )? item_shape.shape_scaled .compute_min_max (angle, mirror):
119- item_shape.shape_inflated .compute_min_max (angle, mirror);
110+ (type == 0 )? item_shape.shape_orig .shape . compute_min_max (angle, mirror):
111+ (type == 1 )? item_shape.shape_scaled .shape . compute_min_max (angle, mirror):
112+ item_shape.shape_inflated .shape . compute_min_max (angle, mirror);
120113 x_min = std::min (x_min, points.first .x );
121114 x_max = std::max (x_max, points.second .x );
122115 y_min = std::min (y_min, points.first .y );
@@ -182,13 +175,11 @@ void ItemType::write_svg(
182175 LengthDbl width = (mm.second .x - mm.first .x );
183176 LengthDbl height = (mm.second .y - mm.first .y );
184177
185- double factor = compute_svg_factor (width);
186-
187178 std::string s = " <svg viewBox=\" "
188- + std::to_string (mm.first .x * factor )
189- + " " + std::to_string (-mm.first .y * factor - height * factor )
190- + " " + std::to_string (width * factor )
191- + " " + std::to_string (height * factor )
179+ + std::to_string (mm.first .x )
180+ + " " + std::to_string (-mm.first .y - height)
181+ + " " + std::to_string (width)
182+ + " " + std::to_string (height)
192183 + " \" version=\" 1.1\" xmlns=\" http://www.w3.org/2000/svg\" >\n " ;
193184 file << s;
194185
@@ -198,8 +189,8 @@ void ItemType::write_svg(
198189 ++item_shape_pos) {
199190 const auto & item_shape = shapes[item_shape_pos];
200191 file << " <g>" << std::endl;
201- file << to_svg ( item_shape.shape_scaled , item_shape. holes_scaled , factor, " blue" );
202- file << to_svg ( item_shape.shape_inflated , item_shape. holes_deflated , factor, " red" );
192+ file << item_shape.shape_scaled . to_svg ( " blue" );
193+ file << item_shape.shape_inflated . to_svg ( " red" );
203194 // file << "<text x=\"" << std::to_string(x * factor)
204195 // << "\" y=\"" << std::to_string(-y * factor)
205196 // << "\" dominant-baseline=\"middle\" text-anchor=\"middle\">"
@@ -238,23 +229,17 @@ void BinType::write_svg(
238229 LengthDbl width = (x_max - x_min);
239230 LengthDbl height = (y_max - y_min);
240231
241- double factor = compute_svg_factor (width);
242- while (width * factor > 1000 )
243- factor /= 10 ;
244- while (width * factor < 100 )
245- factor *= 10 ;
246-
247232 std::string s = " <svg viewBox=\" "
248- + std::to_string (x_min * factor )
249- + " " + std::to_string (-y_min * factor - height * factor )
250- + " " + std::to_string (width * factor )
251- + " " + std::to_string (height * factor )
233+ + std::to_string (x_min)
234+ + " " + std::to_string (-y_min - height)
235+ + " " + std::to_string (width)
236+ + " " + std::to_string (height)
252237 + " \" version=\" 1.1\" xmlns=\" http://www.w3.org/2000/svg\" >\n " ;
253238 file << s;
254239
255240 // Loop through trapezoids of the trapezoid set.
256241 file << " <g>" << std::endl;
257- file << to_svg (shape_scaled, {}, factor );
242+ file << shape_scaled. to_svg ();
258243 // file << "<text x=\"" << std::to_string(x * factor)
259244 // << "\" y=\"" << std::to_string(-y * factor)
260245 // << "\" dominant-baseline=\"middle\" text-anchor=\"middle\">"
@@ -264,7 +249,7 @@ void BinType::write_svg(
264249
265250 for (const Defect& defect: defects) {
266251 file << " <g>" << std::endl;
267- file << to_svg ( defect.shape_scaled , defect. holes_scaled , factor );
252+ file << defect.shape_scaled . to_svg ( );
268253 file << " </g>" << std::endl;
269254 }
270255
@@ -424,7 +409,7 @@ std::ostream& Instance::format(
424409 << std::setw (12 ) << item_type_id
425410 << std::setw (12 ) << shape_pos
426411 << std::setw (12 ) << item_shape.quality_rule
427- << std::setw (12 ) << item_shape.holes_orig .size ()
412+ << std::setw (12 ) << item_shape.shape_orig . holes .size ()
428413 << std::endl;
429414 }
430415 }
@@ -485,9 +470,9 @@ std::ostream& Instance::format(
485470 for (DefectId k = 0 ; k < (DefectId)bin_type.defects .size (); ++k) {
486471 const Defect& defect = bin_type.defects [k];
487472 for (Counter element_pos = 0 ;
488- element_pos < (Counter)defect.shape_orig .elements .size ();
473+ element_pos < (Counter)defect.shape_orig .shape . elements .size ();
489474 ++element_pos) {
490- const ShapeElement& element = defect.shape_orig .elements [element_pos];
475+ const ShapeElement& element = defect.shape_orig .shape . elements [element_pos];
491476 os
492477 << std::setw (2 ) << " B"
493478 << std::setw (5 ) << bin_type_id
@@ -505,9 +490,9 @@ std::ostream& Instance::format(
505490 << std::endl;
506491 }
507492 for (Counter hole_pos = 0 ;
508- hole_pos < (Counter)defect.holes_orig .size ();
493+ hole_pos < (Counter)defect.shape_orig . holes .size ();
509494 ++hole_pos) {
510- const Shape& hole = defect.holes_orig [hole_pos];
495+ const Shape& hole = defect.shape_orig . holes [hole_pos];
511496 for (Counter element_pos = 0 ;
512497 element_pos < (Counter)hole.elements .size ();
513498 ++element_pos) {
@@ -541,9 +526,9 @@ std::ostream& Instance::format(
541526 ++shape_pos) {
542527 const ItemShape& item_shape = item_type.shapes [shape_pos];
543528 for (Counter element_pos = 0 ;
544- element_pos < (Counter)item_shape.shape_orig .elements .size ();
529+ element_pos < (Counter)item_shape.shape_orig .shape . elements .size ();
545530 ++element_pos) {
546- const ShapeElement& element = item_shape.shape_orig .elements [element_pos];
531+ const ShapeElement& element = item_shape.shape_orig .shape . elements [element_pos];
547532 os
548533 << std::setw (2 ) << " I"
549534 << std::setw (5 ) << item_type_id
@@ -561,9 +546,9 @@ std::ostream& Instance::format(
561546 << std::endl;
562547 }
563548 for (Counter hole_pos = 0 ;
564- hole_pos < (Counter)item_shape.holes_orig .size ();
549+ hole_pos < (Counter)item_shape.shape_orig . holes .size ();
565550 ++hole_pos) {
566- const Shape& hole = item_shape.holes_orig [hole_pos];
551+ const Shape& hole = item_shape.shape_orig . holes [hole_pos];
567552 for (Counter element_pos = 0 ;
568553 element_pos < (Counter)hole.elements .size ();
569554 ++element_pos) {
@@ -623,11 +608,11 @@ void Instance::write(
623608 ++defect_id) {
624609 const Defect& defect = bin_type.defects [defect_id];
625610 json[" bin_types" ][bin_type_id][" defects" ][defect_id][" type" ] = " general" ;
626- json[" bin_types" ][bin_type_id][" defects" ][defect_id][" elements" ] = defect.shape_orig .to_json ();
611+ json[" bin_types" ][bin_type_id][" defects" ][defect_id][" elements" ] = defect.shape_orig .shape . to_json ();
627612 for (Counter hole_pos = 0 ;
628- hole_pos < (Counter)defect.holes_orig .size ();
613+ hole_pos < (Counter)defect.shape_orig . holes .size ();
629614 ++hole_pos) {
630- const Shape& hole = defect.holes_orig [hole_pos];
615+ const Shape& hole = defect.shape_orig . holes [hole_pos];
631616 json[" bin_types" ][bin_type_id][" defects" ][defect_id][" holes" ][hole_pos][" type" ] = " general" ;
632617 json[" bin_types" ][bin_type_id][" defects" ][defect_id][" holes" ][hole_pos][" elements" ] = hole.to_json ();
633618 }
@@ -653,11 +638,11 @@ void Instance::write(
653638 ++item_shape_pos) {
654639 const ItemShape& item_shape = item_type.shapes [item_shape_pos];
655640 json[" item_types" ][item_type_id][" shapes" ][item_shape_pos][" type" ] = " general" ;
656- json[" item_types" ][item_type_id][" shapes" ][item_shape_pos][" elements" ] = item_shape.shape_orig .to_json ();
641+ json[" item_types" ][item_type_id][" shapes" ][item_shape_pos][" elements" ] = item_shape.shape_orig .shape . to_json ();
657642 for (Counter hole_pos = 0 ;
658- hole_pos < (Counter)item_shape.holes_orig .size ();
643+ hole_pos < (Counter)item_shape.shape_orig . holes .size ();
659644 ++hole_pos) {
660- const Shape& hole = item_shape.holes_orig [hole_pos];
645+ const Shape& hole = item_shape.shape_orig . holes [hole_pos];
661646 json[" item_types" ][item_type_id][" shapes" ][item_shape_pos][" holes" ][hole_pos][" type" ] = " general" ;
662647 json[" item_types" ][item_type_id][" shapes" ][item_shape_pos][" holes" ][hole_pos][" elements" ] = hole.to_json ();
663648 }
0 commit comments