Calculates and returns the weight of all the rows in this layer.
=cut
subcalculate_weight {
my$self= shift;
my$weight= 0;
foreachmy$row(@{$self->rows}) {
$weight+= $row->calculate_weight;
}
return$weight;
}
=head2 pack_item(item)
Add a L<Box::Calc::Item> to this layer.
Returns 1 on success or 0 on failure.
=over
=item item
The L<Box::Calc::Item> instance you want to add to this layer.
=back
=cut
subpack_item {
my($self, $item, $count) = @_;
$count||= 1;
if($count> 5) {
$log->warn($item->{name}.' is causing infinite recursion in Box::Calc::Layer');
$log->debug(Dumper($item));
return0;
}
my$fill_z= $self->fill_z;
my$fill_y= $self->fill_y;
if($item->y > $self->max_y - $fill_y+ $self->rows->[-1]->fill_y # item would make the layer too wide
) {
$log->info($item->{name}.' would make the layer too wide, requesting new layer.');
return0;
}
if($fill_z> 0 && $item->z > $fill_z* 1.75 && $item->y < $fill_y) { # item would make the layer substantially taller, unless the layer is currently pretty narrow
$log->info($item->{name}.' would make this layer substantially taller, requesting new layer.');
return0;
}
if($self->rows->[-1]->pack_item($item)) {
return1;
}
else{
if($item->y > $self->max_y - $self->fill_y) {
$log->info($item->{name}.' will not fit in a new row in this layer, requesting new layer.');
return0;
}
else{
$self->create_row;
return$self->pack_item($item, $count+ 1);
}
}
}
=head2 packing_list(weight, list)
Updates a scalar reference with the weight of the layer and a hash reference of all the items in this layer.