Passed
Push — 1.x-dev ( e28a82...a67168 )
by Doug
07:51 queued 06:22
created

OrientatedItem   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 99
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getDepth() 0 3 1
A getWidth() 0 3 1
A getLength() 0 3 1
A getItem() 0 3 1
A __construct() 0 6 1
A getSurfaceFootprint() 0 3 1
A isStable() 0 3 1
1
<?php
2
/**
3
 * Box packing (3D bin packing, knapsack problem).
4
 *
5
 * @author Doug Wright
6
 */
7
8
namespace DVDoug\BoxPacker;
9
10
/**
11
 * An item to be packed.
12
 *
13
 * @author Doug Wright
14
 */
15
class OrientatedItem
16
{
17
    /**
18
     * @var Item
19
     */
20
    protected $item;
21
22
    /**
23
     * @var int
24
     */
25
    protected $width;
26
27
    /**
28
     * @var int
29
     */
30
    protected $length;
31
32
    /**
33
     * @var int
34
     */
35
    protected $depth;
36
37
    /**
38
     * Constructor.
39
     *
40
     * @param Item $item
41
     * @param int  $width
42
     * @param int  $length
43
     * @param int  $depth
44
     */
45 19
    public function __construct(Item $item, $width, $length, $depth)
46
    {
47 19
        $this->item = $item;
48 19
        $this->width = $width;
49 19
        $this->length = $length;
50 19
        $this->depth = $depth;
51 19
    }
52
53
    /**
54
     * Item.
55
     *
56
     * @return Item
57
     */
58 19
    public function getItem()
59
    {
60 19
        return $this->item;
61
    }
62
63
    /**
64
     * Item width in mm in it's packed orientation.
65
     *
66
     * @return int
67
     */
68 19
    public function getWidth()
69
    {
70 19
        return $this->width;
71
    }
72
73
    /**
74
     * Item length in mm in it's packed orientation.
75
     *
76
     * @return int
77
     */
78 19
    public function getLength()
79
    {
80 19
        return $this->length;
81
    }
82
83
    /**
84
     * Item depth in mm in it's packed orientation.
85
     *
86
     * @return int
87
     */
88 19
    public function getDepth()
89
    {
90 19
        return $this->depth;
91
    }
92
93
94
    /**
95
     * Calculate the surface footprint of the current orientation
96
     *
97
     * @return int
98
     */
99 12
    public function getSurfaceFootprint()
100
    {
101 12
        return $this->width * $this->length;
102
    }
103
104
    /**
105
     * Is this item stable (low centre of gravity), calculated as if the tipping point is >15 degrees.
106
     *
107
     * N.B. Assumes equal weight distribution.
108
     *
109
     * @return bool
110
     */
111 19
    public function isStable()
112
    {
113 19
        return atan(min($this->getLength(), $this->getWidth()) / $this->getDepth()) > 0.261; //radians
114
    }
115
}
116