Skip to content

Commit e4442eb

Browse files
committed
fix the splitting logic
1 parent c820fc7 commit e4442eb

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

src/__tests__/job.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,16 @@ describe('.layers', () => {
9696
expect(layers[0].paths.length).toEqual(2);
9797
});
9898

99-
test('travel paths moving z above the default tolerance create a new layer', () => {
99+
test('extrusion paths moving z above the default tolerance create a new layer', () => {
100100
const job = new Job();
101101

102102
append_path(job, PathType.Extrusion, [
103103
[0, 0, 0],
104104
[1, 2, 0]
105105
]);
106-
append_path(job, PathType.Travel, [
107-
[5, 6, 0],
108-
[5, 6, LayersIndexer.DEFAULT_TOLERANCE + 0.01]
106+
append_path(job, PathType.Extrusion, [
107+
[5, 6, LayersIndexer.DEFAULT_TOLERANCE + 0.02],
108+
[5, 6, LayersIndexer.DEFAULT_TOLERANCE + 0.02]
109109
]);
110110

111111
const layers = job.layers;
@@ -181,9 +181,8 @@ describe('.layers', () => {
181181

182182
expect(layers).not.toBeNull();
183183
expect(layers).toBeInstanceOf(Array);
184-
expect(layers.length).toEqual(2);
185-
expect(layers[0].paths.length).toEqual(1);
186-
expect(layers[1].paths.length).toEqual(3);
184+
expect(layers.length).toEqual(1);
185+
expect(layers[0].paths.length).toEqual(4);
187186
});
188187

189188
test('extrusions after travels are on the same layer', () => {
@@ -215,8 +214,8 @@ describe('.layers', () => {
215214
expect(layers).not.toBeNull();
216215
expect(layers).toBeInstanceOf(Array);
217216
expect(layers.length).toEqual(2);
218-
expect(layers[0].paths.length).toEqual(1);
219-
expect(layers[1].paths.length).toEqual(4);
217+
expect(layers[0].paths.length).toEqual(4);
218+
expect(layers[1].paths.length).toEqual(1);
220219
});
221220
});
222221

src/job.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,31 +152,23 @@ export class LayersIndexer extends Indexer {
152152
}
153153

154154
sortIn(path: Path): void {
155-
if (path.travelType === PathType.Extrusion && path.vertices.some((_, i, arr) => i % 3 === 2 && arr[i] !== arr[2])) {
155+
if (
156+
path.travelType === PathType.Extrusion &&
157+
path.vertices.some((_, i, arr) => i % 3 === 2 && arr[i] - arr[2] >= this.tolerance)
158+
) {
156159
throw new NonPlanarPathError();
157160
}
161+
158162
if (this.indexes[this.indexes.length - 1] === undefined) {
159163
this.createLayer(path.vertices[2]);
160164
}
161165

162166
if (path.travelType === PathType.Extrusion) {
163-
this.lastLayer().paths.push(path);
164-
} else {
165-
const verticalTravels = path.vertices
166-
.map((_, i, arr) => {
167-
if (i % 3 === 2 && arr[i] - arr[2] > this.tolerance) {
168-
return arr[i] - arr[2];
169-
}
170-
})
171-
.filter((z) => z !== undefined);
172-
const hasVerticalTravel = verticalTravels.length > 0;
173-
const hasExtrusions = this.lastLayer().paths.find((p) => p.travelType === PathType.Extrusion);
174-
175-
if (hasVerticalTravel && hasExtrusions) {
167+
if (path.vertices[2] - (this.lastLayer().z || 0) > this.tolerance) {
176168
this.createLayer(path.vertices[2]);
177169
}
178-
this.lastLayer().paths.push(path);
179170
}
171+
this.lastLayer().paths.push(path);
180172
}
181173

182174
private lastLayer(): Layer {

0 commit comments

Comments
 (0)