landxml 0.2.0 → 0.4.0
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/CHANGELOG.md +12 -0
- package/dist/index.js +41 -38
- package/dist/index.mjs +41 -38
- package/package.json +6 -1
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -228,52 +228,55 @@ var contourLineOnFace = (face, z) => {
|
|
|
228
228
|
return line.length > 0 ? line : void 0;
|
|
229
229
|
};
|
|
230
230
|
var linesToPolyLines = (lineSegments) => {
|
|
231
|
+
var _a, _b;
|
|
231
232
|
if (!Array.isArray(lineSegments) || lineSegments.length === 0) {
|
|
232
233
|
throw new Error("Invalid input: Please provide a non-empty array of line segments.");
|
|
233
234
|
}
|
|
234
|
-
const
|
|
235
|
+
const segmentsMapIndexes = {};
|
|
235
236
|
const polylines = [];
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
segmentsMap.get(startKey).push(end);
|
|
242
|
-
segmentsMap.get(endKey).push(start);
|
|
237
|
+
const parsedSegmentIndexes = [];
|
|
238
|
+
const lineSegmentStrings = lineSegments.map((v) => v.map((c) => c.join(",")));
|
|
239
|
+
lineSegmentStrings.forEach(([start, end], i) => {
|
|
240
|
+
segmentsMapIndexes[start] = segmentsMapIndexes[start] ? [...segmentsMapIndexes[start] || [], i] : [i];
|
|
241
|
+
segmentsMapIndexes[end] = segmentsMapIndexes[end] ? [...segmentsMapIndexes[end] || [], i] : [i];
|
|
243
242
|
});
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
243
|
+
for (let i = 0; i < lineSegmentStrings.length; i++) {
|
|
244
|
+
if (parsedSegmentIndexes.includes(i))
|
|
245
|
+
continue;
|
|
246
|
+
parsedSegmentIndexes.push(i);
|
|
247
|
+
let [start, end] = lineSegmentStrings[i];
|
|
248
|
+
let polyline = [start, end];
|
|
249
|
+
while (start && segmentsMapIndexes[start]) {
|
|
250
|
+
const nextLineIndex = (_a = segmentsMapIndexes[start]) == null ? void 0 : _a.find(
|
|
251
|
+
(lineIndex) => !parsedSegmentIndexes.includes(lineIndex)
|
|
252
|
+
);
|
|
253
|
+
if (nextLineIndex) {
|
|
254
|
+
parsedSegmentIndexes.push(nextLineIndex);
|
|
255
|
+
const nextLineSegment = lineSegmentStrings[nextLineIndex];
|
|
256
|
+
const nextLineSegmentPointIndex = nextLineSegment[0] === start ? 1 : 0;
|
|
257
|
+
const newPoint = nextLineSegment[nextLineSegmentPointIndex];
|
|
258
|
+
polyline.unshift(newPoint);
|
|
259
|
+
start = newPoint;
|
|
260
|
+
} else {
|
|
261
|
+
start = null;
|
|
259
262
|
}
|
|
260
263
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
264
|
+
while (end && segmentsMapIndexes[end]) {
|
|
265
|
+
const nextLineIndex = (_b = segmentsMapIndexes[end]) == null ? void 0 : _b.find(
|
|
266
|
+
(lineIndex) => !parsedSegmentIndexes.includes(lineIndex)
|
|
267
|
+
);
|
|
268
|
+
if (nextLineIndex) {
|
|
269
|
+
parsedSegmentIndexes.push(nextLineIndex);
|
|
270
|
+
const nextLineSegment = lineSegmentStrings[nextLineIndex];
|
|
271
|
+
const nextLineSegmentPointIndex = nextLineSegment[0] === end ? 1 : 0;
|
|
272
|
+
const newPoint = nextLineSegment[nextLineSegmentPointIndex];
|
|
273
|
+
polyline.push(newPoint);
|
|
274
|
+
end = newPoint;
|
|
275
|
+
} else {
|
|
276
|
+
end = null;
|
|
277
|
+
}
|
|
275
278
|
}
|
|
276
|
-
|
|
279
|
+
polylines.push(polyline.map((coord) => coord.split(",").map((v) => parseFloat(v))));
|
|
277
280
|
}
|
|
278
281
|
return polylines;
|
|
279
282
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -193,52 +193,55 @@ var contourLineOnFace = (face, z) => {
|
|
|
193
193
|
return line.length > 0 ? line : void 0;
|
|
194
194
|
};
|
|
195
195
|
var linesToPolyLines = (lineSegments) => {
|
|
196
|
+
var _a, _b;
|
|
196
197
|
if (!Array.isArray(lineSegments) || lineSegments.length === 0) {
|
|
197
198
|
throw new Error("Invalid input: Please provide a non-empty array of line segments.");
|
|
198
199
|
}
|
|
199
|
-
const
|
|
200
|
+
const segmentsMapIndexes = {};
|
|
200
201
|
const polylines = [];
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
segmentsMap.get(startKey).push(end);
|
|
207
|
-
segmentsMap.get(endKey).push(start);
|
|
202
|
+
const parsedSegmentIndexes = [];
|
|
203
|
+
const lineSegmentStrings = lineSegments.map((v) => v.map((c) => c.join(",")));
|
|
204
|
+
lineSegmentStrings.forEach(([start, end], i) => {
|
|
205
|
+
segmentsMapIndexes[start] = segmentsMapIndexes[start] ? [...segmentsMapIndexes[start] || [], i] : [i];
|
|
206
|
+
segmentsMapIndexes[end] = segmentsMapIndexes[end] ? [...segmentsMapIndexes[end] || [], i] : [i];
|
|
208
207
|
});
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
208
|
+
for (let i = 0; i < lineSegmentStrings.length; i++) {
|
|
209
|
+
if (parsedSegmentIndexes.includes(i))
|
|
210
|
+
continue;
|
|
211
|
+
parsedSegmentIndexes.push(i);
|
|
212
|
+
let [start, end] = lineSegmentStrings[i];
|
|
213
|
+
let polyline = [start, end];
|
|
214
|
+
while (start && segmentsMapIndexes[start]) {
|
|
215
|
+
const nextLineIndex = (_a = segmentsMapIndexes[start]) == null ? void 0 : _a.find(
|
|
216
|
+
(lineIndex) => !parsedSegmentIndexes.includes(lineIndex)
|
|
217
|
+
);
|
|
218
|
+
if (nextLineIndex) {
|
|
219
|
+
parsedSegmentIndexes.push(nextLineIndex);
|
|
220
|
+
const nextLineSegment = lineSegmentStrings[nextLineIndex];
|
|
221
|
+
const nextLineSegmentPointIndex = nextLineSegment[0] === start ? 1 : 0;
|
|
222
|
+
const newPoint = nextLineSegment[nextLineSegmentPointIndex];
|
|
223
|
+
polyline.unshift(newPoint);
|
|
224
|
+
start = newPoint;
|
|
225
|
+
} else {
|
|
226
|
+
start = null;
|
|
224
227
|
}
|
|
225
228
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
229
|
+
while (end && segmentsMapIndexes[end]) {
|
|
230
|
+
const nextLineIndex = (_b = segmentsMapIndexes[end]) == null ? void 0 : _b.find(
|
|
231
|
+
(lineIndex) => !parsedSegmentIndexes.includes(lineIndex)
|
|
232
|
+
);
|
|
233
|
+
if (nextLineIndex) {
|
|
234
|
+
parsedSegmentIndexes.push(nextLineIndex);
|
|
235
|
+
const nextLineSegment = lineSegmentStrings[nextLineIndex];
|
|
236
|
+
const nextLineSegmentPointIndex = nextLineSegment[0] === end ? 1 : 0;
|
|
237
|
+
const newPoint = nextLineSegment[nextLineSegmentPointIndex];
|
|
238
|
+
polyline.push(newPoint);
|
|
239
|
+
end = newPoint;
|
|
240
|
+
} else {
|
|
241
|
+
end = null;
|
|
242
|
+
}
|
|
240
243
|
}
|
|
241
|
-
|
|
244
|
+
polylines.push(polyline.map((coord) => coord.split(",").map((v) => parseFloat(v))));
|
|
242
245
|
}
|
|
243
246
|
return polylines;
|
|
244
247
|
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "landxml",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Parse LandXML surfaces on the modern web.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"private": false,
|
|
9
|
+
"homepage": "https://github.com/abrman/landxml#readme",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/abrman/landxml"
|
|
13
|
+
},
|
|
9
14
|
"scripts": {
|
|
10
15
|
"dev": "vitest",
|
|
11
16
|
"test": "vitest run",
|