Skip to content

Commit e44a6e4

Browse files
committed
Update shape dependency
1 parent e669a8c commit e44a6e4

File tree

8 files changed

+69
-82
lines changed

8 files changed

+69
-82
lines changed

extern/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ set(SHAPE_BUILD_TEST OFF)
3838
FetchContent_Declare(
3939
shape
4040
GIT_REPOSITORY https://github.com/fontanf/shape.git
41-
GIT_TAG 039a433f9f1275b2e69f727fdc0c5cf99ebeac27
41+
GIT_TAG b2d7a9c44daf5b7f88257f63ffc78b08b7f995d2
4242
#SOURCE_DIR "${PROJECT_SOURCE_DIR}/../shape/"
4343
EXCLUDE_FROM_ALL)
4444
FetchContent_MakeAvailable(shape)

include/packingsolver/irregular/instance.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ struct ItemType
193193
/** Return type of shape of the item type. */
194194
ShapeType shape_type() const;
195195

196-
std::pair<Point, Point> compute_min_max(
196+
AxisAlignedBoundingBox compute_min_max(
197197
Angle angle = 0.0,
198198
bool mirror = false,
199199
int type = 0) const;

src/irregular/branching_scheme.cpp

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@ BranchingScheme::BranchingScheme(
180180

181181
shape = shape::clean_extreme_slopes_inner(shape).front();
182182

183-
auto mm = shape.compute_min_max();
184-
bb_bin_type.x_min = mm.first.x;
185-
bb_bin_type.x_max = mm.second.x;
186-
bb_bin_type.y_min = mm.first.y;
187-
bb_bin_type.y_max = mm.second.y;
183+
AxisAlignedBoundingBox aabb = shape.compute_min_max();
184+
bb_bin_type.x_min = aabb.x_min;
185+
bb_bin_type.x_max = aabb.x_max;
186+
bb_bin_type.y_min = aabb.y_min;
187+
bb_bin_type.y_max = aabb.y_max;
188188

189189
LengthDbl y_min = bb_bin_type.y_min
190190
- (bb_bin_type.y_max - bb_bin_type.y_min)
@@ -565,16 +565,10 @@ BranchingScheme::BranchingScheme(
565565
}
566566
}
567567

568-
for (Support& support: direction_data.supporting_parts) {
569-
auto mm = support.shape.compute_min_max();
570-
support.min = mm.first;
571-
support.max = mm.second;
572-
}
573-
for (Support& support: direction_data.supported_parts) {
574-
auto mm = support.shape.compute_min_max();
575-
support.min = mm.first;
576-
support.max = mm.second;
577-
}
568+
for (Support& support: direction_data.supporting_parts)
569+
support.aabb = support.shape.compute_min_max();
570+
for (Support& support: direction_data.supported_parts)
571+
support.aabb = support.shape.compute_min_max();
578572
}
579573

