Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ set(SHAPE_BUILD_TEST OFF)
FetchContent_Declare(
shape
GIT_REPOSITORY https://github.com/fontanf/shape.git
GIT_TAG 039a433f9f1275b2e69f727fdc0c5cf99ebeac27
GIT_TAG b2d7a9c44daf5b7f88257f63ffc78b08b7f995d2
#SOURCE_DIR "${PROJECT_SOURCE_DIR}/../shape/"
EXCLUDE_FROM_ALL)
FetchContent_MakeAvailable(shape)
Expand Down
2 changes: 1 addition & 1 deletion include/packingsolver/irregular/instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ struct ItemType
/** Return type of shape of the item type. */
ShapeType shape_type() const;

std::pair<Point, Point> compute_min_max(
AxisAlignedBoundingBox compute_min_max(
Angle angle = 0.0,
bool mirror = false,
int type = 0) const;
Expand Down
54 changes: 24 additions & 30 deletions src/irregular/branching_scheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ BranchingScheme::BranchingScheme(

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

auto mm = shape.compute_min_max();
bb_bin_type.x_min = mm.first.x;
bb_bin_type.x_max = mm.second.x;
bb_bin_type.y_min = mm.first.y;
bb_bin_type.y_max = mm.second.y;
AxisAlignedBoundingBox aabb = shape.compute_min_max();
bb_bin_type.x_min = aabb.x_min;
bb_bin_type.x_max = aabb.x_max;
bb_bin_type.y_min = aabb.y_min;
bb_bin_type.y_max = aabb.y_max;

LengthDbl y_min = bb_bin_type.y_min
- (bb_bin_type.y_max - bb_bin_type.y_min)
Expand Down Expand Up @@ -565,16 +565,10 @@ BranchingScheme::BranchingScheme(
}
}

for (Support& support: direction_data.supporting_parts) {
auto mm = support.shape.compute_min_max();
support.min = mm.first;
support.max = mm.second;
}
for (Support& support: direction_data.supported_parts) {
auto mm = support.shape.compute_min_max();
support.min = mm.first;
support.max = mm.second;
}
for (Support& support: direction_data.supporting_parts)
support.aabb = support.shape.compute_min_max();
for (Support& support: direction_data.supported_parts)
support.aabb = support.shape.compute_min_max();
}

