-
Notifications
You must be signed in to change notification settings - Fork 7
/
Round Corner Customization.jsx
1895 lines (1136 loc) · 53.5 KB
/
Round Corner Customization.jsx
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
/*!
* Round Corners Customization v.0.1.4
* https://github.com/kefiijrw/Round-Corners-Customization-for-Illustrator
*
* Author: Sergey Nikolaev
* kefiijrw.com
*
* Date: 2024-06-12
*
*
* CHANGELOG:
*
* v.0.0.1
* Initial release
*
* v.0.0.2
* Added a warning when trying to run the script on points without rounding.
*
* Now if a point has handles in both directions, and only one of them is
* directed to the other selected point, then only this handle will move.
*
* v.0.0.3
* Fixed a bug that removed the opposite to the corner handle.
*
* v.0.0.4
* Option to hide the curvature profile is now avaible in the interface.
* The language of the settings panel adjusts to the Illustrator locale.
*
* v.0.1.0
* Public release
* The script file and the settings window title now have a more specific name.
*
* v.0.1.1
* Isolation mode support
*
* v.0.1.2
* Symbol editing mode support
*
* v.0.1.3
* Fixed Illustrator crashing when script runned with the "Show curvature profile" option disabled
*
* v.0.1.4
* Fixed script encoding problem
*
*/
//show the settings panel on startup
var ui = true;
//show the curvature profile
var show_profile = true;
//curvature profile color
var curviture_color = newCMYKColor(0, 35, 60, 0);
//do we write in the log file
var debug_mode = false;
//max value of the first coefficient on the slider
var max_coef1 = 3;
//max value of the second coefficient on the slider
var max_coef2 = 1;
//script was run with the shift key pressed
var shifted = false;
//Working with current documents
var doc = app.activeDocument;
var i, p, dxl, dxr, dyl, dyr;
var coefs = [];
var coef1; //point offset
var coef2; //handle offset
var tmp_layer;
var selectedPointsSaved = [];
//a global flag that remembers if there is something suitable for the script among the selected points
var points_to_move = false;
/*
SOME HELPING FUNTIONS
*/
// color creation
function newCMYKColor(c, m, y, k) {
var col = new CMYKColor();
col.cyan = c;
col.magenta = m;
col.yellow = y;
col.black = k;
return col;
}
//write a line in the log file (sorry, bad habit)
function echo(what) {
if (debug_mode)
log_file.write(what + '\n');
}
// rounding values of coefficients to .000 to show in inputs
function roundOff(x) {
var place = 1000;
x = Math.round(x * place);
x /= place;
return x;
}
// return the line in the right language, depending on the illustrator's locale
function loc(vars) {
if (app.locale.indexOf('ru_') == 0)
return vars.ru;
else
return vars.en;
}
/*
CONFIG OPERATION FUNCTIONS
*/
// Read presets from illustrator settings
function init_configs() {
echo('init_configs');
//flag in the illustrator settings saying that the script has already been run before
var was = app.preferences.getIntegerPreference('corner_smoothing_script_first_launch_already_was');
if (was != 6) { //very dumb, sorry. it didn't work to save boolean so 6 is true and 2 is false
//first launch
echo('first_launch!');
//default presets
coefs = [
{
"name": "Default",
"coef1": 0.702,
"coef2": 0.111
},
{
"name": "big",
"coef1": 0.494,
"coef2": 0.171
},
{
"name": "ellipsoid",
"coef1": 0.682,
"coef2": 0.365
}
];
coef1 = coefs[0].coef1; //point
coef2 = coefs[0].coef2; //handle
//save these values in illustrator settings
from_vars_to_prefs();
//remember that first launch was
app.preferences.setIntegerPreference('corner_smoothing_script_first_launch_already_was', 6);
} else {
echo('not first launch');
//not first launch
//read script settings from illustrator settings
from_prefs_to_vars();
}
}
// saving current state (coefficients, presets, checkboxes) to the illustrator settings, so they can be recovered again after restarting the illustrator
function from_vars_to_prefs() {
echo('from_vars_to_prefs ');
for (var i = 0; i < coefs.length; i++) {
echo('set config ' + i + ': ' + coefs[i].name + ', ' + coefs[i].coef1 + ', ' + coefs[i].coef2);
app.preferences.setStringPreference('corner_smoothing_script_config_' + i + '_name', coefs[i].name);
app.preferences.setRealPreference('corner_smoothing_script_config_' + i + '_coef1', coefs[i].coef1);
app.preferences.setRealPreference('corner_smoothing_script_config_' + i + '_coef2', coefs[i].coef2);
}
echo('set congifs_count to ' + coefs.length);
app.preferences.setIntegerPreference("corner_smoothing_script_saved_congifs_count", coefs.length);
echo('set current coefs to ' + coef1 + ', ' + coef2);
app.preferences.setRealPreference('corner_smoothing_script_current_coef1', coef1);
app.preferences.setRealPreference('corner_smoothing_script_current_coef2', coef2);
var uii = ui ? 6 : 2;
echo('set ui to ' + uii);
app.preferences.setIntegerPreference('corner_smoothing_script_show_ui', uii);
var prof = show_profile ? 6 : 2;
echo('set show_profile to ' + prof);
app.preferences.setIntegerPreference('corner_smoothing_script_show_profile', prof);
}
//opposite, restoring the state of the script from the saved illustrator settings
function from_prefs_to_vars() {
echo('from_prefs_to_vars');
//how many presets are saved
var saved_congifs_count = app.preferences.getIntegerPreference('corner_smoothing_script_saved_congifs_count');
echo(saved_congifs_count);
//If it is unknown (although this is strange), then let it be 0
if (saved_congifs_count == undefined || saved_congifs_count < 0 || saved_congifs_count > 10) {
echo('no corner_smoothing_script_saved_congifs_count or invalid values, set 0');
saved_congifs_count = 0;
app.preferences.setIntegerPreference("corner_smoothing_script_saved_congifs_count", 0);
}
//if such a variable is not saved in the Illustrator settings, it can give an absurdly large number instead of null or undefined, so cut it out
if (saved_congifs_count > 40) {
echo('nooo, terminate');
saved_congifs_count = 0;
}
/* if(saved_congifs_count == 0 ){
echo('all presets are gone, strange');
}*/
echo(saved_congifs_count + ' configs');
for (var i = 0; i < saved_congifs_count; i++) {
var conf = {};
conf.name = app.preferences.getStringPreference('corner_smoothing_script_config_' + i + '_name');
conf.coef1 = app.preferences.getRealPreference('corner_smoothing_script_config_' + i + '_coef1');
conf.coef2 = app.preferences.getRealPreference('corner_smoothing_script_config_' + i + '_coef2');
echo('coef' + i + ': ' + conf.name + ', ' + conf.coef1 + ', ' + conf.coef2);
coefs.push(conf);
}
coef1 = app.preferences.getRealPreference('corner_smoothing_script_current_coef1');
coef2 = app.preferences.getRealPreference('corner_smoothing_script_current_coef2');
var s = app.preferences.getIntegerPreference('corner_smoothing_script_show_ui');
var p = app.preferences.getIntegerPreference('corner_smoothing_script_show_profile');
echo(s);
if (s == 6) {
echo('ui: true');
ui = true;
} else {
echo('ui: false');
ui = false;
}
echo(p);
if (p == 6) {
echo('profile: true');
show_profile = true;
} else {
echo('profile: false');
show_profile = false;
}
}
//erase all about script from illustrator settings and write from the variables instead
function update_prefs_from_vars() {
clear_all_prefs();
from_vars_to_prefs();
}
//erase all saved settings
function clear_all_prefs() {
echo('clear_all_prefs:');
var saved_congifs_count = app.preferences.getIntegerPreference('corner_smoothing_script_saved_congifs_count');
echo(saved_congifs_count);
echo(typeof saved_congifs_count);
//If it is unknown (although this is strange), then let it be 0
if (saved_congifs_count == undefined || saved_congifs_count < 0 || saved_congifs_count > 10) {
echo('no corner_smoothing_script_saved_congifs_count, set 0');
saved_congifs_count = 0;
}
for (var i = 0; i < saved_congifs_count; i++) {
echo('removePreference ' + i);
app.preferences.removePreference('corner_smoothing_script_config_' + i + '_name');
app.preferences.removePreference('corner_smoothing_script_config_' + i + '_coef1');
app.preferences.removePreference('corner_smoothing_script_config_' + i + '_coef2');
}
echo('set corner_smoothing_script_saved_congifs_count to 0');
app.preferences.setIntegerPreference("corner_smoothing_script_saved_congifs_count", 0);
}
//full reset, as if the script had never been run before
function factory_reset() {
echo('factory_reset');
clear_all_prefs();
echo('removePreference corner_smoothing_script_saved_congifs_count');
app.preferences.removePreference('corner_smoothing_script_saved_congifs_count');
echo('removePreference corner_smoothing_script_first_launch_already_was');
app.preferences.removePreference('corner_smoothing_script_first_launch_already_was');
echo('removePreference corner_smoothing_script_current_coef1');
echo('removePreference corner_smoothing_script_current_coef2');
echo('removePreference corner_smoothing_script_show_ui');
echo('removePreference corner_smoothing_script_show_profile');
app.preferences.removePreference('corner_smoothing_script_current_coef1');
app.preferences.removePreference('corner_smoothing_script_current_coef2');
app.preferences.removePreference('corner_smoothing_script_show_ui');
app.preferences.removePreference('corner_smoothing_script_show_profile');
}
/*
CORE FUNCTIONS
*/
//Let's go. We need to process all the corners from what
function go(what) {
echo('go!');
//see `what` it is. if it didn't pass, then work with the selection
if (what == undefined) {
what = doc.selection;
}
if (what.length == 0) {
alert(loc({'en':'Nothing selected\nSelect paths or individual points and run the script again', 'ru':'Ничего не выделено\nВыделите объекты или отдельные точки и запустите скрипт снова'}));
return false;
}
//go through everything that needs to be processed and sorted out
for (var i = 0; i < what.length; i++) {
echo('path' + (i + 1));
//create a subarray to save the points that will be processed (will be needed later)
if (selectedPointsSaved[i] === undefined) {
selectedPointsSaved[i] = [];
}
if (what[i].typename == 'PathItem') {
if (selectedPointsSaved[i].length == 0) {
echo('NATURAL SELECTED');
for (var j = 0; j < what[i].pathPoints.length; j++) {
if (what[i].pathPoints[j].selected == PathPointSelection.ANCHORPOINT) {
p = what[i].pathPoints[j];
var prev_point_i = (j == 0 ? what[i].pathPoints.length - 1 : j - 1);
var next_point_i = (j == what[i].pathPoints.length - 1 ? 0 : j + 1);
var is_prev_point_selected = (what[i].pathPoints[prev_point_i].selected == PathPointSelection.ANCHORPOINT);
var is_next_point_selected = (what[i].pathPoints[next_point_i].selected == PathPointSelection.ANCHORPOINT);
selectedPointsSaved[i].push({ 'n': j, 'prev_selected': is_prev_point_selected, 'next_selected': is_next_point_selected });
poiint(p, is_prev_point_selected, is_next_point_selected);
}
}
} else {
echo('RESTORE SELECTED POINTS');
for (var j = 0; j < selectedPointsSaved[i].length; j++) {
p = what[i].pathPoints[selectedPointsSaved[i][j].n];
poiint(p, selectedPointsSaved[i][j].prev_selected, selectedPointsSaved[i][j].next_selected);
}
}
}
}
if (points_to_move == false) {
alert(loc({'en':'Nothing to tune\nSelect rounded corners and run the script again.', 'ru':'Нечего обрабатывать\nВыделите скругленные углы и запустите скрипт снова.'}));
return false;
}
//draw a curvature profile
if (show_profile) {
draw_evolute(what);
}
return true;
}
//point processing
function poiint(p, is_prev_point_selected, is_next_point_selected) {
echo('POINT ' + is_prev_point_selected + ' ' + is_next_point_selected);
if (p.selected == PathPointSelection.ANCHORPOINT) {
//measuring the length of the point handles
dxl = p.leftDirection[0] - p.anchor[0];
dyl = p.leftDirection[1] - p.anchor[1];
dxr = p.rightDirection[0] - p.anchor[0];
dyr = p.rightDirection[1] - p.anchor[1];
if (dxl == 0 && dyl == 0 && dxr == 0 && dyr == 0) {
echo('point without handles');
} else if (!(dxl == 0 && dyl == 0) && dxr == 0 && dyr == 0) {
//only the handle to the left
echo('handle to the left');
points_to_move = true;
move_point(p, 'al');
} else if (dxl == 0 && dyl == 0 && !(dxr == 0 && dyr == 0)) {
//only the handle to the right
echo('handle to the right');
points_to_move = true;
move_point(p, 'ar');
} else { //both handles
echo('both handles');
points_to_move = true;
if (is_prev_point_selected && is_next_point_selected) {
//if both before and after points are selected, then move both handles
move_point(p, 'rl');
} else if (is_prev_point_selected) {
//otherwise move only handle to the other selected point
move_point(p, 'l');
} else if (is_next_point_selected) {
move_point(p, 'r');
} else {
//if a point has two handles and the neighbor points are not selected, then move both handles
move_point(p, 'rl');
}
}
}
}
//moving anchor and handle
function move_point(p, l_or_r) {
echo('moving point ' + l_or_r);
//anchor and left handle
if (l_or_r == 'al') {
p.anchor = [p.anchor[0] - dxl * coef1, p.anchor[1] - dyl * coef1];
p.leftDirection = [p.leftDirection[0] + dxl * coef2, p.leftDirection[1] + dyl * coef2];
p.rightDirection = [p.anchor[0], p.anchor[1]];
//anchor and right handle
} else if (l_or_r == 'ar') {
p.anchor = [p.anchor[0] - dxr * coef1, p.anchor[1] - dyr * coef1];
p.rightDirection = [p.rightDirection[0] + dxr * coef2, p.rightDirection[1] + dyr * coef2];
p.leftDirection = [p.anchor[0], p.anchor[1]];
//only left handle
} else if (l_or_r == 'l') {
p.leftDirection = [p.leftDirection[0] + dxl * coef2, p.leftDirection[1] + dyl * coef2];
//only right handle
} else if (l_or_r == 'r') {
p.rightDirection = [p.rightDirection[0] + dxr * coef2, p.rightDirection[1] + dyr * coef2];
//both handles
} else if (l_or_r == 'rl') {
p.rightDirection = [p.rightDirection[0] + dxr * coef2, p.rightDirection[1] + dyr * coef2];
p.leftDirection = [p.leftDirection[0] + dxl * coef2, p.leftDirection[1] + dyl * coef2];
}
}
//restore point selection (it is reset for some reason)
function restore_points_selection() {
echo('RESTORE SELECTED POINTS');
var what = doc.selection;
for (i = 0; i < what.length; i++) {
if (what[i].typename == 'PathItem') {
for (var j = 0; j < what[i].pathPoints.length; j++) {
what[i].pathPoints[j].selected = PathPointSelection.NOSELECTION;
}
for (var j = 0; j < selectedPointsSaved[i].length; j++) {
what[i].pathPoints[selectedPointsSaved[i][j].n].selected = PathPointSelection.ANCHORPOINT;
}
}
}
}
/*
CURVATURE VISUALIZATION FUNCTIONS
*/
//drawing curvature profile for `what`
function draw_evolute(what) {
//recursively look around all that was given and for Path start drawing curvature
for (var i = 0; i < what.length; i++) {
// draw_evolute_for_path(what[i]);
switch (what[i].typename) {
case "PathItem":
if (what[i].pathPoints.length > 1)
draw_evolute_for_path(what[i]);
break;
case "GroupItem":
draw_evolute(what[i].pageItems);
break;
case "CompoundPathItem":
draw_evolute(what[i].pathItems);
break;
case "TextFrame":
// maybe sometime
break;
}
}
}
//drawing curvature profile for the opath path
function draw_evolute_for_path(opath) {
echo('DRAW_EVOLUTE_FOR_PATH');
var t;
var bx, by;
var dots = [];
var evo_dots = [];
var curv_dots = [];
var curv_graph_dots = [[0, 0]];
var total_path_length = 0;
var current_sector_length = 0;
// var curv_graph_dots = [];
// var ss = doc.layers.getByName('Symbol Editing Mode');
//create a test layer, where the profile will be drawn, if it does not already exist
try {
tmp_layer = doc.layers.getByName('corner_smoothing_script_tmp_layer');
} catch (e) {
//if we can`t find tmp layer, trying to create it
try {
tmp_layer = doc.layers.add();
} catch (e) {
//if we can`t create tmp layer, we are most likely in isolation mode or symbol editing mode
try {
//isolation mode in layer
tmp_layer = doc.layers.getByName('Isolation Mode').layers[0].groupItems.add();
} catch (e) {
//isolation mode in group
try {
tmp_layer = doc.layers.getByName('Isolation Mode').groupItems[0].groupItems.add();
} catch (e) {
//symbol editing mode
tmp_layer = doc.layers.getByName('Symbol Editing Mode').layers[0].groupItems.add();
}
}
}
tmp_layer.name = 'corner_smoothing_script_tmp_layer';
}
var test_group = tmp_layer.groupItems.add();
test_group.opacity = 40;
var curv_path = create_empty_curv_path(test_group, true);
curv_path.name = 'start_path';
var path_for_length_measuring = create_empty_curv_path(test_group, false);
path_for_length_measuring.name = 'path_for_length_measuring';
var stroke_offset = 0;
if (opath.stroked) {
stroke_offset = opath.strokeWidth / 2;
}
//TODO: understand
stroke_offset = 0;//doesn't work yet
echo('stroke: ' + stroke_offset);
echo(opath.pathPoints.length + ' points');
var curv_path_start_point_index = 0;
var to_l = opath.pathPoints.length - 1;
/* if path is closed, return to the zero point at the end of loop */
if (opath.closed) {
to_l++;
}
/* loop for points of path */
for (var j = 0; j < to_l; j++) {
echo(' ');
echo(' ');
//current point index
var from_index = j;
//next point index (assuming that after last will zero again)
var to_index = (j + 1) % opath.pathPoints.length;
echo('from point ' + from_index + ' to ' + to_index + ' (' + (j + 1) + ')');
var p_cur = opath.pathPoints[from_index];
var P0 = p_cur.anchor;
var P1 = p_cur.rightDirection;
var p_next = opath.pathPoints[to_index];
var P2 = p_next.leftDirection;
var P3 = p_next.anchor;
if (j == 0) {
copy_point_to_path(p_cur, path_for_length_measuring);
}
copy_point_to_path(p_next, path_for_length_measuring);
echo('total_length: ' + total_path_length + ' -> ' + path_for_length_measuring.length);
//how much longer
current_sector_length = path_for_length_measuring.length - total_path_length;
//redefining
total_path_length = path_for_length_measuring.length;
echo('sector_length = ' + current_sector_length);
echo('true total_length = ' + opath.length);
echo('P0 ' + P0);
echo('P1 ' + P1);
echo('P2 ' + P2);
echo('P3 ' + P3);
if (P0[0] == P1[0] &&
P0[1] == P1[1] &&
P2[0] == P3[0] &&
P2[1] == P3[1]) {
echo('straight part');
//add points of original path to profile
reverse_points_adding(opath, curv_path_start_point_index, from_index, curv_path, stroke_offset);
//put it back
if (curv_path.pathPoints.length > 0) {
echo('creating new curv_path');
curv_path = create_empty_curv_path(test_group, true);
curv_path.name = 'from ' + j + ' path';
}
curv_path_start_point_index = j + 1;
curv_dots.push([P0[0], P0[1]], [P3[0], P3[1]]);
continue;
}
/*
there are four points:
P0 [x,y] — start point
P1 [x,y] - handle extending from it
P2 [x,y] – handle extending from second point
P3 [x,y] - second point
B = (1-t)***3 * P0 + 3*t*(1-t)**2 * P1 + 3*t*t*(1-t) * P2 + t***3 * P3;
t - in length from 0 to 1
*/
var steps = 50;
for (var i = 0; i <= steps; i++) {
// echo(' ');
t = i / steps; //from 0 to 1
bx = coord_from_t(P0[0], P1[0], P2[0], P3[0], t);
by = coord_from_t(P0[1], P1[1], P2[1], P3[1], t);
dots.push([bx, by]);
var evolute_d = evolute(P0[0], P1[0], P2[0], P3[0], P0[1], P1[1], P2[1], P3[1], t, current_sector_length, opath.length, stroke_offset, opath);
if (evolute_d != undefined) {
evo_dots.push(evolute_d[0]);
curv_dots.push(evolute_d[1]);
curv_graph_dots.push(evolute_d[2]);
var pp = curv_path.pathPoints.add();
pp.anchor = evolute_d[1];
pp.leftDirection = pp.anchor;
pp.rightDirection = pp.anchor;
// echo('adding point to curv_path '+evolute_d[1][0]+' '+evolute_d[1][1]);
}
}
}
echo('draw paths');
path_for_length_measuring.remove();
reverse_points_adding(opath, curv_path_start_point_index, j, curv_path, stroke_offset);
// echo('so length of curv_path is '+);
if (curv_path.pathPoints.length == 0) {
echo('path is empty, delete');
curv_path.remove();
}
if (curv_dots.length > 0) {
} else {
echo('SORRY, NO POINTS – NO CURV PATH');
}
}
function create_empty_curv_path(where, clsed) {
var newPath;
if (where) {
newPath = where.pathItems.add();
} else {
newPath = tmp_layer.pathItems.add();
}
newPath.name = 'curiate';
newPath.filled = true;
newPath.stroked = false;
newPath.fillColor = curviture_color;
newPath.closed = clsed;
return newPath;
}
function copy_point_to_path(p1, to) {
var pp1 = to.pathPoints.add();
pp1.anchor = p1.anchor;
pp1.leftDirection = p1.leftDirection;
pp1.rightDirection = p1.rightDirection;
}
function reverse_points_adding(path_from, point_from_i, point_to_i, path_to, stroke_offset) {
echo('[reverse_points_adding] from ' + point_from_i + ' to ' + point_to_i + ' in path with length ' + path_from.pathPoints.length);
var donor;
var pp;
if (point_from_i == point_to_i) {
echo('same point. ignore');
// return ;
} else if (point_to_i == path_from.pathPoints.length) { //ending at the first point (end of the cycle)
echo('case 1 (closed to the end)');
donor = path_from.pathPoints[0];
echo('>adding point ' + 0);
pp = path_to.pathPoints.add();
pp.anchor = donor.anchor;
pp.leftDirection = donor.anchor;
pp.rightDirection = donor.leftDirection;
for (var i = path_from.pathPoints.length - 1; i >= point_from_i; i--) {
echo('>adding point ' + i);
donor = path_from.pathPoints[i];
pp = path_to.pathPoints.add();
pp.anchor = donor.anchor;
pp.leftDirection = donor.rightDirection;
pp.rightDirection = donor.leftDirection;
// echo('adding point to curv_path '+evolute_d[1][0]+' '+evolute_d[1][1]);
if (i == point_from_i) {
pp.rightDirection = donor.anchor;
}
}
/*
echo('case 3');
var donor = path_from.pathPoints[point_to_i];
echo('>adding point '+point_to_i);
var pp = path_to.pathPoints.add();
pp.anchor = donor.anchor;
pp.leftDirection = donor.anchor;
pp.rightDirection = donor.leftDirection;