Skip to content

Commit

Permalink
Add details of used/remaining space to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Aug 27, 2017
1 parent bed9d7d commit e3d2179
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions docs/advanced-usage.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
Advanced usage
==============

Used / remaining space
----------------------

After packing it is possible to see how much physical space in each ``PackedBox`` is taken up with items,
and how much space was unused (air). This information might be useful to determine whether it would be useful to source
alternative/additional sizes of box.

At a high level, the ``getVolumeUtilisation()`` method exists which calculates how full the box is as a percentage of volume.

Lower-level methods are also available for examining this data in detail either using ``getUsed[Width|Length|Depth()``
(a hypothetical box placed around the items) or ``getRemaining[Width|Length|Depth()`` (the difference between the dimensions of
the actual box and the hypothetical box).

.. note::

BoxPacker will always try to pack items into the smallest box available

Example - warning on a massively oversized box
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: php
<?php
// assuming packing already took place
foreach ($packedBoxes as $packedBox) {
if ($packedBox->getVolumeUtilisation() < 20) {
// box is 80% air, log a warning
}
}
Custom Constraints
------------------

For more advanced use cases where greater control over the contents of each box is required (e.g. legal limits on the number of
hazardous items per box, or perhaps fragile items requiring an extra-strong outer box) you may implement the ``BoxPacker\ConstrainedItem``
interface which contains an additional callback method allowing you to decide whether to allow an item may be packed into a box
Expand All @@ -9,11 +44,8 @@ or not.
As with all other library methods, the objects passed into this callback are your own - you have access to their full range of
properties and methods to use when evaluating a constraint, not only those defined by the standard ``BoxPacker\Item`` interface.

Example
-------

Only allow 2 batteries per box
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Example - only allow 2 batteries per box
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: php
Expand Down

0 comments on commit e3d2179

Please sign in to comment.