Skip to content

Commit 8c2efa2

Browse files
committed
Update layer z value
1 parent 2ff4a73 commit 8c2efa2

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

src/__tests__/job.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,61 @@ describe('.layers', () => {
300300
expect(layers.length).toEqual(1);
301301
expect(layers[0].paths.length).toEqual(4);
302302
});
303+
304+
test('layer z must equal path z', () => {
305+
const job = new Job();
306+
307+
append_path(job, PathType.Extrusion, [
308+
[5, 6, 2],
309+
[5, 6, 2]
310+
]);
311+
312+
const layers = job.layers;
313+
314+
expect(layers).not.toBeNull();
315+
expect(layers.length).toEqual(1);
316+
expect(layers[0].z).toEqual(2);
317+
});
318+
319+
test('layer z must equal extrusion path z', () => {
320+
const job = new Job();
321+
322+
append_path(job, PathType.Extrusion, [
323+
[5, 6, 2],
324+
[5, 6, 2]
325+
]);
326+
327+
append_path(job, PathType.Travel, [
328+
[5, 6, 4],
329+
[5, 6, 4]
330+
]);
331+
332+
const layers = job.layers;
333+
334+
expect(layers).not.toBeNull();
335+
expect(layers.length).toEqual(1);
336+
expect(layers[0].z).toEqual(2);
337+
});
338+
339+
340+
test('layer z must equal path z, for second layer', () => {
341+
const job = new Job();
342+
343+
append_path(job, PathType.Extrusion, [
344+
[5, 6, 2],
345+
[5, 6, 2]
346+
]);
347+
append_path(job, PathType.Extrusion, [
348+
[5, 6, 4],
349+
[5, 6, 4]
350+
]);
351+
352+
const layers = job.layers;
353+
354+
expect(layers).not.toBeNull();
355+
expect(layers.length).toEqual(2);
356+
expect(layers[1].z).toEqual(4);
357+
});
303358
});
304359

305360
describe('.extrusions', () => {

src/indexers.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,13 @@ export class LayersIndexer extends Indexer {
117117
this.createLayer(path.vertices[2]);
118118
}
119119
}
120-
this.lastLayer().paths.push(path);
120+
121+
const layer = this.lastLayer();
122+
if (path.travelType === PathType.Extrusion) {
123+
layer.z = path.vertices[2]; // ensure the layer's Z position is updated when extruding
124+
}
125+
126+
layer.paths.push(path);
121127
}
122128

123129
/**

0 commit comments

Comments
 (0)