580574
//for (TrapezoidSetId trapezoid_set_id = 0;
@@ -585,10 +579,10 @@ BranchingScheme::BranchingScheme(
585579
// std::cout << "item_type_id " << trapezoid_set.item_type_id
586580
// << " angle " << trapezoid_set.angle
587581
// << " mirror " << trapezoid_set.mirror
588-
// << " x_min " << item_type.compute_min_max(trapezoid_set.angle).first.x
589-
// << " x_max " << item_type.compute_min_max(trapezoid_set.angle).second.x
590-
// << " y_min " << item_type.compute_min_max(trapezoid_set.angle).first.y
591-
// << " y_max " << item_type.compute_min_max(trapezoid_set.angle).second.y
582+
// << " x_min " << item_type.compute_min_max(trapezoid_set.angle).x_min
583+
// << " x_max " << item_type.compute_min_max(trapezoid_set.angle).x_max
584+
// << " y_min " << item_type.compute_min_max(trapezoid_set.angle).y_min
585+
// << " y_max " << item_type.compute_min_max(trapezoid_set.angle).y_max
592586
// << std::endl;
593587
// std::cout << "trapezoid_set_id " << trapezoid_set_id << std::endl;
594588
// std::cout << "item_type_id " << trapezoid_set.item_type_id
@@ -1179,15 +1173,15 @@ BranchingScheme::Node BranchingScheme::child_tmp(
11791173
// Compute node.xe_max and node.ye_max.
11801174
Point xy = convert_point_back({node.x, node.y}, node.last_bin_direction);
11811175
xy = (1.0 / instance().parameters().scale_value) * xy;
1182-
auto mm = item_type.compute_min_max(
1176+
AxisAlignedBoundingBox aabb = item_type.compute_min_max(
11831177
trapezoid_set.angle,
11841178
trapezoid_set.mirror);
11851179
if (insertion.new_bin_direction == Direction::Any) { // Same bin
1186-
node.xe_max = std::max(parent.xe_max, xy.x + mm.second.x);
1187-
node.ye_max = std::max(parent.ye_max, xy.y + mm.second.y);
1180+
node.xe_max = std::max(parent.xe_max, xy.x + aabb.x_max);
1181+
node.ye_max = std::max(parent.ye_max, xy.y + aabb.y_max);
11881182
} else {
1189-
node.xe_max = xy.x + mm.second.x;
1190-
node.ye_max = xy.y + mm.second.y;
1183+
node.xe_max = xy.x + aabb.x_max;
1184+
node.ye_max = xy.y + aabb.y_max;
11911185
}
11921186

11931187
node.leftover_value = (bin_type.x_max - bin_type.x_min) * (bin_type.y_max - bin_type.y_min)
@@ -1602,11 +1596,11 @@ void BranchingScheme::update_insertion(
16021596
Insertion insertion = insertion_orig;
16031597
insertion.new_bin_direction = Direction::Any;
16041598

1605-
LengthDbl ys_tmp = supporting_part.min.y + insertion.supporting_part_y
1606-
- (supported_part.max.y - trapezoid_set.y_min)
1599+
LengthDbl ys_tmp = supporting_part.aabb.y_min + insertion.supporting_part_y
1600+
- (supported_part.aabb.y_max - trapezoid_set.y_min)
16071601
- instance_.parameters().scale_value * instance().parameters().item_item_minimum_spacing;
1608-
LengthDbl ye_tmp = supporting_part.max.y + insertion.supporting_part_y
1609-
+ (trapezoid_set.y_max - supported_part.min.y)
1602+
LengthDbl ye_tmp = supporting_part.aabb.y_max + insertion.supporting_part_y
1603+
+ (trapezoid_set.y_max - supported_part.aabb.y_min)
16101604
+ instance_.parameters().scale_value * instance().parameters().item_item_minimum_spacing;
16111605
if (strictly_greater(ys_tmp, parent->ye)
16121606
|| strictly_lesser(ye_tmp, parent->ys)) {
@@ -1923,10 +1917,10 @@ void BranchingScheme::insertion_trapezoid_set(
19231917
return;
19241918
}
19251919

1926-
insertion.ys = supporting_part.min.y + supporting_part_y
1920+
insertion.ys = supporting_part.aabb.y_min + supporting_part_y
19271921
- (trapezoid_set.y_max - trapezoid_set.y_min)
19281922
- instance_.parameters().scale_value * instance().parameters().item_item_minimum_spacing;
1929-
insertion.ye = supporting_part.max.y + supporting_part_y
1923+
insertion.ye = supporting_part.aabb.y_max + supporting_part_y
19301924
+ (trapezoid_set.y_max - trapezoid_set.y_min)
19311925
+ instance_.parameters().scale_value * instance().parameters().item_item_minimum_spacing;
19321926
parent->children_insertions.push_back(insertion);

src/irregular/branching_scheme.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ class BranchingScheme
148148
BinTypeId bin_type_id = -1;
149149
DefectId defect_id = -1;
150150

151-
Point min = {0, 0};
152-
Point max = {0, 0};
151+
AxisAlignedBoundingBox aabb;
153152
};
154153

155154
struct DirectionData

src/irregular/instance.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,20 @@ ShapeType ItemType::shape_type() const
9696
return ShapeType::GeneralShape;
9797
}
9898

99-
std::pair<Point, Point> ItemType::compute_min_max(
99+
AxisAlignedBoundingBox ItemType::compute_min_max(
100100
Angle angle,
101101
bool mirror,
102102
int type) const
103103
{
104-
LengthDbl x_min = std::numeric_limits<LengthDbl>::infinity();
105-
LengthDbl x_max = -std::numeric_limits<LengthDbl>::infinity();
106-
LengthDbl y_min = std::numeric_limits<LengthDbl>::infinity();
107-
LengthDbl y_max = -std::numeric_limits<LengthDbl>::infinity();
104+
AxisAlignedBoundingBox output;
108105
for (const ItemShape& item_shape: shapes) {
109-
auto points =
106+
AxisAlignedBoundingBox aabb =
110107
(type == 0)? item_shape.shape_orig.shape.compute_min_max(angle, mirror):
111108
(type == 1)? item_shape.shape_scaled.shape.compute_min_max(angle, mirror):
112109
item_shape.shape_inflated.shape.compute_min_max(angle, mirror);
113-
x_min = std::min(x_min, points.first.x);
114-
x_max = std::max(x_max, points.second.x);
115-
y_min = std::min(y_min, points.first.y);
116-
y_max = std::max(y_max, points.second.y);
110+
output = merge(output, aabb);
117111
}
118-
return {{x_min, y_min}, {x_max, y_max}};
112+
return output;
119113
}
120114

121115
bool ItemType::has_full_continuous_rotations() const
@@ -172,13 +166,13 @@ void ItemType::write_svg(
172166
"unable to open file \"" + file_path + "\".");
173167
}
174168

175-
auto mm = compute_min_max(0.0, false, 2);
176-
LengthDbl width = (mm.second.x - mm.first.x);
177-
LengthDbl height = (mm.second.y - mm.first.y);
169+
AxisAlignedBoundingBox aabb = compute_min_max(0.0, false, 2);
170+
LengthDbl width = (aabb.x_max - aabb.x_min);
171+
LengthDbl height = (aabb.y_max - aabb.y_min);
178172

179173
std::string s = "<svg viewBox=\""
180-
+ std::to_string(mm.first.x)
181-
+ " " + std::to_string(-mm.first.y - height)
174+
+ std::to_string(aabb.x_min)
175+
+ " " + std::to_string(-aabb.y_min - height)
182176
+ " " + std::to_string(width)
183177
+ " " + std::to_string(height)
184178
+ "\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";

src/irregular/instance_builder.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ BinTypeId InstanceBuilder::add_bin_type(
5555
bin_type.shape_orig = shape;
5656
bin_type.area_orig = shape.compute_area();
5757
auto points = shape.compute_min_max();
58-
bin_type.x_min = points.first.x;
59-
bin_type.x_max = points.second.x;
60-
bin_type.y_min = points.first.y;
61-
bin_type.y_max = points.second.y;
58+
bin_type.x_min = points.x_min;
59+
bin_type.x_max = points.x_max;
60+
bin_type.y_min = points.y_min;
61+
bin_type.y_max = points.y_max;
6262
bin_type.cost = (cost == -1)? bin_type.area_orig: cost;
6363
bin_type.copies = copies;
6464
bin_type.copies_min = copies_min;
@@ -423,11 +423,11 @@ Instance InstanceBuilder::build()
423423
bin_type_id < instance_.number_of_bin_types();
424424
++bin_type_id) {
425425
BinType& bin_type = instance_.bin_types_[bin_type_id];
426-
auto mm = bin_type.shape_orig.compute_min_max();
427-
value_max = (std::max)(value_max, std::abs(mm.first.x));
428-
value_max = (std::max)(value_max, std::abs(mm.first.y));
429-
value_max = (std::max)(value_max, std::abs(mm.second.x));
430-
value_max = (std::max)(value_max, std::abs(mm.second.y));
426+
AxisAlignedBoundingBox aabb = bin_type.shape_orig.compute_min_max();
427+
value_max = (std::max)(value_max, std::abs(aabb.x_min));
428+
value_max = (std::max)(value_max, std::abs(aabb.y_min));
429+
value_max = (std::max)(value_max, std::abs(aabb.x_max));
430+
value_max = (std::max)(value_max, std::abs(aabb.y_max));
431431
}
432432
instance_.parameters_.scale_value = 1024.0 / smallest_power_of_two_greater_or_equal(value_max);
433433
//std::cout << "instance_.scale_value() " << instance_.parameters().scale_value << std::endl;

src/irregular/optimize.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,9 @@ void optimize_open_dimension_sequential(
573573
item_type_id < instance.number_of_item_types();
574574
++item_type_id) {
575575
const ItemType& item_type = instance.item_type(item_type_id);
576-
auto mm = item_type.compute_min_max();
577-
LengthDbl dx = mm.second.x - mm.first.x;
578-
LengthDbl dy = mm.second.y - mm.first.y;
576+
AxisAlignedBoundingBox aabb = item_type.compute_min_max();
577+
LengthDbl dx = aabb.x_max - aabb.x_min;
578+
LengthDbl dy = aabb.y_max - aabb.y_min;
579579
a += dx * dy * item_type.copies;
580580
}
581581
LengthDbl x = std::sqrt(a / instance.parameters().open_dimension_xy_aspect_ratio);

src/irregular/solution.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ BinPos Solution::add_bin(
3737
number_of_bins_ += copies;
3838
bin_cost_ += copies * bin_type.cost;
3939
bin_area_ += copies * bin_type.area_orig;
40-
auto mm = bin_type.shape_orig.compute_min_max();
41-
x_min_ = mm.second.x;
42-
y_min_ = mm.second.y;
43-
x_max_ = mm.first.x;
44-
y_max_ = mm.first.y;
40+
AxisAlignedBoundingBox aabb = bin_type.shape_orig.compute_min_max();
41+
x_min_ = aabb.x_max;
42+
y_min_ = aabb.y_max;
43+
x_max_ = aabb.x_min;
44+
y_max_ = aabb.y_min;
4545

4646
return bins_.size() - 1;
4747
}
@@ -99,11 +99,11 @@ void Solution::add_item(
9999
item_copies_[item_type_id] += bin.copies;
100100

101101
if (bin_pos == (BinPos)bins_.size() - 1) {
102-
auto mm = item_type.compute_min_max(angle, mirror);
103-
x_min_ = std::min(x_min_, bl_corner.x + mm.first.x);
104-
y_min_ = std::min(y_min_, bl_corner.y + mm.first.y);
105-
x_max_ = std::max(x_max_, bl_corner.x + mm.second.x);
106-
y_max_ = std::max(y_max_, bl_corner.y + mm.second.y);
102+
AxisAlignedBoundingBox aabb = item_type.compute_min_max(angle, mirror);
103+
x_min_ = std::min(x_min_, bl_corner.x + aabb.x_min);
104+
y_min_ = std::min(y_min_, bl_corner.y + aabb.y_min);
105+
x_max_ = std::max(x_max_, bl_corner.x + aabb.x_max);
106+
y_max_ = std::max(y_max_, bl_corner.y + aabb.y_max);
107107
leftover_value_ = (bin_type.x_max - bin_type.x_min) * (bin_type.y_max - bin_type.y_min)
108108
- (x_max_ - bin_type.x_min) * (y_max_ - bin_type.y_min);
109109
}
@@ -435,13 +435,13 @@ void Solution::write_svg(
435435
const SolutionBin& bin = this->bin(bin_pos);
436436
const BinType& bin_type = instance().bin_type(bin.bin_type_id);
437437
const Shape& bin_shape = (scaled)? bin_type.shape_scaled: bin_type.shape_orig;
438-
auto bin_mm = bin_shape.compute_min_max();
439-
LengthDbl width = (bin_mm.second.x - bin_mm.first.x);
440-
LengthDbl height = (bin_mm.second.y - bin_mm.first.y);
438+
AxisAlignedBoundingBox bin_aabb = bin_shape.compute_min_max();
439+
LengthDbl width = (bin_aabb.x_max - bin_aabb.x_min);
440+
LengthDbl height = (bin_aabb.y_max - bin_aabb.y_min);
441441

442442
std::string s = "<svg viewBox=\""
443-
+ std::to_string(bin_mm.first.x)
444-
+ " " + std::to_string(-bin_mm.first.y - height)
443+
+ std::to_string(bin_aabb.x_min)
444+
+ " " + std::to_string(-bin_aabb.y_min - height)
445445
+ " " + std::to_string(width)
446446
+ " " + std::to_string(height)
447447
+ "\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
@@ -495,11 +495,11 @@ void Solution::write_svg(
495495

496496
file << shape.to_svg("blue");
497497

498-
auto mm = shape.compute_min_max(0.0);
499-
x_min = (std::min)(x_min, mm.first.x);
500-
x_max = (std::max)(x_max, mm.second.x);
501-
y_min = (std::min)(y_min, mm.first.y);
502-
y_max = (std::max)(y_max, mm.second.y);
498+
AxisAlignedBoundingBox aabb = shape.compute_min_max(0.0);
499+
x_min = (std::min)(x_min, aabb.x_min);
500+
x_max = (std::max)(x_max, aabb.x_max);
501+
y_min = (std::min)(y_min, aabb.y_min);
502+
y_max = (std::max)(y_max, aabb.y_max);
503503
}
504504

505505
// Write item type id.

0 commit comments

Comments
 (0)