@jetta/blocks-allocator 0.2.1-3 → 0.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetta/blocks-allocator",
3
- "version": "0.2.1-3",
3
+ "version": "0.2.1",
4
4
  "description": "Blocks wall allocation library",
5
5
  "main": "src/index.js",
6
6
  "exports": {
@@ -41,7 +41,7 @@
41
41
  "license": "ISC",
42
42
  "dependencies": {
43
43
  "@jetta/axle-load-calculator": "^0.4.1",
44
- "@jetta/empty-spaces-manager": "^0.1.1-0",
44
+ "@jetta/empty-spaces-manager": "^0.1.2-1",
45
45
  "@jetta/item-amount-controller": "0.1.0-0",
46
46
  "@jetta/logger": "^2.0.1",
47
47
  "@jetta/lp-framework": "2.1.0-6",
@@ -1,19 +1,108 @@
1
1
  /**
2
- * Maps allocated container items to empty-space chooser snapshots.
3
- * @param {object} container - Container with get_allocated_items().
4
- * @returns {Array<{ x: number, y: number, z: number, width: number, height: number, length: number }>}
2
+ * @param {object} item - Allocated item.
3
+ * @param {string} reader_name - Accessor name.
4
+ * @returns {string|undefined} Non-empty text when the accessor returns one.
5
5
  */
6
- function build_allocated_item_snapshots(container)
6
+ function optional_identity(item, reader_name)
7
7
  {
8
- const allocated_items = container.get_allocated_items?.() ?? []
9
- return allocated_items.map(item => ({
8
+ const reader = item[reader_name]
9
+ if (typeof reader !== 'function')
10
+ {
11
+ return undefined
12
+ }
13
+ const value = reader.call(item)
14
+ if (typeof value !== 'string' || value.length === 0)
15
+ {
16
+ return undefined
17
+ }
18
+ return value
19
+ }
20
+
21
+ /**
22
+ * @param {object} snapshot - Geometry snapshot.
23
+ * @param {object} item - Allocated item.
24
+ * @returns {object} Snapshot with identity fields when the item exposes them.
25
+ */
26
+ function assign_identity(snapshot, item)
27
+ {
28
+ const item_id = optional_identity(item, 'get_id')
29
+ const tie_ratio_orientation = optional_identity(item, 'get_tie_ratio_orientation')
30
+ if (item_id !== undefined)
31
+ {
32
+ snapshot.item_id = item_id
33
+ }
34
+ if (tie_ratio_orientation !== undefined)
35
+ {
36
+ snapshot.tie_ratio_orientation = tie_ratio_orientation
37
+ }
38
+ return assign_stacking(snapshot, item)
39
+ }
40
+
41
+ /**
42
+ * @param {object} item - Allocated item.
43
+ * @returns {object|undefined} Stacking info from the item or its source.
44
+ */
45
+ function read_stacking_info(item)
46
+ {
47
+ const source = typeof item.get_stacking_source_item === 'function'
48
+ ? item.get_stacking_source_item()
49
+ : item
50
+ if (typeof source.get_stacking_info !== 'function')
51
+ {
52
+ return undefined
53
+ }
54
+ return source.get_stacking_info()
55
+ }
56
+
57
+ /**
58
+ * @param {object} snapshot - Geometry snapshot.
59
+ * @param {object} item - Allocated item.
60
+ * @returns {object} Snapshot with stacking fields when present.
61
+ */
62
+ function assign_stacking(snapshot, item)
63
+ {
64
+ const info = read_stacking_info(item)
65
+ if (!info)
66
+ {
67
+ return snapshot
68
+ }
69
+ if (typeof info.stacking_family === 'string' && info.stacking_family.length > 0)
70
+ {
71
+ snapshot.stacking_family = info.stacking_family
72
+ }
73
+ if (Array.isArray(info.supported_families) && info.supported_families.length > 0)
74
+ {
75
+ snapshot.supported_families = info.supported_families
76
+ }
77
+ return snapshot
78
+ }
79
+
80
+ /**
81
+ * @param {object} item - Allocated item.
82
+ * @returns {object} Chooser snapshot.
83
+ */
84
+ function snapshot_from_item(item)
85
+ {
86
+ const snapshot = {
10
87
  x: item.get_x(),
11
88
  y: item.get_y(),
12
89
  z: item.get_z(),
13
90
  width: item.get_width(),
14
91
  height: item.get_height(),
15
92
  length: item.get_length()
16
- }))
93
+ }
94
+ return assign_identity(snapshot, item)
95
+ }
96
+
97
+ /**
98
+ * Maps allocated container items to empty-space chooser snapshots.
99
+ * @param {object} container - Container with get_allocated_items().
100
+ * @returns {Array<object>} Geometry plus optional identity and stacking fields.
101
+ */
102
+ function build_allocated_item_snapshots(container)
103
+ {
104
+ const allocated_items = container.get_allocated_items?.() ?? []
105
+ return allocated_items.map(snapshot_from_item)
17
106
  }
18
107
 
19
108
  module.exports = build_allocated_item_snapshots