//for (TrapezoidSetId trapezoid_set_id = 0;
Expand All @@ -585,10 +579,10 @@ BranchingScheme::BranchingScheme(
// std::cout << "item_type_id " << trapezoid_set.item_type_id
// << " angle " << trapezoid_set.angle
// << " mirror " << trapezoid_set.mirror
// << " x_min " << item_type.compute_min_max(trapezoid_set.angle).first.x
// << " x_max " << item_type.compute_min_max(trapezoid_set.angle).second.x
// << " y_min " << item_type.compute_min_max(trapezoid_set.angle).first.y
// << " y_max " << item_type.compute_min_max(trapezoid_set.angle).second.y
// << " x_min " << item_type.compute_min_max(trapezoid_set.angle).x_min
// << " x_max " << item_type.compute_min_max(trapezoid_set.angle).x_max
// << " y_min " << item_type.compute_min_max(trapezoid_set.angle).y_min
// << " y_max " << item_type.compute_min_max(trapezoid_set.angle).y_max
// << std::endl;
// std::cout << "trapezoid_set_id " << trapezoid_set_id << std::endl;
// std::cout << "item_type_id " << trapezoid_set.item_type_id
Expand Down Expand Up @@ -1179,15 +1173,15 @@ BranchingScheme::Node BranchingScheme::child_tmp(
// Compute node.xe_max and node.ye_max.
Point xy = convert_point_back({node.x, node.y}, node.last_bin_direction);
xy = (1.0 / instance().parameters().scale_value) * xy;
auto mm = item_type.compute_min_max(
AxisAlignedBoundingBox aabb = item_type.compute_min_max(
trapezoid_set.angle,
trapezoid_set.mirror);
if (insertion.new_bin_direction == Direction::Any) { // Same bin
node.xe_max = std::max(parent.xe_max, xy.x + mm.second.x);
node.ye_max = std::max(parent.ye_max, xy.y + mm.second.y);
node.xe_max = std::max(parent.xe_max, xy.x + aabb.x_max);
node.ye_max = std::max(parent.ye_max, xy.y + aabb.y_max);
} else {
node.xe_max = xy.x + mm.second.x;
node.ye_max = xy.y + mm.second.y;
node.xe_max = xy.x + aabb.x_max;
node.ye_max = xy.y + aabb.y_max;
}

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

LengthDbl ys_tmp = supporting_part.min.y + insertion.supporting_part_y
- (supported_part.max.y - trapezoid_set.y_min)
LengthDbl ys_tmp = supporting_part.aabb.y_min + insertion.supporting_part_y
- (supported_part.aabb.y_max - trapezoid_set.y_min)
- instance_.parameters().scale_value * instance().parameters().item_item_minimum_spacing;
LengthDbl ye_tmp = supporting_part.max.y + insertion.supporting_part_y
+ (trapezoid_set.y_max - supported_part.min.y)
LengthDbl ye_tmp = supporting_part.aabb.y_max + insertion.supporting_part_y
+ (trapezoid_set.y_max - supported_part.aabb.y_min)
+ instance_.parameters().scale_value * instance().parameters().item_item_minimum_spacing;
if (strictly_greater(ys_tmp, parent->ye)
|| strictly_lesser(ye_tmp, parent->ys)) {
Expand Down Expand Up @@ -1923,10 +1917,10 @@ void BranchingScheme::insertion_trapezoid_set(
return;
}

insertion.ys = supporting_part.min.y + supporting_part_y
insertion.ys = supporting_part.aabb.y_min + supporting_part_y
- (trapezoid_set.y_max - trapezoid_set.y_min)
- instance_.parameters().scale_value * instance().parameters().item_item_minimum_spacing;
insertion.ye = supporting_part.max.y + supporting_part_y
insertion.ye = supporting_part.aabb.y_max + supporting_part_y
+ (trapezoid_set.y_max - trapezoid_set.y_min)
+ instance_.parameters().scale_value * instance().parameters().item_item_minimum_spacing;
parent->children_insertions.push_back(insertion);
Expand Down
3 changes: 1 addition & 2 deletions src/irregular/branching_scheme.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ class BranchingScheme
BinTypeId bin_type_id = -1;
DefectId defect_id = -1;

Point min = {0, 0};
Point max = {0, 0};
AxisAlignedBoundingBox aabb;
};

struct DirectionData
Expand Down
26 changes: 10 additions & 16 deletions src/irregular/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,20 @@ ShapeType ItemType::shape_type() const
return ShapeType::GeneralShape;
}

std::pair<Point, Point> ItemType::compute_min_max(
AxisAlignedBoundingBox ItemType::compute_min_max(
Angle angle,
bool mirror,
int type) const
{
LengthDbl x_min = std::numeric_limits<LengthDbl>::infinity();
LengthDbl x_max = -std::numeric_limits<LengthDbl>::infinity();
LengthDbl y_min = std::numeric_limits<LengthDbl>::infinity();
LengthDbl y_max = -std::numeric_limits<LengthDbl>::infinity();
AxisAlignedBoundingBox output;
for (const ItemShape& item_shape: shapes) {
auto points =
AxisAlignedBoundingBox aabb =
(type == 0)? item_shape.shape_orig.shape.compute_min_max(angle, mirror):
(type == 1)? item_shape.shape_scaled.shape.compute_min_max(angle, mirror):
item_shape.shape_inflated.shape.compute_min_max(angle, mirror);
x_min = std::min(x_min, points.first.x);
x_max = std::max(x_max, points.second.x);
y_min = std::min(y_min, points.first.y);
y_max = std::max(y_max, points.second.y);
output = merge(output, aabb);
}
return {{x_min, y_min}, {x_max, y_max}};
return output;
}

bool ItemType::has_full_continuous_rotations() const
Expand Down Expand Up @@ -172,13 +166,13 @@ void ItemType::write_svg(
"unable to open file \"" + file_path + "\".");
}

auto mm = compute_min_max(0.0, false, 2);
LengthDbl width = (mm.second.x - mm.first.x);
LengthDbl height = (mm.second.y - mm.first.y);
AxisAlignedBoundingBox aabb = compute_min_max(0.0, false, 2);
LengthDbl width = (aabb.x_max - aabb.x_min);
LengthDbl height = (aabb.y_max - aabb.y_min);

std::string s = "<svg viewBox=\""
+ std::to_string(mm.first.x)
+ " " + std::to_string(-mm.first.y - height)
+ std::to_string(aabb.x_min)
+ " " + std::to_string(-aabb.y_min - height)
+ " " + std::to_string(width)
+ " " + std::to_string(height)
+ "\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
Expand Down
18 changes: 9 additions & 9 deletions src/irregular/instance_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ BinTypeId InstanceBuilder::add_bin_type(
bin_type.shape_orig = shape;
bin_type.area_orig = shape.compute_area();
auto points = shape.compute_min_max();
bin_type.x_min = points.first.x;
bin_type.x_max = points.second.x;
bin_type.y_min = points.first.y;
bin_type.y_max = points.second.y;
bin_type.x_min = points.x_min;
bin_type.x_max = points.x_max;
bin_type.y_min = points.y_min;
bin_type.y_max = points.y_max;
bin_type.cost = (cost == -1)? bin_type.area_orig: cost;
bin_type.copies = copies;
bin_type.copies_min = copies_min;
Expand Down Expand Up @@ -423,11 +423,11 @@ Instance InstanceBuilder::build()
bin_type_id < instance_.number_of_bin_types();
++bin_type_id) {
BinType& bin_type = instance_.bin_types_[bin_type_id];
auto mm = bin_type.shape_orig.compute_min_max();
value_max = (std::max)(value_max, std::abs(mm.first.x));
value_max = (std::max)(value_max, std::abs(mm.first.y));
value_max = (std::max)(value_max, std::abs(mm.second.x));
value_max = (std::max)(value_max, std::abs(mm.second.y));
AxisAlignedBoundingBox aabb = bin_type.shape_orig.compute_min_max();
value_max = (std::max)(value_max, std::abs(aabb.x_min));
value_max = (std::max)(value_max, std::abs(aabb.y_min));
value_max = (std::max)(value_max, std::abs(aabb.x_max));
value_max = (std::max)(value_max, std::abs(aabb.y_max));
}
instance_.parameters_.scale_value = 1024.0 / smallest_power_of_two_greater_or_equal(value_max);
//std::cout << "instance_.scale_value() " << instance_.parameters().scale_value << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions src/irregular/optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,9 @@ void optimize_open_dimension_sequential(
item_type_id < instance.number_of_item_types();
++item_type_id) {
const ItemType& item_type = instance.item_type(item_type_id);
auto mm = item_type.compute_min_max();
LengthDbl dx = mm.second.x - mm.first.x;
LengthDbl dy = mm.second.y - mm.first.y;
AxisAlignedBoundingBox aabb = item_type.compute_min_max();
LengthDbl dx = aabb.x_max - aabb.x_min;
LengthDbl dy = aabb.y_max - aabb.y_min;
a += dx * dy * item_type.copies;
}
LengthDbl x = std::sqrt(a / instance.parameters().open_dimension_xy_aspect_ratio);
Expand Down
40 changes: 20 additions & 20 deletions src/irregular/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ BinPos Solution::add_bin(
number_of_bins_ += copies;
bin_cost_ += copies * bin_type.cost;
bin_area_ += copies * bin_type.area_orig;
auto mm = bin_type.shape_orig.compute_min_max();
x_min_ = mm.second.x;
y_min_ = mm.second.y;
x_max_ = mm.first.x;
y_max_ = mm.first.y;
AxisAlignedBoundingBox aabb = bin_type.shape_orig.compute_min_max();
x_min_ = aabb.x_max;
y_min_ = aabb.y_max;
x_max_ = aabb.x_min;
y_max_ = aabb.y_min;

return bins_.size() - 1;
}
Expand Down Expand Up @@ -99,11 +99,11 @@ void Solution::add_item(
item_copies_[item_type_id] += bin.copies;

if (bin_pos == (BinPos)bins_.size() - 1) {
auto mm = item_type.compute_min_max(angle, mirror);
x_min_ = std::min(x_min_, bl_corner.x + mm.first.x);
y_min_ = std::min(y_min_, bl_corner.y + mm.first.y);
x_max_ = std::max(x_max_, bl_corner.x + mm.second.x);
y_max_ = std::max(y_max_, bl_corner.y + mm.second.y);
AxisAlignedBoundingBox aabb = item_type.compute_min_max(angle, mirror);
x_min_ = std::min(x_min_, bl_corner.x + aabb.x_min);
y_min_ = std::min(y_min_, bl_corner.y + aabb.y_min);
x_max_ = std::max(x_max_, bl_corner.x + aabb.x_max);
y_max_ = std::max(y_max_, bl_corner.y + aabb.y_max);
leftover_value_ = (bin_type.x_max - bin_type.x_min) * (bin_type.y_max - bin_type.y_min)
- (x_max_ - bin_type.x_min) * (y_max_ - bin_type.y_min);
}
Expand Down Expand Up @@ -435,13 +435,13 @@ void Solution::write_svg(
const SolutionBin& bin = this->bin(bin_pos);
const BinType& bin_type = instance().bin_type(bin.bin_type_id);
const Shape& bin_shape = (scaled)? bin_type.shape_scaled: bin_type.shape_orig;
auto bin_mm = bin_shape.compute_min_max();
LengthDbl width = (bin_mm.second.x - bin_mm.first.x);
LengthDbl height = (bin_mm.second.y - bin_mm.first.y);
AxisAlignedBoundingBox bin_aabb = bin_shape.compute_min_max();
LengthDbl width = (bin_aabb.x_max - bin_aabb.x_min);
LengthDbl height = (bin_aabb.y_max - bin_aabb.y_min);

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

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

auto mm = shape.compute_min_max(0.0);
x_min = (std::min)(x_min, mm.first.x);
x_max = (std::max)(x_max, mm.second.x);
y_min = (std::min)(y_min, mm.first.y);
y_max = (std::max)(y_max, mm.second.y);
AxisAlignedBoundingBox aabb = shape.compute_min_max(0.0);
x_min = (std::min)(x_min, aabb.x_min);
x_max = (std::max)(x_max, aabb.x_max);
y_min = (std::min)(y_min, aabb.y_min);
y_max = (std::max)(y_max, aabb.y_max);
}

// Write item type id.
Expand Down
Loading