Completed
Push — master ( a3b573...a397ce )
by Doug
01:54
created

OrientatedItem::isStable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Box packing (3D bin packing, knapsack problem)
4
 * @package BoxPacker
5
 * @author Doug Wright
6
 */
7
namespace DVDoug\BoxPacker;
8
9
/**
10
 * An item to be packed
11
 * @author Doug Wright
12
 * @package BoxPacker
13
 */
14
class OrientatedItem
15
{
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
     * @param Item $item
40
     * @param int $width
41
     * @param int $length
42
     * @param int $depth
43
     */
44 29
    public function __construct(Item $item, $width, $length, $depth) {
45 29
        $this->item = $item;
46 29
        $this->width = $width;
47 29
        $this->length = $length;
48 29
        $this->depth = $depth;
49
    }
50
51
    /**
52
     * Item
53
     *
54
     * @return Item
55
     */
56 29
    public function getItem() {
57 29
        return $this->item;
58
    }
59
60
    /**
61
     * Item width in mm in it's packed orientation
62
     *
63
     * @return int
64
     */
65 29
    public function getWidth() {
66 29
        return $this->width;
67
    }
68
69
    /**
70
     * Item length in mm in it's packed orientation
71
     *
72
     * @return int
73
     */
74 29
    public function getLength() {
75 29
        return $this->length;
76
    }
77
78
    /**
79
     * Item depth in mm in it's packed orientation
80
     *
81
     * @return int
82
     */
83 29
    public function getDepth() {
84 29
        return $this->depth;
85
    }
86
87
    /**
88
     * Is this orientation stable (low centre of gravity)
89
     * N.B. Assumes equal weight distribution
90
     *
91
     * @return bool
92
     */
93 29
    public function isStable() {
94 29
        return $this->getDepth() <= min($this->getLength(), $this->getWidth());
95
    }
96
}
97
98