-
Notifications
You must be signed in to change notification settings - Fork 55
/
K40NanoDriver.java
1864 lines (1696 loc) · 43.4 KB
/
K40NanoDriver.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This file is part of LibLaserCut.
Copyright (C) 2011 - 2014 Thomas Oster <mail@thomas-oster.de>
LibLaserCut is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LibLaserCut is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with LibLaserCut. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thomas_oster.liblasercut.drivers;
import de.thomas_oster.liblasercut.properties.AbstractLaserProperty;
import de.thomas_oster.liblasercut.IllegalJobException;
import de.thomas_oster.liblasercut.JobPart;
import de.thomas_oster.liblasercut.LaserCutter;
import de.thomas_oster.liblasercut.LaserJob;
import de.thomas_oster.liblasercut.properties.LaserProperty;
import de.thomas_oster.liblasercut.ProgressListener;
import de.thomas_oster.liblasercut.RasterBuilder;
import de.thomas_oster.liblasercut.RasterElement;
import de.thomas_oster.liblasercut.RasterPart;
import de.thomas_oster.liblasercut.VectorCommand;
import de.thomas_oster.liblasercut.VectorPart;
import de.thomas_oster.liblasercut.utils.LinefeedPrintStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import org.usb4java.Context;
import org.usb4java.Device;
import org.usb4java.DeviceDescriptor;
import org.usb4java.ConfigDescriptor;
import org.usb4java.DeviceHandle;
import org.usb4java.Interface;
import org.usb4java.InterfaceDescriptor;
import org.usb4java.DeviceList;
import org.usb4java.LibUsb;
import org.usb4java.LibUsbException;
public class K40NanoDriver extends LaserCutter
{
private static final String VAR_MM_PER_SECOND = "mm per second";
private static final String VAR_D_RATIO = "diagonal ratio";
private static final String VAR_POWER = "power";
private static final String SETTING_BEDWIDTH = "Laserbed Width";
private static final String SETTING_BEDHEIGHT = "Laserbed Height";
private static final String SETTING_BOARD = "M2, M1, M, B2, B1, B, A, board selection";
private static final String SETTING_MOCK = "Use mock usb channel";
private static final String[] settingAttributes = new String[]
{
SETTING_BEDWIDTH, SETTING_BEDHEIGHT, SETTING_BOARD, SETTING_MOCK
};
//310mm by 220mm
double bedWidth = 310;
double bedHeight = 220;
String board = "M2";
boolean mock = false;
PrintStream saveJob = null;
List<String> warnings = null;
ProgressListener progress = null;
/**
* This is the core method of the driver. It is called, whenever LibLaseCut
* wants your driver to send a job to the lasercutter.
*
* @param job This is an LaserJob object, containing all information on the
* job, which is to be sent
* @param pl Use this object to inform VisiCut about the progress of your
* sending action.
* @param warnings If you there are warnings for the user, you can add them to
* this list, so they can be displayed by VisiCut
* @throws IllegalJobException Throw this exception, when the job is not
* suitable for the current machine
*/
@Override
public void sendJob(LaserJob job, ProgressListener pl, List<String> warnings) throws IllegalJobException, Exception
{
this.progress = pl;
this.warnings = warnings;
//let's check the job for some errors
checkJob(job);
K40Device device = new K40Device();
device.setBoard(board);
this.progress.taskChanged(this, "Opening Device.");
if (saveJob == null)
{
device.open();
}
else
{
device.open(new K40Queue()
{
@Override
public void execute()
{
}
@Override
public void add(String element)
{
saveJob.println(element);
}
@Override
public void close()
{
}
@Override
public void open()
{
}
});
}
for (JobPart p : job.getParts())
{
if (p instanceof RasterPart)
{
RasterPart rp = (RasterPart) p;
LaserProperty property = rp.getLaserProperty();
double speed = (Float) property.getProperty("mm per second");
device.setSpeed(speed);
int sx = (int) (rp.getMinX() * (1000 / p.getDPI()));
int sy = (int) (rp.getMinY() * (1000 / p.getDPI()));
device.move_absolute(sx, sy);
int step_size = (int) (1000.0 / p.getDPI());
device.setRaster_step(step_size);
RasterElement element = ((RasterElement.Provider) rp.getImage()).getRaster();
RasterBuilder rasterbuild = new RasterBuilder(element, (properties, pixel) -> properties.setProperty("pixel", pixel), 0, 0, 0);
rasterbuild.setOffsetPosition(rp.getMinX(), rp.getMinY());
int pixel = 0;
device.raster_start();
for (VectorCommand cmd : rasterbuild)
{
if ((cmd.getType() == VectorCommand.CmdType.MOVETO) || ((cmd.getType() == VectorCommand.CmdType.LINETO) && (pixel == 0))) //treat moveto with pixel 0 as a lineto.
{
int x = (int) (cmd.getX() * (1000 / p.getDPI()));
int y = (int) (cmd.getY() * (1000 / p.getDPI()));
int dx = x - device.x;
int dy = y - device.y;
if (dy > device.raster_step)
{
device.move_absolute(x, y - device.raster_step);
//if we're moving in the y direction, but more than the raster step,
//we still need to h_switch to change the directionality. But, that will
//step, so we go down to where the raster-step will put us on the correct line.
}
if (dy == device.raster_step)
{
device.h_switch();
device.y += device.raster_step;
}
device.move_absolute(x, y);
device.execute();
}
else
{
switch (cmd.getType())
{
case LINETO:
{
int x = (int) (cmd.getX() * (1000 / p.getDPI()));
int y = (int) (cmd.getY() * (1000 / p.getDPI()));
//Native units are mils.
device.cut_absolute(x, y);
device.execute();
break;
}
case SETPROPERTY:
{
AbstractLaserProperty prop = (AbstractLaserProperty) cmd.getProperty();
pixel = prop.getInteger("pixel", pixel);
break;
}
}
}
}
}
else if (p instanceof VectorPart)
{
VectorPart vp = (VectorPart) p;
int i = 0;
int total = vp.getCommandList().length;
for (VectorCommand cmd : vp.getCommandList())
{
pl.taskChanged(this, "Vector Part");
pl.progressChanged(this, (100 * i++) / total);
switch (cmd.getType())
{
case LINETO:
{
/*
Move the laserhead (laser on) from the current position to the
x/y position of this command. All coordinates are in dots
respecting to the job resolution
*/
int x = (int) (cmd.getX() * (1000 / p.getDPI()));
int y = (int) (cmd.getY() * (1000 / p.getDPI()));
//Native units are mils.
device.cut_absolute(x, y);
device.execute();
break;
}
case MOVETO:
{
/*
Move the laserhead (laser off) from the current position to the
x/y position of this command. All coordinates are in mm
*/
int x = (int) (cmd.getX() * (1000 / p.getDPI()));
int y = (int) (cmd.getY() * (1000 / p.getDPI()));
//Native units are mils.
device.move_absolute(x, y);
device.execute();
break;
}
case SETPROPERTY:
{
LaserProperty prop = cmd.getProperty();
for (String key : prop.getPropertyKeys())
{
String value = prop.getProperty(key).toString();
if (VAR_MM_PER_SECOND.equals(key) || "speed".equals(key))
{
device.setSpeed(Double.valueOf(value));
}
else if (VAR_D_RATIO.equals(key))
{
device.setD_ratio(Double.valueOf(value));
}
else if (VAR_POWER.equals(key))
{
device.setPower(Integer.valueOf(value));
}
}
break;
}
}
}
}
}
device.exit_compact_mode();
device.move_absolute(0, 0); //Return device to start position 0,0.
device.execute();
device.close();
}
@Override
public void saveJob(OutputStream fileOutputStream, LaserJob job) throws UnsupportedOperationException, IllegalJobException, Exception
{
try (PrintStream ps = new LinefeedPrintStream(fileOutputStream))
{
saveJob = ps;
sendJob(job);
}
finally
{
saveJob = null;
}
}
@Override
public LaserProperty getLaserPropertyForVectorPart()
{
AbstractLaserProperty property = new AbstractLaserProperty();
property.addPropertyRanged("mm per second", 30f, 0.4f, 240f);
property.addPropertyRanged("power", 1000, 0, 1000);
property.addPropertyRanged("diagonal speed adjustment", 0.2612f, 0f, 1f);
return property;
}
@Override
public LaserProperty getLaserPropertyForRasterPart()
{
AbstractLaserProperty property = new AbstractLaserProperty();
property.addPropertyRanged("mm per second", 60f, 5f, 500f);
property.addPropertyRanged("power", 1000, 0, 1000);
return property;
}
/**
* This method returns a list of all supported resolutions (in DPI)
*/
@Override
public List<Double> getResolutions()
{
return Arrays.asList(250.0, 500.0, 1000.0);
}
public String getBoard()
{
return board;
}
public void setBoard(String board)
{
this.board = board;
}
public boolean isMock()
{
return mock;
}
public void setMock(boolean mock)
{
this.mock = mock;
}
public void setBedWidth(double bedWidth)
{
this.bedWidth = bedWidth;
}
public void setBedHeight(double bedHeight)
{
this.bedHeight = bedHeight;
}
@Override
public double getBedWidth()
{
return this.bedWidth;
}
@Override
public double getBedHeight()
{
return this.bedHeight;
}
@Override
public String getModelName()
{
return "K40 Stock-LIHUIYU M2/M1/M/B2/B1/B/A";
}
@Override
public LaserCutter clone()
{
K40NanoDriver clone = new K40NanoDriver();
clone.bedHeight = this.bedHeight;
clone.bedWidth = this.bedWidth;
clone.board = this.board;
clone.mock = this.mock;
return clone;
}
@Override
public String[] getPropertyKeys()
{
return settingAttributes;
}
@Override
public void setProperty(String attribute, Object value)
{
if (SETTING_BEDWIDTH.equals(attribute))
{
this.setBedWidth((Double) value);
}
else if (SETTING_BEDHEIGHT.equals(attribute))
{
this.setBedHeight((Double) value);
}
else if (SETTING_BOARD.equals(attribute))
{
this.setBoard((String) value);
}
else if (SETTING_MOCK.equals(attribute))
{
this.setMock((Boolean) value);
}
}
@Override
public Object getProperty(String attribute)
{
if (SETTING_BEDWIDTH.equals(attribute))
{
return this.getBedWidth();
}
else if (SETTING_BEDHEIGHT.equals(attribute))
{
return this.getBedHeight();
}
else if (SETTING_BOARD.equals(attribute))
{
return this.getBoard();
}
else if (SETTING_MOCK.equals(attribute))
{
return this.isMock();
}
return null;
}
public class K40Device
{
private static final int UNINIT = 0;
private static final int DEFAULT = 1;
private static final int COMPACT = 2;
static final char LASER_ON = 'D';
static final char LASER_OFF = 'U';
static final char RIGHT = 'B';
static final char LEFT = 'T';
static final char TOP = 'L';
static final char BOTTOM = 'R';
static final char DIAGONAL = 'M';
K40Queue queue;
private final StringBuilder builder = new StringBuilder();
private int mode = UNINIT;
private boolean is_top = false;
private boolean is_left = false;
private boolean is_on = false;
private String board = "M2";
private double speed = 30;
private int raster_step = 1;
private int power = 1000;
double d_ratio = 0.2612;
private int power_remainder = 0;
private int x = 0;
private int y = 0;
void open()
{
open(new K40Queue());
}
void open(K40Queue q)
{
queue = q;
q.open();
}
void close()
{
if (mode == COMPACT)
{
exit_compact_mode();
execute();
}
queue.close();
queue = null;
}
public String getBoard()
{
return board;
}
public void setBoard(String board)
{
this.board = board;
}
void setSpeed(double mm_per_second)
{
if (mode == COMPACT)
{
exit_compact_mode();
}
speed = mm_per_second;
}
void setPower(int ppi)
{
power = ppi;
}
public int getRaster_step()
{
return raster_step;
}
public void setRaster_step(int raster_step)
{
if (raster_step > 64)
{
raster_step = 64;
}
if (raster_step < 1)
{
raster_step = 1;
}
this.raster_step = raster_step;
}
public double getD_ratio()
{
return d_ratio;
}
public void setD_ratio(double d_ratio)
{
this.d_ratio = d_ratio;
}
void send()
{
queue.add(builder.toString());
builder.delete(0, builder.length());
}
void home()
{
exit_compact_mode();
builder.append("IPP\n");
send();
mode = UNINIT;
x = 0;
y = 0;
}
void unlock_rail()
{
exit_compact_mode();
builder.append("IS2P\n");
send();
mode = UNINIT;
}
void lock_rail()
{
exit_compact_mode();
builder.append("IS1P\n");
send();
mode = UNINIT;
}
void move_absolute(int x, int y)
{
int dx = x - this.x;
int dy = y - this.y;
move_relative(dx, dy);
}
void move_relative(int dx, int dy)
{
if ((dx == 0) && (dy == 0))
{
return;
}
check_init();
laser_off();
if (mode == DEFAULT)
{
encode_default_move(dx, dy);
}
else
{
makeLine(0, 0, dx, dy);
}
send();
}
void cut_absolute(int x, int y)
{
int dx = x - this.x;
int dy = y - this.y;
cut_relative(dx, dy);
}
void cut_relative(int dx, int dy)
{
if ((dx == 0) && (dy == 0))
{
return;
}
check_init();
if (mode != COMPACT)
{
start_compact_mode();
}
laser_on();
makeLine(0, 0, dx, dy);
send();
}
void raster_start()
{
laser_off();
check_init();
if (mode == COMPACT)
{
exit_compact_mode();
}
builder.append(getSpeed(speed, true));
builder.append('N');
builder.append(BOTTOM);
builder.append(RIGHT);
builder.append("S1E");
is_top = false;
is_left = false;
mode = COMPACT;
}
void raster_end()
{
exit_compact_mode();
}
void check_init()
{
if (mode == UNINIT)
{
builder.append('I');
mode = DEFAULT;
}
}
void exit_compact_mode()
{
if (mode == COMPACT)
{
builder.append("FNSE-\n");
send();
is_on = false;
mode = UNINIT;
}
}
void start_compact_mode()
{
check_init();
if (mode == COMPACT)
{
return;
}
if (mode == DEFAULT)
{
encode_speed(speed);
builder.append('N');
if (is_top)
{
builder.append(TOP);
}
else
{
builder.append(BOTTOM);
}
if (is_left)
{
builder.append(LEFT);
}
else
{
builder.append(RIGHT);
}
builder.append("S1E");
}
mode = COMPACT;
}
void execute()
{
queue.execute();
}
void encode_default_move(int dx, int dy)
{
move_x(dx);
move_y(dy);
builder.append("S1P\n");
mode = UNINIT;
}
void encode_speed(double speed)
{
builder.append(getSpeed(speed));
}
void move_x(int dx)
{
if (0 < dx)
{
builder.append(RIGHT);
is_left = false;
}
else
{
builder.append(LEFT);
is_left = true;
}
distance(Math.abs(dx));
this.x += dx;
}
void move_y(int dy)
{
if (0 < dy)
{
builder.append(BOTTOM);
is_top = false;
}
else
{
builder.append(TOP);
is_top = true;
}
distance(Math.abs(dy));
this.y += dy;
}
void move_angle(int dx, int dy)
{
//assert(abs(dx) == abs(dy));
if (0 < dx)
{
if (is_left)
{
builder.append(RIGHT);
}
is_left = false;
}
else
{
if (!is_left)
{
builder.append(LEFT);
}
is_left = true;
}
if (0 < dy)
{
if (is_top)
{
builder.append(BOTTOM);
}
is_top = false;
}
else
{
if (!is_top)
{
builder.append(TOP);
}
is_top = true;
}
builder.append(DIAGONAL);
distance(Math.abs(dx));
this.x += dx;
this.y += dy;
}
void move_diagonal(int v)
{
builder.append(DIAGONAL);
distance(Math.abs(v));
if (is_top)
{
this.y -= v;
}
else
{
this.y += v;
}
if (is_left)
{
this.x -= v;
}
else
{
this.x += v;
}
}
void set_top()
{
if (!is_top)
{
builder.append(TOP);
}
is_top = true;
}
void set_bottom()
{
if (is_top)
{
builder.append(BOTTOM);
}
is_top = false;
}
void set_left()
{
if (!is_left)
{
builder.append(LEFT);
}
is_left = true;
}
void set_right()
{
if (is_left)
{
builder.append(RIGHT);
}
is_left = false;
}
void laser_on()
{
if (!is_on)
{
builder.append(LASER_ON);
}
is_on = true;
}
void laser_off()
{
if (is_on)
{
builder.append(LASER_OFF);
}
is_on = false;
}
public void h_switch()
{
if (is_left)
{
this.set_right();
}
else
{
this.set_left();
}
}
public void v_switch()
{
if (is_top)
{
this.set_bottom();
}
else
{
this.set_top();
}
}
/*
* Zingl-Bresenham line draw algorithm
* With Tatarize's PPI carryforward power modulation.
*
* The general goal of this is to trigger a state sync, if the laser is to
* change state or if the next movement is not exactly diagonal or orthogonal
* all other states can be combined into the same movement.
*/
void makeLine(int x0, int y0, int x1, int y1)
{
int dx = Math.abs(x1 - x0);
int dy = -Math.abs(y1 - y0);
int sx = (x0 < x1) ? 1 : -1;
int sy = (y0 < y1) ? 1 : -1;
int err = dx + dy; //error value e_xy
int cud_x = 0; //Current unapplied delta x
int cud_y = 0; //Current unapplied delta y
int dud_x = 0; //Previous unapplied delta x
int dud_y = 0; //Previous unapplied delta y
boolean laser_cutting = this.is_on;
boolean pulse_on = this.is_on;
while (true)
{
/* loop */
if (laser_cutting)
{
power_remainder += power;
if (power_remainder >= 1000)
{
power_remainder -= 1000;
pulse_on = true;
}
else
{
pulse_on = false;
}
}
int abs_cud_x = Math.abs(cud_x);
int abs_cud_y = Math.abs(cud_y);
if (
(this.is_on != pulse_on) // fire pulse changed.
|| //Can't be combined into a command
((abs_cud_x != abs_cud_y) // not diagonal
&& (abs_cud_x != 0) // not ortho y-direction
&& (abs_cud_y != 0))) // not ortho x-direction
{
// The current settings do not combine. Actualize previous values.
int pud_x = cud_x - dud_x;
int pud_y = cud_y - dud_y;
if (Math.abs(pud_x) == Math.abs(pud_y))
{
if (pud_x != 0) {
move_angle(pud_x, pud_y);
}
}
else if ((pud_y == 0) && (pud_x != 0))
{
move_x(pud_x);
}
else if ((pud_y != 0) && (pud_x == 0))
{
move_y(pud_y);
}
else if ((pud_x == 0) && (pud_y == 0)) {
}
else {
}
cud_x = dud_x;
cud_y = dud_y;
if (pulse_on)
{
laser_on(); //set laser to the correct state.
}
else
{
laser_off();
}
}
if ((x0 == x1) && (y0 == y1))
{ //line has ended
if (Math.abs(cud_x) == Math.abs(cud_y))
{
if (cud_x != 0) {
move_angle(cud_x, cud_y);
}
}
else if ((cud_y == 0) && (cud_x != 0))
{
move_x(cud_x);
}
else if ((cud_y != 0) && (cud_x == 0))
{
move_y(cud_y);
}
break;
}
int e2 = 2 * err;
if (e2 >= dy)
{// # e_xy+e_y < 0
err += dy;
x0 += sx;
dud_x = sx;
cud_x += dud_x;
}
else {
dud_x = 0;
}
if (e2 <= dx)
{// # e_xy+e_y < 0
err += dx;
y0 += sy;
dud_y = sy;
cud_y += dud_y;
}