@@ -11,7 +11,7 @@ test('it has an initial state', () => {
1111} ) ;
1212
1313describe ( '.isPlanar' , ( ) => {
14- test ( 'returns true if all extrusions are on the same plane' , ( ) => {
14+ test ( 'if all extrusions are on the same plane (Z=0) ' , ( ) => {
1515 const job = new Job ( ) ;
1616
1717 append_path ( job , PathType . Extrusion , [
@@ -23,22 +23,33 @@ describe('.isPlanar', () => {
2323 [ 5 , 6 , 0 ]
2424 ] ) ;
2525
26- expect ( job . isPlanar ( ) ) . toEqual ( true ) ;
26+ expect ( job . isPlanar ) . toEqual ( true ) ;
2727 } ) ;
2828
29- test ( 'returns false if any extrusions are on a different plane' , ( ) => {
29+ test ( 'if all extrusions are on the same plane (Z=1) ' , ( ) => {
3030 const job = new Job ( ) ;
3131
3232 append_path ( job , PathType . Extrusion , [
33- [ 0 , 0 , 0 ] ,
34- [ 1 , 2 , 0 ]
33+ [ 0 , 0 , 1 ] ,
34+ [ 1 , 2 , 1 ]
3535 ] ) ;
36+ append_path ( job , PathType . Extrusion , [
37+ [ 1 , 2 , 1 ] ,
38+ [ 5 , 6 , 1 ]
39+ ] ) ;
40+
41+ expect ( job . isPlanar ) . toEqual ( true ) ;
42+ } ) ;
43+
44+ test ( 'if any extrusion path has a Z value that exceeds the default tolerance' , ( ) => {
45+ const job = new Job ( ) ;
46+
3647 append_path ( job , PathType . Extrusion , [
3748 [ 1 , 2 , 0 ] ,
3849 [ 5 , 6 , 1 ]
3950 ] ) ;
4051
41- expect ( job . isPlanar ( ) ) . toEqual ( false ) ;
52+ expect ( job . isPlanar ) . toEqual ( false ) ;
4253 } ) ;
4354
4455 test ( 'ignores travel paths' , ( ) => {
@@ -58,12 +69,29 @@ describe('.isPlanar', () => {
5869 [ 5 , 6 , 0 ]
5970 ] ) ;
6071
61- expect ( job . isPlanar ( ) ) . toEqual ( true ) ;
72+ expect ( job . isPlanar ) . toEqual ( true ) ;
6273 } ) ;
6374} ) ;
6475
6576describe ( '.layers' , ( ) => {
66- test ( 'returns null if the job is not planar' , ( ) => {
77+ test ( 'returns empty list if no paths are present' , ( ) => {
78+ const job = new Job ( ) ;
79+
80+ expect ( job . layers ) . toEqual ( [ ] ) ;
81+ } ) ;
82+
83+ test ( 'returns empty list if no extrusion is present' , ( ) => {
84+ const job = new Job ( ) ;
85+
86+ append_path ( job , PathType . Travel , [
87+ [ 0 , 0 , 0 ] ,
88+ [ 1 , 2 , 0 ]
89+ ] ) ;
90+
91+ expect ( job . layers ) . toEqual ( [ ] ) ;
92+ } ) ;
93+
94+ test ( 'returns empty list if the job is not planar' , ( ) => {
6795 const job = new Job ( ) ;
6896
6997 append_path ( job , PathType . Extrusion , [
@@ -76,16 +104,17 @@ describe('.layers', () => {
76104 ] ) ;
77105
78106 expect ( job . layers ) . toEqual ( [ ] ) ;
107+ expect ( job . isPlanar ) . toEqual ( false ) ;
79108 } ) ;
80109
81- test ( 'paths without z changes are on the same layer' , ( ) => {
110+ test ( 'extrusions with same Z value are on the same layer' , ( ) => {
82111 const job = new Job ( ) ;
83112
84113 append_path ( job , PathType . Extrusion , [
85114 [ 0 , 0 , 0 ] ,
86115 [ 1 , 2 , 0 ]
87116 ] ) ;
88- append_path ( job , PathType . Travel , [
117+ append_path ( job , PathType . Extrusion , [
89118 [ 5 , 6 , 0 ] ,
90119 [ 5 , 6 , 0 ]
91120 ] ) ;
@@ -119,7 +148,7 @@ describe('.layers', () => {
119148 expect ( layers [ 1 ] . paths . length ) . toEqual ( 1 ) ;
120149 } ) ;
121150
122- test ( 'travel paths moving z under the default tolerance are on the same layer' , ( ) => {
151+ test ( 'travel with a z component is still on the same layer' , ( ) => {
123152 const job = new Job ( ) ;
124153
125154 append_path ( job , PathType . Extrusion , [
@@ -128,7 +157,7 @@ describe('.layers', () => {
128157 ] ) ;
129158 append_path ( job , PathType . Travel , [
130159 [ 5 , 6 , 0 ] ,
131- [ 5 , 6 , LayersIndexer . DEFAULT_TOLERANCE - 0.01 ]
160+ [ 5 , 6 , 42 ]
132161 ] ) ;
133162
134163 const layers = job . layers ;
@@ -146,7 +175,7 @@ describe('.layers', () => {
146175 [ 0 , 0 , 0 ] ,
147176 [ 1 , 2 , 0 ]
148177 ] ) ;
149- append_path ( job , PathType . Travel , [
178+ append_path ( job , PathType . Extrusion , [
150179 [ 5 , 6 , 0 ] ,
151180 [ 5 , 6 , 0.09 ]
152181 ] ) ;
@@ -190,6 +219,38 @@ describe('.layers', () => {
190219 test ( 'extrusions after travels are on the same layer' , ( ) => {
191220 const job = new Job ( ) ;
192221
222+ append_path ( job , PathType . Extrusion , [
223+ [ 0 , 0 , 0 ] ,
224+ [ 1 , 2 , 0 ]
225+ ] ) ;
226+ append_path ( job , PathType . Travel , [
227+ [ 5 , 6 , 0 ] ,
228+ [ 5 , 6 , 2 ]
229+ ] ) ;
230+ append_path ( job , PathType . Travel , [
231+ [ 5 , 6 , 2 ] ,
232+ [ 5 , 6 , 0 ]
233+ ] ) ;
234+ append_path ( job , PathType . Travel , [
235+ [ 5 , 6 , 0 ] ,
236+ [ 5 , 6 , 2 ]
237+ ] ) ;
238+ append_path ( job , PathType . Extrusion , [
239+ [ 5 , 6 , 0 ] ,
240+ [ 5 , 6 , 0 ]
241+ ] ) ;
242+
243+ const layers = job . layers ;
244+
245+ expect ( layers ) . not . toBeNull ( ) ;
246+ expect ( layers ) . toBeInstanceOf ( Array ) ;
247+ expect ( layers . length ) . toEqual ( 1 ) ;
248+ expect ( layers [ 0 ] . paths . length ) . toEqual ( 5 ) ;
249+ } ) ;
250+
251+ test ( 'extrusions with a new Z value after travels are on a new layer' , ( ) => {
252+ const job = new Job ( ) ;
253+
193254 append_path ( job , PathType . Extrusion , [
194255 [ 0 , 0 , 0 ] ,
195256 [ 1 , 2 , 0 ]
@@ -220,7 +281,7 @@ describe('.layers', () => {
220281 expect ( layers [ 1 ] . paths . length ) . toEqual ( 1 ) ;
221282 } ) ;
222283
223- test ( 'initial travels are on the same layer as the first extrusion ' , ( ) => {
284+ test ( 'travel paths before the first extrusion are not indexed ' , ( ) => {
224285 const job = new Job ( ) ;
225286
226287 append_path ( job , PathType . Travel , [
@@ -244,7 +305,61 @@ describe('.layers', () => {
244305
245306 expect ( layers ) . not . toBeNull ( ) ;
246307 expect ( layers . length ) . toEqual ( 1 ) ;
247- expect ( layers [ 0 ] . paths . length ) . toEqual ( 4 ) ;
308+ expect ( layers [ 0 ] . paths . length ) . toEqual ( 1 ) ;
309+ } ) ;
310+
311+ test ( 'layer z must equal path z' , ( ) => {
312+ const job = new Job ( ) ;
313+
314+ append_path ( job , PathType . Extrusion , [
315+ [ 5 , 6 , 2 ] ,
316+ [ 5 , 6 , 2 ]
317+ ] ) ;
318+
319+ const layers = job . layers ;
320+
321+ expect ( layers ) . not . toBeNull ( ) ;
322+ expect ( layers . length ) . toEqual ( 1 ) ;
323+ expect ( layers [ 0 ] . z ) . toEqual ( 2 ) ;
324+ } ) ;
325+
326+ test ( 'layer z must equal extrusion path z' , ( ) => {
327+ const job = new Job ( ) ;
328+
329+ append_path ( job , PathType . Extrusion , [
330+ [ 5 , 6 , 2 ] ,
331+ [ 5 , 6 , 2 ]
332+ ] ) ;
333+
334+ append_path ( job , PathType . Travel , [
335+ [ 5 , 6 , 4 ] ,
336+ [ 5 , 6 , 4 ]
337+ ] ) ;
338+
339+ const layers = job . layers ;
340+
341+ expect ( layers ) . not . toBeNull ( ) ;
342+ expect ( layers . length ) . toEqual ( 1 ) ;
343+ expect ( layers [ 0 ] . z ) . toEqual ( 2 ) ;
344+ } ) ;
345+
346+ test ( 'layer z must equal path z, for second layer' , ( ) => {
347+ const job = new Job ( ) ;
348+
349+ append_path ( job , PathType . Extrusion , [
350+ [ 5 , 6 , 2 ] ,
351+ [ 5 , 6 , 2 ]
352+ ] ) ;
353+ append_path ( job , PathType . Extrusion , [
354+ [ 5 , 6 , 4 ] ,
355+ [ 5 , 6 , 4 ]
356+ ] ) ;
357+
358+ const layers = job . layers ;
359+
360+ expect ( layers ) . not . toBeNull ( ) ;
361+ expect ( layers . length ) . toEqual ( 2 ) ;
362+ expect ( layers [ 1 ] . z ) . toEqual ( 4 ) ;
248363 } ) ;
249364} ) ;
250365
0 commit comments