@@ -20,7 +20,7 @@ export class Job {
2020 state : State ;
2121 private travelPaths : Path [ ] = [ ] ;
2222 private extrusionPaths : Path [ ] = [ ] ;
23- private layersPaths : Path [ ] [ ] | null = [ ] ;
23+ private layersPaths : Path [ ] [ ] | null = [ [ ] ] ;
2424 private indexers : Indexer [ ] = [
2525 new TravelTypeIndexer ( { travel : this . travelPaths , extrusion : this . extrusionPaths } ) ,
2626 new LayersIndexer ( this . layersPaths )
@@ -62,16 +62,19 @@ export class Job {
6262 try {
6363 indexer . sortIn ( path ) ;
6464 } catch ( e ) {
65- if ( e . message === "Non-planar paths can't be indexed by layer" ) {
66- this . layersPaths = null ;
65+ if ( e . instanceOf ( NonApplicableIndexer ) ) {
66+ if ( e . instanceOf ( NonPlanarPathError ) ) {
67+ this . layersPaths = null ;
68+ }
69+ const i = this . indexers . indexOf ( indexer ) ;
70+ this . indexers . splice ( i , 1 ) ;
6771 }
68- const i = this . indexers . indexOf ( indexer ) ;
69- this . indexers . splice ( i , 1 ) ;
7072 }
7173 } ) ;
7274 }
7375}
7476
77+ class NonApplicableIndexer extends Error { }
7578class Indexer {
7679 protected indexes : Record < string , Path [ ] > | Path [ ] [ ] ;
7780 constructor ( indexes : Record < string , Path [ ] > | Path [ ] [ ] ) {
@@ -98,6 +101,11 @@ class TravelTypeIndexer extends Indexer {
98101 }
99102}
100103
104+ class NonPlanarPathError extends NonApplicableIndexer {
105+ constructor ( ) {
106+ super ( "Non-planar paths can't be indexed by layer" ) ;
107+ }
108+ }
101109class LayersIndexer extends Indexer {
102110 protected indexes : Path [ ] [ ] ;
103111 constructor ( indexes : Path [ ] [ ] ) {
@@ -106,7 +114,7 @@ class LayersIndexer extends Indexer {
106114
107115 sortIn ( path : Path ) : void {
108116 if ( path . travelType === PathType . Extrusion && path . vertices . some ( ( _ , i , arr ) => i % 3 === 2 && arr [ i ] !== arr [ 2 ] ) ) {
109- throw new Error ( "Non-planar paths can't be indexed by layer" ) ;
117+ throw new NonPlanarPathError ( ) ;
110118 }
111119
112120 if ( path . travelType === PathType . Extrusion ) {
0 commit comments