Skip to content

Commit 78ac84c

Browse files
committed
Add extra calls to clean_extreme_slopes
1 parent a972d8e commit 78ac84c

File tree

3 files changed

+25
-30
lines changed

3 files changed

+25
-30
lines changed

extern/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ FetchContent_MakeAvailable(optimizationtools)
1414
FetchContent_Declare(
1515
shape
1616
GIT_REPOSITORY https://github.com/fontanf/shape.git
17-
GIT_TAG 333bea2942ab297cd067add1bb6e1bbb333dcd75
17+
GIT_TAG d062b436349b12c659ca1c5b6718ec0e9c5da7a2
1818
#SOURCE_DIR "${PROJECT_SOURCE_DIR}/../shape/"
1919
EXCLUDE_FROM_ALL)
2020
FetchContent_MakeAvailable(shape)

src/irregular/branching_scheme.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ BranchingScheme::BranchingScheme(
100100
BranchingSchemeBinType& bb_bin_type = direction_data.bin_types[bin_type_id];
101101
Shape shape = convert_shape(bin_type.shape_scaled, direction);
102102

103+
shape = shape::clean_extreme_slopes(shape, false);
104+
103105
auto mm = shape.compute_min_max();
104106
bb_bin_type.x_min = mm.first.x;
105107
bb_bin_type.x_max = mm.second.x;
@@ -155,7 +157,9 @@ BranchingScheme::BranchingScheme(
155157
border_pos < (DefectId)simplified_bin_type.borders.size();
156158
++border_pos) {
157159
const Shape& simplified_inflated_shape = simplified_bin_type.borders[border_pos].shape_inflated;
158-
const Shape& shape_inflated = convert_shape(simplified_inflated_shape, direction);
160+
Shape shape_inflated = convert_shape(simplified_inflated_shape, direction);
161+
162+
shape_inflated = shape::clean_extreme_slopes(shape_inflated, true);
159163

160164
// Supports.
161165
shape::ShapeSupports supports = shape::compute_shape_supports(shape_inflated, false);
@@ -185,7 +189,9 @@ BranchingScheme::BranchingScheme(
185189
++defect_id) {
186190
//std::cout << "defect_id " << defect_id << std::endl;
187191
const Shape& simplified_inflated_shape = simplified_bin_type.defects[defect_id].shape_inflated;
188-
const Shape& shape_inflated = convert_shape(simplified_inflated_shape, direction);
192+
Shape shape_inflated = convert_shape(simplified_inflated_shape, direction);
193+
194+
shape_inflated = shape::clean_extreme_slopes(shape_inflated, true);
189195

190196
// Supports.
191197
shape::ShapeSupports supports = shape::compute_shape_supports(shape_inflated, false);
@@ -204,7 +210,9 @@ BranchingScheme::BranchingScheme(
204210
hole_pos < (ShapePos)simplified_bin_type.defects[defect_id].holes_deflated.size();
205211
++hole_pos) {
206212
const Shape& simplified_deflated_shape = simplified_bin_type.defects[defect_id].holes_deflated[hole_pos];
207-
const Shape& shape_deflated = convert_shape(simplified_deflated_shape, direction);
213+
Shape shape_deflated = convert_shape(simplified_deflated_shape, direction);
214+
215+
shape_deflated = shape::clean_extreme_slopes(shape_deflated, false);
208216

209217
// Update trapezoidation input.
210218
holes_deflated.push_back(shape_deflated);
@@ -286,8 +294,11 @@ BranchingScheme::BranchingScheme(
286294
+ "_inflated_simplified.svg");
287295
}
288296

289-
const Shape& shape = convert_shape(simplified_shape, angle_range.first, mirror, direction);
290-
const Shape& shape_inflated = convert_shape(simplified_inflated_shape, angle_range.first, mirror, direction);
297+
Shape shape = convert_shape(simplified_shape, angle_range.first, mirror, direction);
298+
Shape shape_inflated = convert_shape(simplified_inflated_shape, angle_range.first, mirror, direction);
299+
300+
shape = shape::clean_extreme_slopes(shape, true);
301+
shape_inflated = shape::clean_extreme_slopes(shape_inflated, true);
291302

292303
if (write_shapes) {
293304
simplified_inflated_shape.write_svg(
@@ -332,7 +343,9 @@ BranchingScheme::BranchingScheme(
332343
++hole_pos) {
333344
const Shape& simplified_shape = simplified_item_type.shapes[item_shape_pos].holes[hole_pos];
334345

335-
const Shape& shape = convert_shape(simplified_shape, angle_range.first, mirror, direction);
346+
Shape shape = convert_shape(simplified_shape, angle_range.first, mirror, direction);
347+
348+
shape = shape::clean_extreme_slopes(shape, false);
336349

337350
// Update trapezoidation input.
338351
holes.push_back(shape);
@@ -358,7 +371,9 @@ BranchingScheme::BranchingScheme(
358371
++hole_pos) {
359372
const Shape& simplified_deflated_shape = simplified_item_type.shapes[item_shape_pos].holes_deflated[hole_pos];
360373

361-
const Shape& shape_deflated = convert_shape(simplified_deflated_shape, angle_range.first, mirror, direction);
374+
Shape shape_deflated = convert_shape(simplified_deflated_shape, angle_range.first, mirror, direction);
375+
376+
shape_deflated = shape::clean_extreme_slopes(shape_deflated, false);
362377

363378
// Update trapezoidation input.
364379
holes_deflated.push_back(shape_deflated);

src/irregular/instance_builder.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -441,17 +441,7 @@ std::pair<Shape, std::vector<Shape>> process_shape_outer(
441441
{
442442
bool outer = true;
443443
Shape shape_tmp = shape::approximate_by_line_segments(shape, 1, outer);
444-
for (int i = 0;; ++i) {
445-
if (i == 100) {
446-
throw std::runtime_error(
447-
"packingsolver::irregular::process_shape_outer: "
448-
"too many iterations.");
449-
}
450-
auto res = shape::clean_extreme_slopes(shape_tmp, outer);
451-
if (!res.first)
452-
break;
453-
shape_tmp = res.second;
454-
}
444+
shape_tmp = shape::clean_extreme_slopes(shape_tmp, outer);
455445
return shape::remove_self_intersections(shape_tmp);
456446
}
457447

@@ -460,17 +450,7 @@ std::vector<Shape> process_shape_inner(
460450
{
461451
bool outer = false;
462452
Shape shape_tmp = shape::approximate_by_line_segments(shape, 1, outer);
463-
for (int i = 0;; ++i) {
464-
if (i == 100) {
465-
throw std::runtime_error(
466-
"packingsolver::irregular::process_shape_inner: "
467-
"too many iterations.");
468-
}
469-
auto res = shape::clean_extreme_slopes(shape_tmp, outer);
470-
if (!res.first)
471-
break;
472-
shape_tmp = res.second;
473-
}
453+
shape_tmp = shape::clean_extreme_slopes(shape_tmp, outer);
474454
return shape::extract_all_holes_from_self_intersecting_hole(shape_tmp);
475455
}
476456

0 commit comments

Comments
 (0)