1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Box packing (3D bin packing, knapsack problem). |
4
|
|
|
* |
5
|
|
|
* @author Doug Wright |
6
|
|
|
*/ |
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace DVDoug\BoxPacker; |
10
|
|
|
|
11
|
|
|
use JsonSerializable; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* A packed item. |
15
|
|
|
* |
16
|
|
|
* @author Doug Wright |
17
|
|
|
*/ |
18
|
|
|
class PackedItem implements JsonSerializable |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var int |
22
|
|
|
*/ |
23
|
|
|
protected $x; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var int |
27
|
|
|
*/ |
28
|
|
|
protected $y; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var int |
32
|
|
|
*/ |
33
|
|
|
protected $z; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var Item |
37
|
|
|
*/ |
38
|
|
|
protected $item; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var int |
42
|
|
|
*/ |
43
|
|
|
protected $width; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var int |
47
|
|
|
*/ |
48
|
|
|
protected $length; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var int |
52
|
|
|
*/ |
53
|
|
|
protected $depth; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* PackedItem constructor. |
57
|
|
|
*/ |
58
|
77 |
|
public function __construct(Item $item, int $x, int $y, int $z, int $width, int $length, int $depth) |
59
|
|
|
{ |
60
|
77 |
|
$this->item = $item; |
61
|
77 |
|
$this->x = $x; |
62
|
77 |
|
$this->y = $y; |
63
|
77 |
|
$this->z = $z; |
64
|
77 |
|
$this->width = $width; |
65
|
77 |
|
$this->length = $length; |
66
|
77 |
|
$this->depth = $depth; |
67
|
77 |
|
} |
68
|
|
|
|
69
|
76 |
|
public function getX(): int |
70
|
|
|
{ |
71
|
76 |
|
return $this->x; |
72
|
|
|
} |
73
|
|
|
|
74
|
76 |
|
public function getY(): int |
75
|
|
|
{ |
76
|
76 |
|
return $this->y; |
77
|
|
|
} |
78
|
|
|
|
79
|
76 |
|
public function getZ(): int |
80
|
|
|
{ |
81
|
76 |
|
return $this->z; |
82
|
|
|
} |
83
|
|
|
|
84
|
76 |
|
public function getItem(): Item |
85
|
|
|
{ |
86
|
76 |
|
return $this->item; |
87
|
|
|
} |
88
|
|
|
|
89
|
76 |
|
public function getWidth(): int |
90
|
|
|
{ |
91
|
76 |
|
return $this->width; |
92
|
|
|
} |
93
|
|
|
|
94
|
76 |
|
public function getLength(): int |
95
|
|
|
{ |
96
|
76 |
|
return $this->length; |
97
|
|
|
} |
98
|
|
|
|
99
|
76 |
|
public function getDepth(): int |
100
|
|
|
{ |
101
|
76 |
|
return $this->depth; |
102
|
|
|
} |
103
|
|
|
|
104
|
76 |
|
public function getVolume(): int |
105
|
|
|
{ |
106
|
76 |
|
return $this->width * $this->length * $this->depth; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return PackedItem |
111
|
|
|
*/ |
112
|
75 |
|
public static function fromOrientatedItem(OrientatedItem $orientatedItem, int $x, int $y, int $z): self |
113
|
|
|
{ |
114
|
75 |
|
return new static( |
115
|
75 |
|
$orientatedItem->getItem(), |
116
|
|
|
$x, |
117
|
|
|
$y, |
118
|
|
|
$z, |
119
|
75 |
|
$orientatedItem->getWidth(), |
120
|
75 |
|
$orientatedItem->getLength(), |
121
|
75 |
|
$orientatedItem->getDepth() |
122
|
|
|
); |
123
|
|
|
} |
124
|
|
|
|
125
|
75 |
|
public function toOrientatedItem(): OrientatedItem |
126
|
|
|
{ |
127
|
75 |
|
return new OrientatedItem($this->item, $this->width, $this->length, $this->depth); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function jsonSerialize(): array |
131
|
|
|
{ |
132
|
|
|
return [ |
133
|
|
|
'x' => $this->x, |
134
|
|
|
'y' => $this->y, |
135
|
|
|
'z' => $this->z, |
136
|
|
|
'width' => $this->width, |
137
|
|
|
'length' => $this->length, |
138
|
|
|
'depth' => $this->depth, |
139
|
|
|
'item' => [ |
140
|
|
|
'description' => $this->item->getDescription(), |
141
|
|
|
'width' => $this->item->getWidth(), |
142
|
|
|
'length' => $this->item->getLength(), |
143
|
|
|
'depth' => $this->item->getDepth(), |
144
|
|
|
'keepFlat' => $this->item->getKeepFlat(), |
|
|
|
|
145
|
|
|
], |
146
|
|
|
]; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.