Skip to content

Commit c820fc7

Browse files
committed
Layer number, height and z
1 parent a712504 commit c820fc7

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/job.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ export class Layer {
2020
public paths: Path[];
2121
public lineNumber: number;
2222
public height: number = 0;
23-
constructor(layer: number, paths: Path[], lineNumber: number, height: number = 0) {
23+
public z: number = 0;
24+
constructor(layer: number, paths: Path[], lineNumber: number, height: number = 0, z: number = 0) {
2425
this.layer = layer;
2526
this.paths = paths;
2627
this.lineNumber = lineNumber;
2728
this.height = height;
29+
this.z = z;
2830
}
2931
}
3032

@@ -153,6 +155,9 @@ export class LayersIndexer extends Indexer {
153155
if (path.travelType === PathType.Extrusion && path.vertices.some((_, i, arr) => i % 3 === 2 && arr[i] !== arr[2])) {
154156
throw new NonPlanarPathError();
155157
}
158+
if (this.indexes[this.indexes.length - 1] === undefined) {
159+
this.createLayer(path.vertices[2]);
160+
}
156161

157162
if (path.travelType === PathType.Extrusion) {
158163
this.lastLayer().paths.push(path);
@@ -168,21 +173,19 @@ export class LayersIndexer extends Indexer {
168173
const hasExtrusions = this.lastLayer().paths.find((p) => p.travelType === PathType.Extrusion);
169174

170175
if (hasVerticalTravel && hasExtrusions) {
171-
this.createLayer();
176+
this.createLayer(path.vertices[2]);
172177
}
173178
this.lastLayer().paths.push(path);
174179
}
175180
}
176181

177182
private lastLayer(): Layer {
178-
if (this.indexes[this.indexes.length - 1] === undefined) {
179-
this.createLayer();
180-
return this.lastLayer();
181-
}
182183
return this.indexes[this.indexes.length - 1];
183184
}
184185

185-
private createLayer(): void {
186-
this.indexes.push(new Layer(this.indexes.length, [], 0));
186+
private createLayer(z: number): void {
187+
const layerNumber = this.indexes.length;
188+
const height = z - this.lastLayer()?.z;
189+
this.indexes.push(new Layer(this.indexes.length, [], layerNumber, height, z));
187190
}
188191
}

0 commit comments

Comments
 (0)