rectpackbin 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +18 -0
- package/{src/index.js → index.js} +35 -14
- package/package.json +7 -3
- package/src/rectpack/geometry.js +0 -343
- package/src/rectpack/guillotine copy.js +406 -0
- package/src/rectpack/guillotine.js +283 -67
- package/src/rectpack/index.js +90 -0
- package/src/rectpack/packAlgo.js +3 -2
- package/src/rectpack/packer.js +342 -81
- package/src/rectpack/packer2.js +144 -0
- package/test/guillotine/GuillotineBssfSas2.test.js +141 -0
- package/test/packer/packer.test.js +466 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
|
3
|
+
// Hover to view descriptions of existing attributes.
|
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"configurations": [
|
|
7
|
+
|
|
8
|
+
{
|
|
9
|
+
"type": "node",
|
|
10
|
+
"request": "launch",
|
|
11
|
+
"name": "Launch Program",
|
|
12
|
+
"skipFiles": [
|
|
13
|
+
"<node_internals>/**"
|
|
14
|
+
],
|
|
15
|
+
"program": "${workspaceFolder}\\driver_code.js"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
GuillotineBafSas, GuillotineBafLas,
|
|
10
10
|
GuillotineBafSlas, GuillotineBafLlas,
|
|
11
11
|
GuillotineBafMaxas, GuillotineBafMinas
|
|
12
|
-
} from './rectpack/guillotine.js';
|
|
12
|
+
} from './src/rectpack/guillotine.js';
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
@@ -17,14 +17,27 @@ import {
|
|
|
17
17
|
import {
|
|
18
18
|
SORT_AREA, SORT_PERI, SORT_DIFF, SORT_SSIDE,
|
|
19
19
|
SORT_LSIDE, SORT_RATIO, SORT_NONE
|
|
20
|
-
} from './rectpack/packer.js';
|
|
20
|
+
} from './src/rectpack/packer.js';
|
|
21
21
|
|
|
22
22
|
// packer.js - classes and functions
|
|
23
23
|
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
float2dec,
|
|
25
|
+
SORT_AREA,
|
|
26
|
+
SORT_PERI,
|
|
27
|
+
SORT_DIFF,
|
|
28
|
+
SORT_SSIDE,
|
|
29
|
+
SORT_LSIDE,
|
|
30
|
+
SORT_RATIO,
|
|
31
|
+
SORT_NONE,
|
|
32
|
+
BinFactory,
|
|
33
|
+
PackerBNFMixin,
|
|
34
|
+
PackerBFFMixin,
|
|
35
|
+
PackerBBFMixin,
|
|
36
|
+
PackerOnline,
|
|
37
|
+
PackingMode,
|
|
38
|
+
PackingBin,
|
|
39
|
+
newPacker
|
|
40
|
+
} from './src/rectpack/packer.js';
|
|
28
41
|
|
|
29
42
|
// guillotine.js
|
|
30
43
|
export {
|
|
@@ -43,17 +56,25 @@ export {
|
|
|
43
56
|
|
|
44
57
|
|
|
45
58
|
|
|
46
|
-
// packer.js - constants
|
|
47
|
-
export {
|
|
48
|
-
SORT_AREA, SORT_PERI, SORT_DIFF, SORT_SSIDE,
|
|
49
|
-
SORT_LSIDE, SORT_RATIO, SORT_NONE
|
|
50
|
-
}
|
|
51
59
|
|
|
52
60
|
// packer.js - classes and functions
|
|
53
61
|
export {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
float2dec,
|
|
63
|
+
SORT_AREA,
|
|
64
|
+
SORT_PERI,
|
|
65
|
+
SORT_DIFF,
|
|
66
|
+
SORT_SSIDE,
|
|
67
|
+
SORT_LSIDE,
|
|
68
|
+
SORT_RATIO,
|
|
69
|
+
SORT_NONE,
|
|
70
|
+
BinFactory,
|
|
71
|
+
PackerBNFMixin,
|
|
72
|
+
PackerBFFMixin,
|
|
73
|
+
PackerBBFMixin,
|
|
74
|
+
PackerOnline,
|
|
75
|
+
PackingMode,
|
|
76
|
+
PackingBin,
|
|
77
|
+
newPacker
|
|
57
78
|
}
|
|
58
79
|
|
|
59
80
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rectpackbin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "A helpful description of your package",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"module": "commonjs",
|
|
6
7
|
"scripts": {
|
|
8
|
+
"test:single": "jest -t default_options test/packer/packer.test.js",
|
|
7
9
|
"test": "jest"
|
|
8
10
|
},
|
|
9
11
|
"repository": {
|
|
@@ -13,7 +15,9 @@
|
|
|
13
15
|
"author": "Diljot Singh",
|
|
14
16
|
"license": "MIT",
|
|
15
17
|
"dependencies": {
|
|
16
|
-
|
|
18
|
+
"canvas": "^3.1.0",
|
|
19
|
+
"guillotine-packer": "^1.0.2",
|
|
20
|
+
"sharp": "^0.34.1"
|
|
17
21
|
},
|
|
18
22
|
"jest": {
|
|
19
23
|
"transform": {
|
package/src/rectpack/geometry.js
CHANGED
|
@@ -1,346 +1,3 @@
|
|
|
1
|
-
// from math import sqrt
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// class Point(object):
|
|
6
|
-
|
|
7
|
-
// __slots__ = ('x', 'y')
|
|
8
|
-
|
|
9
|
-
// def __init__(self, x, y):
|
|
10
|
-
// self.x = x
|
|
11
|
-
// self.y = y
|
|
12
|
-
|
|
13
|
-
// def __eq__(self, other):
|
|
14
|
-
// return (self.x == other.x and self.y == other.y)
|
|
15
|
-
|
|
16
|
-
// def __repr__(self):
|
|
17
|
-
// return "P({}, {})".format(self.x, self.y)
|
|
18
|
-
|
|
19
|
-
// def distance(self, point):
|
|
20
|
-
// """
|
|
21
|
-
// Calculate distance to another point
|
|
22
|
-
// """
|
|
23
|
-
// return sqrt((self.x-point.x)**2+(self.y-point.y)**2)
|
|
24
|
-
|
|
25
|
-
// def distance_squared(self, point):
|
|
26
|
-
// return (self.x-point.x)**2+(self.y-point.y)**2
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// class Segment(object):
|
|
30
|
-
|
|
31
|
-
// __slots__ = ('start', 'end')
|
|
32
|
-
|
|
33
|
-
// def __init__(self, start, end):
|
|
34
|
-
// """
|
|
35
|
-
// Arguments:
|
|
36
|
-
// start (Point): Segment start point
|
|
37
|
-
// end (Point): Segment end point
|
|
38
|
-
// """
|
|
39
|
-
// assert(isinstance(start, Point) and isinstance(end, Point))
|
|
40
|
-
// self.start = start
|
|
41
|
-
// self.end = end
|
|
42
|
-
|
|
43
|
-
// def __eq__(self, other):
|
|
44
|
-
// if not isinstance(other, self.__class__):
|
|
45
|
-
// None
|
|
46
|
-
// return self.start==other.start and self.end==other.end
|
|
47
|
-
|
|
48
|
-
// def __repr__(self):
|
|
49
|
-
// return "S({}, {})".format(self.start, self.end)
|
|
50
|
-
|
|
51
|
-
// @property
|
|
52
|
-
// def length_squared(self):
|
|
53
|
-
// """Faster than length and useful for some comparisons"""
|
|
54
|
-
// return self.start.distance_squared(self.end)
|
|
55
|
-
|
|
56
|
-
// @property
|
|
57
|
-
// def length(self):
|
|
58
|
-
// return self.start.distance(self.end)
|
|
59
|
-
|
|
60
|
-
// @property
|
|
61
|
-
// def top(self):
|
|
62
|
-
// return max(self.start.y, self.end.y)
|
|
63
|
-
|
|
64
|
-
// @property
|
|
65
|
-
// def bottom(self):
|
|
66
|
-
// return min(self.start.y, self.end.y)
|
|
67
|
-
|
|
68
|
-
// @property
|
|
69
|
-
// def right(self):
|
|
70
|
-
// return max(self.start.x, self.end.x)
|
|
71
|
-
|
|
72
|
-
// @property
|
|
73
|
-
// def left(self):
|
|
74
|
-
// return min(self.start.x, self.end.x)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
// class HSegment(Segment):
|
|
78
|
-
// """Horizontal Segment"""
|
|
79
|
-
|
|
80
|
-
// def __init__(self, start, length):
|
|
81
|
-
// """
|
|
82
|
-
// Create an Horizontal segment given its left most end point and its
|
|
83
|
-
// length.
|
|
84
|
-
|
|
85
|
-
// Arguments:
|
|
86
|
-
// - start (Point): Starting Point
|
|
87
|
-
// - length (number): segment length
|
|
88
|
-
// """
|
|
89
|
-
// assert(isinstance(start, Point) and not isinstance(length, Point))
|
|
90
|
-
// super(HSegment, self).__init__(start, Point(start.x+length, start.y))
|
|
91
|
-
|
|
92
|
-
// @property
|
|
93
|
-
// def length(self):
|
|
94
|
-
// return self.end.x-self.start.x
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// class VSegment(Segment):
|
|
98
|
-
// """Vertical Segment"""
|
|
99
|
-
|
|
100
|
-
// def __init__(self, start, length):
|
|
101
|
-
// """
|
|
102
|
-
// Create a Vertical segment given its bottom most end point and its
|
|
103
|
-
// length.
|
|
104
|
-
|
|
105
|
-
// Arguments:
|
|
106
|
-
// - start (Point): Starting Point
|
|
107
|
-
// - length (number): segment length
|
|
108
|
-
// """
|
|
109
|
-
// assert(isinstance(start, Point) and not isinstance(length, Point))
|
|
110
|
-
// super(VSegment, self).__init__(start, Point(start.x, start.y+length))
|
|
111
|
-
|
|
112
|
-
// @property
|
|
113
|
-
// def length(self):
|
|
114
|
-
// return self.end.y-self.start.y
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
// class Rectangle(object):
|
|
119
|
-
// """Basic rectangle primitive class.
|
|
120
|
-
// x, y-> Lower right corner coordinates
|
|
121
|
-
// width -
|
|
122
|
-
// height -
|
|
123
|
-
// """
|
|
124
|
-
// __slots__ = ('width', 'height', 'x', 'y', 'rid')
|
|
125
|
-
|
|
126
|
-
// def __init__(self, x, y, width, height, rid = None):
|
|
127
|
-
// """
|
|
128
|
-
// Args:
|
|
129
|
-
// x (int, float):
|
|
130
|
-
// y (int, float):
|
|
131
|
-
// width (int, float):
|
|
132
|
-
// height (int, float):
|
|
133
|
-
// rid (int):
|
|
134
|
-
// """
|
|
135
|
-
// assert(height >=0 and width >=0)
|
|
136
|
-
|
|
137
|
-
// self.width = width
|
|
138
|
-
// self.height = height
|
|
139
|
-
// self.x = x
|
|
140
|
-
// self.y = y
|
|
141
|
-
// self.rid = rid
|
|
142
|
-
|
|
143
|
-
// @property
|
|
144
|
-
// def bottom(self):
|
|
145
|
-
// """
|
|
146
|
-
// Rectangle bottom edge y coordinate
|
|
147
|
-
// """
|
|
148
|
-
// return self.y
|
|
149
|
-
|
|
150
|
-
// @property
|
|
151
|
-
// def top(self):
|
|
152
|
-
// """
|
|
153
|
-
// Rectangle top edge y coordiante
|
|
154
|
-
// """
|
|
155
|
-
// return self.y+self.height
|
|
156
|
-
|
|
157
|
-
// @property
|
|
158
|
-
// def left(self):
|
|
159
|
-
// """
|
|
160
|
-
// Rectangle left ednge x coordinate
|
|
161
|
-
// """
|
|
162
|
-
// return self.x
|
|
163
|
-
|
|
164
|
-
// @property
|
|
165
|
-
// def right(self):
|
|
166
|
-
// """
|
|
167
|
-
// Rectangle right edge x coordinate
|
|
168
|
-
// """
|
|
169
|
-
// return self.x+self.width
|
|
170
|
-
|
|
171
|
-
// @property
|
|
172
|
-
// def corner_top_l(self):
|
|
173
|
-
// return Point(self.left, self.top)
|
|
174
|
-
|
|
175
|
-
// @property
|
|
176
|
-
// def corner_top_r(self):
|
|
177
|
-
// return Point(self.right, self.top)
|
|
178
|
-
|
|
179
|
-
// @property
|
|
180
|
-
// def corner_bot_r(self):
|
|
181
|
-
// return Point(self.right, self.bottom)
|
|
182
|
-
|
|
183
|
-
// @property
|
|
184
|
-
// def corner_bot_l(self):
|
|
185
|
-
// return Point(self.left, self.bottom)
|
|
186
|
-
|
|
187
|
-
// def __lt__(self, other):
|
|
188
|
-
// """
|
|
189
|
-
// Compare rectangles by area (used for sorting)
|
|
190
|
-
// """
|
|
191
|
-
// return self.area() < other.area()
|
|
192
|
-
|
|
193
|
-
// def __eq__(self, other):
|
|
194
|
-
// """
|
|
195
|
-
// Equal rectangles have same area.
|
|
196
|
-
// """
|
|
197
|
-
// if not isinstance(other, self.__class__):
|
|
198
|
-
// return False
|
|
199
|
-
|
|
200
|
-
// return (self.width == other.width and \
|
|
201
|
-
// self.height == other.height and \
|
|
202
|
-
// self.x == other.x and \
|
|
203
|
-
// self.y == other.y)
|
|
204
|
-
|
|
205
|
-
// def __hash__(self):
|
|
206
|
-
// return hash((self.x, self.y, self.width, self.height))
|
|
207
|
-
|
|
208
|
-
// def __iter__(self):
|
|
209
|
-
// """
|
|
210
|
-
// Iterate through rectangle corners
|
|
211
|
-
// """
|
|
212
|
-
// yield self.corner_top_l
|
|
213
|
-
// yield self.corner_top_r
|
|
214
|
-
// yield self.corner_bot_r
|
|
215
|
-
// yield self.corner_bot_l
|
|
216
|
-
|
|
217
|
-
// def __repr__(self):
|
|
218
|
-
// return "R({}, {}, {}, {})".format(self.x, self.y, self.width, self.height)
|
|
219
|
-
|
|
220
|
-
// def area(self):
|
|
221
|
-
// """
|
|
222
|
-
// Rectangle area
|
|
223
|
-
// """
|
|
224
|
-
// return self.width * self.height
|
|
225
|
-
|
|
226
|
-
// def move(self, x, y):
|
|
227
|
-
// """
|
|
228
|
-
// Move Rectangle to x,y coordinates
|
|
229
|
-
|
|
230
|
-
// Arguments:
|
|
231
|
-
// x (int, float): X coordinate
|
|
232
|
-
// y (int, float): Y coordinate
|
|
233
|
-
// """
|
|
234
|
-
// self.x = x
|
|
235
|
-
// self.y = y
|
|
236
|
-
|
|
237
|
-
// def contains(self, rect):
|
|
238
|
-
// """
|
|
239
|
-
// Tests if another rectangle is contained by this one
|
|
240
|
-
|
|
241
|
-
// Arguments:
|
|
242
|
-
// rect (Rectangle): The other rectangle
|
|
243
|
-
|
|
244
|
-
// Returns:
|
|
245
|
-
// bool: True if it is container, False otherwise
|
|
246
|
-
// """
|
|
247
|
-
// return (rect.y >= self.y and \
|
|
248
|
-
// rect.x >= self.x and \
|
|
249
|
-
// rect.y+rect.height <= self.y+self.height and \
|
|
250
|
-
// rect.x+rect.width <= self.x+self.width)
|
|
251
|
-
|
|
252
|
-
// def intersects(self, rect, edges=False):
|
|
253
|
-
// """
|
|
254
|
-
// Detect intersections between this and another Rectangle.
|
|
255
|
-
|
|
256
|
-
// Parameters:
|
|
257
|
-
// rect (Rectangle): The other rectangle.
|
|
258
|
-
// edges (bool): True to consider rectangles touching by their
|
|
259
|
-
// edges or corners to be intersecting.
|
|
260
|
-
// (Should have been named include_touching)
|
|
261
|
-
|
|
262
|
-
// Returns:
|
|
263
|
-
// bool: True if the rectangles intersect, False otherwise
|
|
264
|
-
// """
|
|
265
|
-
// if edges:
|
|
266
|
-
// if (self.bottom > rect.top or self.top < rect.bottom or\
|
|
267
|
-
// self.left > rect.right or self.right < rect.left):
|
|
268
|
-
// return False
|
|
269
|
-
// else:
|
|
270
|
-
// if (self.bottom >= rect.top or self.top <= rect.bottom or
|
|
271
|
-
// self.left >= rect.right or self.right <= rect.left):
|
|
272
|
-
// return False
|
|
273
|
-
|
|
274
|
-
// return True
|
|
275
|
-
|
|
276
|
-
// def intersection(self, rect, edges=False):
|
|
277
|
-
// """
|
|
278
|
-
// Returns the rectangle resulting of the intersection between this and another
|
|
279
|
-
// rectangle. If the rectangles are only touching by their edges, and the
|
|
280
|
-
// argument 'edges' is True the rectangle returned will have an area of 0.
|
|
281
|
-
// Returns None if there is no intersection.
|
|
282
|
-
|
|
283
|
-
// Arguments:
|
|
284
|
-
// rect (Rectangle): The other rectangle.
|
|
285
|
-
// edges (bool): If True Rectangles touching by their edges are
|
|
286
|
-
// considered to be intersection. In this case a rectangle of
|
|
287
|
-
// 0 height or/and width will be returned.
|
|
288
|
-
|
|
289
|
-
// Returns:
|
|
290
|
-
// Rectangle: Intersection.
|
|
291
|
-
// None: There was no intersection.
|
|
292
|
-
// """
|
|
293
|
-
// if not self.intersects(rect, edges=edges):
|
|
294
|
-
// return None
|
|
295
|
-
|
|
296
|
-
// bottom = max(self.bottom, rect.bottom)
|
|
297
|
-
// left = max(self.left, rect.left)
|
|
298
|
-
// top = min(self.top, rect.top)
|
|
299
|
-
// right = min(self.right, rect.right)
|
|
300
|
-
|
|
301
|
-
// return Rectangle(left, bottom, right-left, top-bottom)
|
|
302
|
-
|
|
303
|
-
// def join(self, other):
|
|
304
|
-
// """
|
|
305
|
-
// Try to join a rectangle to this one, if the result is also a rectangle
|
|
306
|
-
// and the operation is successful and this rectangle is modified to the union.
|
|
307
|
-
|
|
308
|
-
// Arguments:
|
|
309
|
-
// other (Rectangle): Rectangle to join
|
|
310
|
-
|
|
311
|
-
// Returns:
|
|
312
|
-
// bool: True when successfully joined, False otherwise
|
|
313
|
-
// """
|
|
314
|
-
// if self.contains(other):
|
|
315
|
-
// return True
|
|
316
|
-
|
|
317
|
-
// if other.contains(self):
|
|
318
|
-
// self.x = other.x
|
|
319
|
-
// self.y = other.y
|
|
320
|
-
// self.width = other.width
|
|
321
|
-
// self.height = other.height
|
|
322
|
-
// return True
|
|
323
|
-
|
|
324
|
-
// if not self.intersects(other, edges=True):
|
|
325
|
-
// return False
|
|
326
|
-
|
|
327
|
-
// # Other rectangle is Up/Down from this
|
|
328
|
-
// if self.left == other.left and self.width == other.width:
|
|
329
|
-
// y_min = min(self.bottom, other.bottom)
|
|
330
|
-
// y_max = max(self.top, other.top)
|
|
331
|
-
// self.y = y_min
|
|
332
|
-
// self.height = y_max-y_min
|
|
333
|
-
// return True
|
|
334
|
-
|
|
335
|
-
// # Other rectangle is Right/Left from this
|
|
336
|
-
// if self.bottom == other.bottom and self.height == other.height:
|
|
337
|
-
// x_min = min(self.left, other.left)
|
|
338
|
-
// x_max = max(self.right, other.right)
|
|
339
|
-
// self.x = x_min
|
|
340
|
-
// self.width = x_max-x_min
|
|
341
|
-
// return True
|
|
342
|
-
|
|
343
|
-
// return False
|
|
344
1
|
|
|
345
2
|
class Point {
|
|
346
3
|
constructor(x, y) {
|