for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Box packing (3D bin packing, knapsack problem).
*
* @author Doug Wright
*/
declare(strict_types=1);
namespace DVDoug\BoxPacker;
use function min;
* An item to be packed.
class OrientatedItem
{
* @var Item
protected $item;
* @var int
protected $width;
protected $length;
protected $depth;
* Constructor.
* @param Item $item
* @param int $width
* @param int $length
* @param int $depth
public function __construct(Item $item, int $width, int $length, int $depth)
$this->item = $item;
$this->width = $width;
$this->length = $length;
$this->depth = $depth;
}
* Item.
* @return Item
public function getItem(): Item
return $this->item;
* Item width in mm in it's packed orientation.
* @return int
public function getWidth(): int
return $this->width;
* Item length in mm in it's packed orientation.
public function getLength(): int
return $this->length;
* Item depth in mm in it's packed orientation.
public function getDepth(): int
return $this->depth;
* Calculate the surface footprint of the current orientation
public function getSurfaceFootprint(): int
return $this->width * $this->length;
* Is this item stable (low centre of gravity), calculated as if the tipping point is >15 degrees.
* N.B. Assumes equal weight distribution.
* @return bool
public function isStable(): bool
return atan(min($this->getLength(), $this->getWidth()) / $this->getDepth()) > 0.261; //radians