@@ -81,6 +81,101 @@ describe('G-code Toolpath', () => {
8181 } ) ;
8282 } ) ;
8383
84+ describe ( 'position' , ( ) => {
85+ it ( 'should match the specified position.' , ( done ) => {
86+ const toolpath = new Toolpath ( {
87+ position : { x : 200 , y : 100 }
88+ } ) ;
89+ expect ( toolpath . getPosition ( ) ) . to . deep . equal ( { x : 200 , y : 100 , z : 0 } ) ;
90+ toolpath . setPosition ( { y : 200 , z : 10 } ) ;
91+ expect ( toolpath . getPosition ( ) ) . to . deep . equal ( { x : 200 , y : 200 , z : 10 } ) ;
92+ toolpath . setPosition ( 10 , 10 ) ;
93+ expect ( toolpath . getPosition ( ) ) . to . deep . equal ( { x : 10 , y : 10 , z : 10 } ) ;
94+ toolpath . setPosition ( 0 , 0 , 0 ) ;
95+ expect ( toolpath . getPosition ( ) ) . to . deep . equal ( { x : 0 , y : 0 , z : 0 } ) ;
96+ done ( ) ;
97+ } ) ;
98+ } ) ;
99+
100+ describe ( 'modal' , ( ) => {
101+ it ( 'should match the specified modal state.' , ( done ) => {
102+ const toolpath = new Toolpath ( {
103+ modal : {
104+ tool : 1
105+ }
106+ } ) ;
107+ const expectedModal = {
108+ // Moton Mode
109+ // G0, G1, G2, G3, G38.2, G38.3, G38.4, G38.5, G80
110+ motion : 'G0' ,
111+
112+ // Coordinate System Select
113+ // G54, G55, G56, G57, G58, G59
114+ wcs : 'G54' ,
115+
116+ // Plane Select
117+ // G17: XY-plane, G18: ZX-plane, G19: YZ-plane
118+ plane : 'G17' ,
119+
120+ // Units Mode
121+ // G20: Inches, G21: Millimeters
122+ units : 'G21' ,
123+
124+ // Distance Mode
125+ // G90: Absolute, G91: Relative
126+ distance : 'G90' ,
127+
128+ // Arc IJK distance mode
129+ arc : 'G91.1' ,
130+
131+ // Feed Rate Mode
132+ // G93: Inverse time mode, G94: Units per minute mode, G95: Units per rev mode
133+ feedrate : 'G94' ,
134+
135+ // Cutter Radius Compensation
136+ cutter : 'G40' ,
137+
138+ // Tool Length Offset
139+ // G43.1, G49
140+ tlo : 'G49' ,
141+
142+ // Program Mode
143+ // M0, M1, M2, M30
144+ program : 'M0' ,
145+
146+ // Spingle State
147+ // M3, M4, M5
148+ spindle : 'M5' ,
149+
150+ // Coolant State
151+ // M7, M8, M9
152+ coolant : 'M9' , // 'M7', 'M8', 'M7,M8', or 'M9'
153+
154+ // Tool Select
155+ tool : 0
156+ } ;
157+
158+ expect ( toolpath . getModal ( ) ) . to . deep . equal ( {
159+ motion : 'G0' ,
160+ wcs : 'G54' ,
161+ plane : 'G17' ,
162+ units : 'G21' ,
163+ distance : 'G90' ,
164+ arc : 'G91.1' ,
165+ feedrate : 'G94' ,
166+ cutter : 'G40' ,
167+ tlo : 'G49' ,
168+ program : 'M0' ,
169+ spindle : 'M5' ,
170+ coolant : 'M9' ,
171+ tool : 1
172+ } ) ;
173+ toolpath . setModal ( { tool : 2 } ) ;
174+ expect ( toolpath . getModal ( ) . tool ) . to . equal ( 2 ) ;
175+ done ( ) ;
176+ } ) ;
177+ } ) ;
178+
84179 describe ( 'Linear Move: G0/G1' , ( ) => {
85180 it ( 'should generate tool paths for linear movement.' , ( done ) => {
86181 const expectedMotions = [
0 commit comments