@jetta/cargo-stabilizer 0.1.0-12 → 0.1.0-14
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/build/core/adapters/coordinate_mapper.d.ts +1 -1
- package/build/core/adapters/coordinate_mapper.js +3 -3
- package/build/core/filters/is_item_on_cm_floor.d.ts +2 -2
- package/build/core/filters/is_item_on_cm_floor.js +3 -3
- package/build/core/geometry/has_penetrating_overlap.d.ts +2 -2
- package/build/core/geometry/has_penetrating_overlap.js +3 -3
- package/build/core/validation/contract/map_contract_to_wire_shape.js +3 -0
- package/build/core/validation/contract/map_wire_input_to_contract_shape.d.ts.map +1 -1
- package/build/core/validation/contract/map_wire_input_to_contract_shape.js +2 -1
- package/build/core/validation/contract/map_wire_item_to_contract.js +13 -5
- package/build/core/validation/contract/uniquify_contract_item_ids.d.ts +8 -0
- package/build/core/validation/contract/uniquify_contract_item_ids.d.ts.map +1 -0
- package/build/core/validation/contract/uniquify_contract_item_ids.js +38 -0
- package/package.json +1 -1
|
@@ -15,7 +15,7 @@ export interface StabilityContainerPayload {
|
|
|
15
15
|
item_list: StabilityItemPayload[];
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
* Maps contract
|
|
18
|
+
* Maps contract coordinates onto cargo-stability axes (y = height, z = length).
|
|
19
19
|
* @param item - Stabilizer item record.
|
|
20
20
|
* @returns Stability item payload entry.
|
|
21
21
|
*/
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { item_to_box } from '../geometry/box_geometry.js';
|
|
2
2
|
/**
|
|
3
|
-
* Maps contract
|
|
3
|
+
* Maps contract coordinates onto cargo-stability axes (y = height, z = length).
|
|
4
4
|
* @param item - Stabilizer item record.
|
|
5
5
|
* @returns Stability item payload entry.
|
|
6
6
|
*/
|
|
7
7
|
export function map_item_to_stability(item) {
|
|
8
8
|
return {
|
|
9
9
|
x: item.x,
|
|
10
|
-
y: item.
|
|
11
|
-
z: item.
|
|
10
|
+
y: item.y,
|
|
11
|
+
z: item.z,
|
|
12
12
|
w: item.width,
|
|
13
13
|
h: item.height,
|
|
14
14
|
l: item.depth
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { StabilizerItem } from '../validation/contract/stabilizer_domain_schema.js';
|
|
2
2
|
/**
|
|
3
|
-
* True when the item rests on the
|
|
4
|
-
* @param item - Stabilizer item in
|
|
3
|
+
* True when the item rests on the floor (contract y is height after wire map).
|
|
4
|
+
* @param item - Stabilizer item in contract coordinates.
|
|
5
5
|
* @returns True when height origin is on the floor.
|
|
6
6
|
*/
|
|
7
7
|
export declare function is_item_on_cm_floor(item: StabilizerItem): boolean;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const CM_FLOOR_HEIGHT_EPSILON = 1e-6;
|
|
2
2
|
/**
|
|
3
|
-
* True when the item rests on the
|
|
4
|
-
* @param item - Stabilizer item in
|
|
3
|
+
* True when the item rests on the floor (contract y is height after wire map).
|
|
4
|
+
* @param item - Stabilizer item in contract coordinates.
|
|
5
5
|
* @returns True when height origin is on the floor.
|
|
6
6
|
*/
|
|
7
7
|
export function is_item_on_cm_floor(item) {
|
|
8
|
-
return item.
|
|
8
|
+
return item.y <= CM_FLOOR_HEIGHT_EPSILON;
|
|
9
9
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { StabilizerContainer } from '../validation/contract/stabilizer_domain_schema.js';
|
|
2
2
|
/**
|
|
3
|
-
* True when any two items penetrate in the
|
|
4
|
-
* (x + width, y +
|
|
3
|
+
* True when any two items penetrate in the contract frame
|
|
4
|
+
* (x + width, y + height, z + depth) by more than a face-touch epsilon.
|
|
5
5
|
* @param containers - Layout to inspect.
|
|
6
6
|
* @returns True when a pair occupies the same volume beyond float error.
|
|
7
7
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const PENETRATION_EPSILON = 1e-6;
|
|
2
2
|
/**
|
|
3
|
-
* True when any two items penetrate in the
|
|
4
|
-
* (x + width, y +
|
|
3
|
+
* True when any two items penetrate in the contract frame
|
|
4
|
+
* (x + width, y + height, z + depth) by more than a face-touch epsilon.
|
|
5
5
|
* @param containers - Layout to inspect.
|
|
6
6
|
* @returns True when a pair occupies the same volume beyond float error.
|
|
7
7
|
*/
|
|
@@ -20,7 +20,7 @@ function container_has_penetrating_overlap(container) {
|
|
|
20
20
|
return false;
|
|
21
21
|
}
|
|
22
22
|
function items_penetrate(left, right) {
|
|
23
|
-
return interval_penetration({ min: left.x, max: left.x + left.width }, { min: right.x, max: right.x + right.width }) && interval_penetration({ min: left.y, max: left.y + left.
|
|
23
|
+
return interval_penetration({ min: left.x, max: left.x + left.width }, { min: right.x, max: right.x + right.width }) && interval_penetration({ min: left.y, max: left.y + left.height }, { min: right.y, max: right.y + right.height }) && interval_penetration({ min: left.z, max: left.z + left.depth }, { min: right.z, max: right.z + right.depth });
|
|
24
24
|
}
|
|
25
25
|
function interval_penetration(left, right) {
|
|
26
26
|
return Math.min(left.max, right.max) - Math.max(left.min, right.min) > PENETRATION_EPSILON;
|
|
@@ -38,5 +38,8 @@ function map_item_to_wire(item) {
|
|
|
38
38
|
if (item.attributes === undefined) {
|
|
39
39
|
return rename_keys(omit_keys(item, ['attributes']), CONTRACT_TO_ITEM_WIRE);
|
|
40
40
|
}
|
|
41
|
+
if (typeof item.attributes.w === 'number') {
|
|
42
|
+
return { ...item.attributes, x: item.x, y: item.z, z: item.y };
|
|
43
|
+
}
|
|
41
44
|
return { ...item.attributes, x: item.x, y: item.y, z: item.z };
|
|
42
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map_wire_input_to_contract_shape.d.ts","sourceRoot":"","sources":["../../../../src/core/validation/contract/map_wire_input_to_contract_shape.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"map_wire_input_to_contract_shape.d.ts","sourceRoot":"","sources":["../../../../src/core/validation/contract/map_wire_input_to_contract_shape.ts"],"names":[],"mappings":"AAWA,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAiBnE"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CONTAINER_WIRE_TO_CONTRACT, ENV_WIRE_TO_CONTRACT } from './cargo_movement_wire_field_map.js';
|
|
2
2
|
import { map_wire_item_to_contract } from './map_wire_item_to_contract.js';
|
|
3
|
+
import { uniquify_contract_item_ids } from './uniquify_contract_item_ids.js';
|
|
3
4
|
import { is_record, omit_keys, pick_keys, rename_keys } from './wire_mapper_record_utils.js';
|
|
4
5
|
const CONTAINER_CONTRACT_KEYS = ['sequence', 'width', 'height', 'length'];
|
|
5
6
|
const ENV_CONTRACT_KEYS = ['axles'];
|
|
@@ -32,7 +33,7 @@ function map_container_to_contract(value) {
|
|
|
32
33
|
}
|
|
33
34
|
const mapped = rename_keys(value, CONTAINER_WIRE_TO_CONTRACT);
|
|
34
35
|
if (Array.isArray(value.items)) {
|
|
35
|
-
mapped.items = value.items.map(map_wire_item_to_contract);
|
|
36
|
+
mapped.items = uniquify_contract_item_ids(value.items.map(map_wire_item_to_contract));
|
|
36
37
|
}
|
|
37
38
|
return pick_container_contract_keys(mapped);
|
|
38
39
|
}
|
|
@@ -22,11 +22,7 @@ export function map_wire_item_to_contract(value) {
|
|
|
22
22
|
return contract;
|
|
23
23
|
}
|
|
24
24
|
function read_contract_item_fields(source) {
|
|
25
|
-
const contract =
|
|
26
|
-
x: source.x,
|
|
27
|
-
y: source.y,
|
|
28
|
-
z: source.z
|
|
29
|
-
};
|
|
25
|
+
const contract = read_contract_position(source);
|
|
30
26
|
for (const [contract_key, wire_keys] of Object.entries(ITEM_CONTRACT_WIRE_KEYS)) {
|
|
31
27
|
const value = read_first_present(source, wire_keys);
|
|
32
28
|
if (value !== undefined) {
|
|
@@ -35,6 +31,18 @@ function read_contract_item_fields(source) {
|
|
|
35
31
|
}
|
|
36
32
|
return contract;
|
|
37
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* BWA `to_json` stores length on `y` and height on `z`. Candidate geometry
|
|
36
|
+
* uses the opposite (y = height, z = length), so CM wire items are swapped.
|
|
37
|
+
* @param source - Wire or English item record.
|
|
38
|
+
* @returns Contract x/y/z.
|
|
39
|
+
*/
|
|
40
|
+
function read_contract_position(source) {
|
|
41
|
+
if (typeof source.w === 'number') {
|
|
42
|
+
return { x: source.x, y: source.z, z: source.y };
|
|
43
|
+
}
|
|
44
|
+
return { x: source.x, y: source.y, z: source.z };
|
|
45
|
+
}
|
|
38
46
|
/**
|
|
39
47
|
* Coerces blocks-wall numeric group ids to the string contract type.
|
|
40
48
|
* @param contract_key - English contract field name.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Makes contract item_id unique when the same SKU id repeats.
|
|
3
|
+
* Original `_id` stays in attributes for the wire round-trip.
|
|
4
|
+
* @param items - Mapped contract items.
|
|
5
|
+
* @returns Items with unique `item_id` values.
|
|
6
|
+
*/
|
|
7
|
+
export declare function uniquify_contract_item_ids(items: unknown[]): unknown[];
|
|
8
|
+
//# sourceMappingURL=uniquify_contract_item_ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniquify_contract_item_ids.d.ts","sourceRoot":"","sources":["../../../../src/core/validation/contract/uniquify_contract_item_ids.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAKtE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { is_record } from './wire_mapper_record_utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Makes contract item_id unique when the same SKU id repeats.
|
|
4
|
+
* Original `_id` stays in attributes for the wire round-trip.
|
|
5
|
+
* @param items - Mapped contract items.
|
|
6
|
+
* @returns Items with unique `item_id` values.
|
|
7
|
+
*/
|
|
8
|
+
export function uniquify_contract_item_ids(items) {
|
|
9
|
+
const counts = count_item_ids(items);
|
|
10
|
+
const seen = new Map();
|
|
11
|
+
return items.map(item => uniquify_one_item(item, counts, seen));
|
|
12
|
+
}
|
|
13
|
+
function count_item_ids(items) {
|
|
14
|
+
const counts = new Map();
|
|
15
|
+
for (const item of items) {
|
|
16
|
+
const item_id = read_item_id(item);
|
|
17
|
+
if (item_id === undefined) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
counts.set(item_id, (counts.get(item_id) ?? 0) + 1);
|
|
21
|
+
}
|
|
22
|
+
return counts;
|
|
23
|
+
}
|
|
24
|
+
function uniquify_one_item(item, counts, seen) {
|
|
25
|
+
const item_id = read_item_id(item);
|
|
26
|
+
if (item_id === undefined || (counts.get(item_id) ?? 0) <= 1 || !is_record(item)) {
|
|
27
|
+
return item;
|
|
28
|
+
}
|
|
29
|
+
const occurrence = seen.get(item_id) ?? 0;
|
|
30
|
+
seen.set(item_id, occurrence + 1);
|
|
31
|
+
return { ...item, item_id: `${item_id}#${occurrence}` };
|
|
32
|
+
}
|
|
33
|
+
function read_item_id(item) {
|
|
34
|
+
if (!is_record(item) || typeof item.item_id !== 'string') {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
return item.item_id;
|
|
38
|
+
}
|