Skip to content

Commit 5c96773

Browse files
committed
remove ItemArray type alias, update nestWrapper parameter to emscripten::val, and simplify array validation and processing.
1 parent a0885fb commit 5c96773

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

libnest2d_js/libnest2d_js.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ EMSCRIPTEN_DECLARE_VAL_TYPE(PointList);
3232
EMSCRIPTEN_DECLARE_VAL_TYPE(ItemList);
3333
EMSCRIPTEN_DECLARE_VAL_TYPE(DoubleList);
3434

35-
// Define a more specific type for Item arrays (JavaScript Array<Item>)
36-
// Represents: Item[] in JavaScript/TypeScript
37-
using ItemArray = emscripten::val; // This will be bound as Item[] in TypeScript
38-
3935
// Helper function to convert JavaScript arrays to std::vector<Point>
4036
std::vector<Point> jsArrayToPointVector(const emscripten::val& jsArray) {
4137
std::vector<Point> vertices;
@@ -76,11 +72,8 @@ std::vector<double> jsArrayToVectorDouble(const emscripten::val& jsArray) {
7672
}
7773

7874
// Wrapper function for nest() to handle JavaScript arrays
79-
size_t nestWrapper(ItemArray& jsItems, const Box& bin, long distance = 1, const NfpConfig& config = NfpConfig()) {
80-
81-
if (!jsItems.isArray()) {
82-
throw std::invalid_argument("First parameter must be an array of Items");
83-
}
75+
// Wrapper function for nest() to handle JavaScript arrays
76+
size_t nestWrapper(emscripten::val jsItems, const Box& bin, long distance = 1, const NfpConfig& config = NfpConfig()) {
8477
// Convert JavaScript array to std::vector<Item>
8578
std::vector<Item> items;
8679
auto length = jsItems["length"].as<unsigned>();
@@ -95,18 +88,17 @@ size_t nestWrapper(ItemArray& jsItems, const Box& bin, long distance = 1, const
9588
if (distance <= 0) {
9689
distance = 1;
9790
}
98-
9991
// Create nest config
10092
NestConfig<> nestConfig(config);
10193

10294
// Call the nest function
10395
size_t result = nest(items, bin, distance, nestConfig);
104-
96+
10597
// Copy results back to original JavaScript items
10698
for (size_t i = 0; i < items.size() && i < length; ++i) {
10799
jsItems.set(i, val(items[i]));
108100
}
109-
101+
110102
return result;
111103
}
112104

0 commit comments

Comments
 (0)