Documentation
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396


use std::ops::Range;

/**

 * 矩形切圆角矩形
 * * input:
 *      x, y, w, h: 矩形参数
 *      radius:     圆角半径
 *      z:          z 定位数据
 *      segment:    切分粒度
 * * output:
 *      points:     点坐标数据流
 *      indices     多边形点序号数据流
 */
// pub fn split_by_radius(x: f32, y: f32, w: f32, h: f32, radius: f32, z: f32, segment: Option<usize>) -> (Vec<f32>, Vec<u16>) {
pub fn split_by_radius(x: f32, y: f32, w: f32, h: f32, radius: f32, segment: Option<usize>) -> (Vec<f32>, Vec<u16>) {
    let points:  Vec<f32>;
    let mut indices: Vec<u16> = Vec::new();

    let point_len: usize = 2;

    match segment {
        Some(lv) => {
            // points = split_by_radius_with_level(x, y, w, h, radius, z, scale_level(lv as u16));
            points = split_by_radius_with_level(x, y, w, h, radius, scale_level(lv as u16));
        },
        None    => {
            // points = split_by_radius_0(x, y, w, h, radius, z);
            points = split_by_radius_0(x, y, w, h, radius);
        },
    }

    let mut index = 0;
    let count = points.len() / point_len;
    while index < count {
        indices.push(index as u16);
        index = index + 1;
    }

    (points, indices)
}
/**

 * 矩形切圆角矩形 - 带 边框 
 * * input:
 *      x, y, w, h: 矩形参数
 *      radius:     圆角半径
 *      border:     边框尺寸
 *      z:          z 定位数据
 *      segment:    切分粒度
 * * output:
 *      points:     点坐标数据流
 *      indices     多边形点序号数据流
 */
// pub fn split_by_radius_border(x: f32, y: f32, w: f32, h: f32, radius: f32, border: f32, z: f32, segment: Option<usize>) -> (Vec<f32>, Vec<u16>) {
pub fn split_by_radius_border(x: f32, y: f32, w: f32, h: f32, radius: f32, border: f32, segment: Option<usize>) -> (Vec<f32>, Vec<u16>) {
    match segment {
        Some(lv) => {
            // split_by_radius_border_with_level(x, y, w, h, radius, border, z, scale_level(lv as u16))
            split_by_radius_border_with_level(x, y, w, h, radius, border, scale_level(lv as u16))
        },
        None    => {
            // split_by_radius_border_0(x, y, w, h, radius, border, z)
            split_by_radius_border_0(x, y, w, h, radius, border)
        },
    }
}
/**

 * 根据指定切割线列表,切割出多个多边形
 * input:
 *      positions:  初始点列表
 *      indices:    初始多边形点序号列表
 *      lg_pos:     切割线在切割域内位置
 *      start:      切割域起点
 *      end:        切割域终点
 * output: 
 *      points:     结果点列表
 *      indices:    [结果多边形点序号列表]
 */
pub fn split_by_lg(result: &mut PolygonIndices, positions: &mut Vec<f32>,  attrs: &mut [Attribute], indices: &[u16], lg_pos: &[f32], start: (f32, f32), end: (f32, f32)) -> PolygonSlice {
    let index_start = result.indices.len();
    let count_start = result.counts.len();
    split_by_lg_0(result, positions, attrs, indices, lg_pos, start, end);
    PolygonSlice {
        start: index_start,
        range: count_start..result.counts.len(),
    }
}

/**

 * 根据指定切割线列表,切割出多个多边形
 * input:
 *      positions:  [初始点列表]
 *      indices:    [初始多边形点序号列表]
 *      lg_pos:     切割线在切割域内位置
 *      start:      切割域起点
 *      end:        切割域终点
 * output: 
 *      points:     结果点列表
 *      indices:    [结果多边形点序号列表]
 */
pub fn split_mult_by_lg(result: &mut PolygonIndices, positions: &mut Vec<f32>, attrs: &mut [Attribute], indices: &PolygonIndices, indices_slice: PolygonSlice, lg_pos: &[f32], start: (f32, f32), end: (f32, f32)) {
    let a: &[usize] = &indices.counts[indices_slice.range];
    let mut index_start = indices_slice.start;
    for i in a.iter() {
        split_by_lg(result, positions, attrs, &indices.indices[index_start..index_start + *i], lg_pos, start, end);
        index_start += *i;
    }
}
/**

 * 沿指定方向对指定属性列表做指定点的插值
 * input:
 *      positions   点列表
 *      indices
 *      attrs
 *      lg_attrs
 *      lg_pos
 *      start
 *      end
 * output:
 *      attrs
 */
pub fn interp_by_lg(positions: &[f32], indices: &[u16], attrs: &mut [&mut Vec<f32>], lg_attrs: &Vec<LgCfg>, lg_pos: &[f32], start: (f32, f32), end: (f32, f32)) {
    interp_by_lg_0(positions, indices, attrs, lg_attrs, lg_pos, start, end);
}

pub fn interp_mult_by_lg(positions: &[f32], indices: &PolygonIndices, indices_slice: PolygonSlice, attrs:  &mut [&mut Vec<f32>], lg_attrs: Vec<LgCfg>, lg_pos: &[f32], start: (f32, f32), end: (f32, f32)) {
    let a: &[usize] = &indices.counts[indices_slice.range];
    let mut index_start = indices_slice.start;
    for i in a.iter() {
        interp_by_lg(positions, &indices.indices[index_start..index_start + *i], attrs, &lg_attrs, lg_pos, start, end);
        index_start += *i;
    }
}

pub fn to_triangle(indices: &[u16], out_indices: &mut Vec<u16>) {
    to_triangle_0(indices, out_indices)
}

pub fn mult_to_triangle(indices: &PolygonIndices, out_indices: &mut Vec<u16>){
    let a: &[usize] = &indices.counts;
    let mut index_start = 0;
    for i in a.iter() {
        to_triangle(&indices.indices[index_start..index_start + *i], out_indices);
        index_start += *i;
    }
}

/**

 * 作角度为angle(单位: 角度)的直线, 计算其与一个凸多边形的交点, 如果只有一个交点, 返回两个相同的点
 * polygon 2 维点
 */
pub fn find_lg_endp(polygon: &[f32], angle: f32) -> ((f32, f32), (f32, f32)) {

    let direct_vec2 = get_direction_vector(angle);
    let mut point_dot: Vec<f32> = Vec::new();

    let point_len: usize = 2;
    let count = polygon.len() / point_len;

    let mut index: usize = 0;
    let mut min_dot = std::f32::MAX;
    let mut max_dot = std::f32::MIN;
    let mut min_index = 0;
    while index < count {
        let x = polygon[index * point_len];
        let y = polygon[index * point_len + 1];
        let dot = get_dot(x, y, direct_vec2[0], direct_vec2[1]);

        if dot < min_dot {
            min_dot     = dot;
            min_index   = index;
        }
        
        if max_dot < dot {
            max_dot = dot;
        }

        point_dot.push(dot);

        index = index + 1;
    }

    let total_dot   = max_dot - min_dot;
    // let ex_size_x   = direct_vec2[0] * 0.0001;
    // let ex_size_y   = direct_vec2[1] * 0.0001;
    // let start_point = (polygon[min_index * 2] - ex_size_x, polygon[min_index * 2 + 1]- ex_size_y);
    // let end_point   = (start_point.0 + total_dot * direct_vec2[0] + ex_size_x, start_point.1 + total_dot * direct_vec2[1] + ex_size_y);
    
    let start_point = (float_clip(polygon[min_index * 2]) , float_clip(polygon[min_index * 2 + 1]));
    let end_point   = (float_clip(start_point.0 + total_dot * direct_vec2[0]) , float_clip(start_point.1 + total_dot * direct_vec2[1]));

    (start_point, end_point)
}

/**

 * 处理带border 的圆角矩形
 * input:
 *      x, y: 左上
 *      w, h:矩形大小
 *      radius: 圆角半径
 *      z:
 *      level: 细分级别 4 / 8 / 16
 * output:
 *      (三维点数据, 多边形点索引)
 */
// pub fn split_by_radius_border_with_level(x: f32, y: f32, w: f32, h: f32, radius: f32, border: f32, z: f32, level: u16) -> (Vec<f32>, Vec<u16>) {
pub fn split_by_radius_border_with_level(x: f32, y: f32, w: f32, h: f32, radius: f32, border: f32, level: u16) -> (Vec<f32>, Vec<u16>) {
    let mut result: Vec<f32> = Vec::new();
    let mut result2: Vec<f32> = Vec::new();
    let mut result_indices: Vec<u16> = Vec::new();
    let mut check_list: Vec<(f32,f32,u8)> = Vec::new();
    check_list.push((x + radius,        y - radius,     2));
    check_list.push((x + radius,        y - h + radius, 3));
    check_list.push((x + w - radius,    y - h + radius, 4));
    check_list.push((x + w - radius,    y - radius,     1));

    // let point_len: usize = 3;
    let point_len: usize = 2;
    for data in check_list {

        let (_x,_y,a) = data;
        // let res     = get_one_quarter_arc_with_level(_x, _y, radius, a, z, level);
        let res     = get_one_quarter_arc_with_level(_x, _y, radius, a, level);
        let mut index = 0;
        for v in res {
            if index % point_len == 1 {
                result.push(y + y - v);
            } else {
                result.push(v);
            }

            index = index + 1;
        }
        
        // let res     = get_one_quarter_arc_with_level(_x, _y, radius - border, a, z, level);
        let res     = get_one_quarter_arc_with_level(_x, _y, radius - border, a, level);
        index = 0;
        for v in res {
            if index % point_len == 1 {
                result2.push(y + y - v);
            } else {
                result2.push(v);
            }
            
            index = index + 1;
        }
    }

    let count = result.len() / point_len;
    
    let mut temp_index: usize = 0;
    while temp_index < count - 1 {
        let mut indices = Vec::new();
        to_triangle_0(&[
            (temp_index) as u16,
            (temp_index + 1) as u16,
            (count + temp_index + 1) as u16,
            (count + temp_index) as u16
        ], &mut indices);

        result_indices.extend_from_slice(&indices);

        temp_index = temp_index + 1;
    }
    
    let mut indices = Vec::new();
    to_triangle_0(&[
        (count - 1) as u16,
        (0) as u16,
        (count + 0) as u16,
        (count + count - 1) as u16
    ], &mut indices);
    result_indices.extend_from_slice(&indices);

    result.extend_from_slice(&result2);
    (result, result_indices)
}

/**

 * 处理带border 的圆角矩形
 * input:
 *      x, y: 左上
 *      w, h:矩形大小
 *      radius: 圆角半径
 *      z:
 * output:
 *      (三维点数据, 多边形点索引)
 */
// pub fn split_by_radius_border_0(x: f32, y: f32, w: f32, h: f32, radius: f32, border: f32, z: f32) -> (Vec<f32>, Vec<u16>) {
pub fn split_by_radius_border_0(x: f32, y: f32, w: f32, h: f32, radius: f32, border: f32) -> (Vec<f32>, Vec<u16>) {
    let mut result: Vec<f32> = Vec::new();
    let mut result2: Vec<f32> = Vec::new();
    let mut result_indices: Vec<u16> = Vec::new();
    let mut check_list: Vec<(f32,f32,u8)> = Vec::new();
    check_list.push((x + radius,        y - radius,     2));
    check_list.push((x + radius,        y - h + radius, 3));
    check_list.push((x + w - radius,    y - h + radius, 4));
    check_list.push((x + w - radius,    y - radius,     1));

    // let point_len: usize = 3;
    let point_len: usize = 2;
    for data in check_list {

        let (_x,_y,a) = data;
        // let res     = get_one_quarter_arc(_x, _y, radius, a, z);
        let res     = get_one_quarter_arc(_x, _y, radius, a);
        let level   = res.len() / point_len - 1;
        let mut index = 0;
        for v in res {
            if index % point_len == 1 {
                result.push(y + y - v);
            } else {
                result.push(v);
            }

            index = index + 1;
        }
        
        // let res = get_one_quarter_arc_with_level(_x, _y, radius - border, a, z, level as u16);
        let res = get_one_quarter_arc_with_level(_x, _y, radius - border, a, level as u16);
        index = 0;
        for v in res {
            if index % point_len == 1 {
                result2.push(y + y - v);
            } else {
                result2.push(v);
            }
            
            index = index + 1;
        }
    }

    let count = result.len() / point_len;
    
    let mut temp_index: usize = 0;
    while temp_index < count - 1 {
        let mut indices: Vec<u16> = Vec::new();
        to_triangle_0(&[
            (temp_index) as u16,
            (temp_index + 1) as u16,
            (count + temp_index + 1) as u16,
            (count + temp_index) as u16
        ], &mut indices);

        result_indices.extend_from_slice(&indices);

        temp_index = temp_index + 1;
    }
    
    let mut indices: Vec<u16> = Vec::new();
    to_triangle_0(&[
        (count - 1) as u16,
        (0) as u16,
        (count + 0) as u16,
        (count + count - 1) as u16
    ], &mut indices);
    result_indices.extend_from_slice(&indices);

    result.extend_from_slice(&result2);
    (result, result_indices)
}

/**

 * 将一个矩形转化为圆角矩形, 返回多边形的顶点流, 顶点为三维顶点
 * 多边形方向:逆时针
 */
// pub fn split_by_radius_0(x: f32, y: f32, w: f32, h: f32, radius: f32, z: f32) -> Vec<f32> {
pub fn split_by_radius_0(x: f32, y: f32, w: f32, h: f32, radius: f32) -> Point2DVec {
    // get_rounded_rect(x, y, w, h, radius, z)
    get_rounded_rect(x, y, w, h, radius)
}

/**

 * 将一个矩形转化为圆角矩形, 返回多边形的顶点流, 顶点为三维顶点
 * 多边形方向:逆时针
 */
// pub fn split_by_radius_with_level(x: f32, y: f32, w: f32, h: f32, radius: f32, z: f32, level: u16) -> Vec<f32> {
pub fn split_by_radius_with_level(x: f32, y: f32, w: f32, h: f32, radius: f32, level: u16) -> Point2DVec {
    // get_rounded_rect_with_level(x, y, w, h, radius, z, level)
    get_rounded_rect_with_level(x, y, w, h, radius, level)
}

// pub type PolygonCfg = (Vec<f32>, Vec<Vec<u16>>);
/**

 * (x, y, z)
 */
pub type Point3D = (f32, f32, f32);
/**

 * (x, y) 
 */
pub type Point2D = (f32, f32);

#[derive(Debug, Default, Clone)]
pub struct PolygonIndices {
    pub indices: Vec<u16>,
    pub counts: Vec<usize>, // indices中各多边形的顶点数量 如果 counts为vec![4, 5], 则indices长度为4 + 5 = 9, 依次为一个四边形, 一个五边形
}

impl PolygonIndices {
    pub fn clear(&mut self) {
        self.indices.clear();
        self.counts.clear();
    }
}

#[derive(Debug, Default, Clone)]
pub struct PolygonSlice {
    pub start: usize,
    pub range: Range<usize>,
}


pub struct PolygonCfg {
    pub positions: Vec<f32>,
    pub indices: PolygonIndices,
}

#[derive(Debug)]
pub struct Attribute<'a> {
    pub unit: usize,
    pub value: &'a mut Vec<f32>,
}

/**

 * 将一个多边形按照指示方向的多个空间线切分, 返回新的多边形
 * input:
 *      result: 新的多边形放入result中
 *      points: 初始点数据集 - 三维数据
 *      polygon_indices: 初始多边形点索引列表
 *      lg_pos: 分割百分比列表
 *      start: 分割方向的起点
 *      end: 分割方向的终点
 */
pub fn split_by_lg_0(
    result: &mut PolygonIndices,
    points: &mut Vec<f32>, 
    attrs: &mut [Attribute],
    polygon_indices: &[u16], 
    lg_pos: &[f32], 
    start: (f32, f32), 
    end: (f32, f32)
) {
    let _end    =  (end.0, -end.1);
    let _start  =  (start.0, -start.1);
    let dist_x  = _end.0 - _start.0;
    let dist_y  = _end.1 - _start.1;
    let dist    = (dist_x.powi(2) + dist_y.powi(2)).sqrt();
    // let z: f32  = points[2];
    let lg_lines: Vec<LineCfg> = line_segment_vertical_lines(&_start, &_end, lg_pos);

    // let pointe_len: usize       = 3;
    let pointe_len: usize       = 2;

    let src_points_count        = points.len() / pointe_len;
    let src_polygon_point_count = polygon_indices.len();
    let src_lg_count            = lg_pos.len();
    let mut new_indices_list: Vec<u16>  = Vec::new();
    let mut new_dot_list: Vec<f32>      = Vec::new();

    // 方向上单位向量
    let direct_vec2 = [(_end.0 - _start.0) / dist , (_end.1 - _start.1) / dist];

    let mut lg_dot: Vec<f32> = Vec::new();
    for percent in lg_pos {
        lg_dot.push(get_dot(direct_vec2[0], direct_vec2[1], direct_vec2[0] * dist * percent, direct_vec2[1] * dist * percent));
        // lg_dot.push(dist * percent);
    }

    // 多边形各点在方向上的点积
    // let mut point0: Point3D;
    // let mut point1: Point3D;
    let mut point0: Point2D;
    let mut point1: Point2D;
    let mut line0: LineCfg;
    // println!("lg_lines: {:?}", lg_lines);

    // point0 = read_point_3d_f(&points, polygon_indices, src_polygon_point_count - 1);
    point0 = read_point_2d_f(&points, polygon_indices, src_polygon_point_count - 1);
    // println!("==================\n {:?}", points);

    let temp_dot = get_dot(direct_vec2[0], direct_vec2[1], point0.0 - _start.0, point0.1 - _start.1);
    new_indices_list.push(polygon_indices[src_polygon_point_count - 1]);
    new_dot_list.push(temp_dot);

    let mut result_count: u16 = src_points_count as u16;


    let mut index0 = src_polygon_point_count - 1;
    let mut index1 = 0; 
    while index1 < src_polygon_point_count {

        // point1  = read_point_3d_f(&points, polygon_indices, index);
        point1  = read_point_2d_f(&points, polygon_indices, index1);

        // println!("===========================边与界限求交点");

        if !(eq_f32(point0.0, point1.0) && eq_f32(point0.1, point1.1)) {
            line0   = get_line_with_two_point(point0.0, point0.1, point1.0, point1.1);

            // println!("===========================获得边");
            // println!("{:?}", point1);
            // log::warn!("get_dot p0: {:?} ---- p1: {:?}, dot: {:?}", point0, point1, get_dot(direct_vec2[0], direct_vec2[1], point1.0 - point0.0, point1.1 - point0.1));
            if get_dot(direct_vec2[0], direct_vec2[1], point1.0 - point0.0, point1.1 - point0.1) > 0.0 {

                // println!("===========================获得边 - dot > 0.0");

                let l_count = lg_lines.len();
                let mut l_index: usize = 0;

                while l_index < l_count {
                    
                    // println!("===========================获得边 与 界限交点");

                    let (is_get, _x, _y) = get_two_lines_intersection(line0, lg_lines[l_index]);
                    let has_intersect = is_get && is_between_2d(&point0, &point1, &(_x, _y));
                    
                    // println!("交点: x: {:?} --- y: {:?}", _x, _y);
                    if has_intersect {
                        // println!("满足条件05");

                        result_count = result_count + 1;
                        // points.extend_from_slice(&[_x, -_y, z]);
                        points.extend_from_slice(&[_x, -_y]);

                        new_indices_list.push((result_count - 1) as u16);
                        new_dot_list.push(lg_dot[l_index]);
                        // log::warn!("新增2: x: {:?} ---- y: {:?}, pos_index: {:?}", _x, _y, points.len());
                        interp_attrs_by_line(attrs, polygon_indices, index0, index1, (_x, _y), point0, point1);
                    }
                    
                    l_index = l_index + 1;
                }
            } else {

                // println!("===========================获得边 - dot <= 0.0");

                let l_count = lg_lines.len();
                let mut l_index: usize = 0;

                while l_index < l_count {
                    // println!("===========================获得边 与 界限交点");

                    let (is_get, _x, _y) = get_two_lines_intersection(line0, lg_lines[l_count - l_index - 1]);

                    let has_intersect = is_get && is_between_2d(&point0, &point1, &(_x, _y));
                    
                    // println!("交点: x: {:?} --- y: {:?}", _x, _y);

                    if has_intersect {
                        result_count = result_count + 1;
                        // points.extend_from_slice(&[_x, -_y, z]);
                        points.extend_from_slice(&[_x, -_y]);
                        
                        new_indices_list.push((result_count - 1) as u16);
                        new_dot_list.push(lg_dot[l_count - l_index - 1]);

                        // log::warn!("新增1: x: {:?} ---- y: {:?}, pos_index: {:?}", _x, _y, points.len() - 1);
                        interp_attrs_by_line(attrs, polygon_indices, index0, index1, (_x, _y), point0, point1);
                    }

                    l_index = l_index + 1;
                }
            }
        }


        if index1 < src_polygon_point_count - 1 {
            let temp_dot = get_dot(direct_vec2[0], direct_vec2[1], point1.0 - _start.0, point1.1 - _start.1);
            new_indices_list.push(polygon_indices[index1]);
            new_dot_list.push(temp_dot);
        }

        point0 = point1;

        index0 = index1;
        index1 = index1 + 1;
    }

    // let mut new_polygon_indices_list: Vec<Vec<u16>> = Vec::new();
    let mut min_dot: f32;
    let mut max_dot: f32;

    let new_point_count = new_indices_list.len();
    
    index1   = 0;
    min_dot = lg_dot[index1];

    let mut i_index = 0;
    let new_polygon_start = result.indices.len();
    while i_index < new_point_count {
        if new_dot_list[i_index] <= min_dot {
            result.indices.push(new_indices_list[i_index]);
        }

        i_index = i_index + 1;
    }
    let count = result.indices.len() - new_polygon_start;
    if count > 2 {
        result.counts.push(count);
    } else {
        unsafe { result.indices.set_len(new_polygon_start) } // 
    }

    index1 = 0;
    while index1 < src_lg_count - 1 {
        min_dot = lg_dot[index1];
        max_dot = lg_dot[index1 + 1];

        i_index = 0;
        let new_polygon_start = result.indices.len();
        while i_index < new_point_count {
            if min_dot <= new_dot_list[i_index] && new_dot_list[i_index] <= max_dot {
                result.indices.push(new_indices_list[i_index]);
            }

            i_index = i_index + 1;
        }
        let count = result.indices.len() - new_polygon_start;
        if count > 2 {
            result.counts.push(count);
        } else {
            unsafe { result.indices.set_len(new_polygon_start) } // 
        }

        index1 = index1 + 1;
    }
    
    index1   = src_lg_count - 1;
    max_dot = lg_dot[index1];

    let new_polygon_start = result.indices.len();
    i_index = 0;
    while i_index < new_point_count {
        if max_dot <= new_dot_list[i_index] {
            result.indices.push(new_indices_list[i_index]);
        }

        i_index = i_index + 1;
    }
    let count = result.indices.len() - new_polygon_start;
    if count > 2 {
        result.counts.push(count);
    } else {
        unsafe { result.indices.set_len(new_polygon_start) } // 
    }

    // println!("split_by_lg_0: {:?}\n", points);
    // println!("split_by_lg_0: {:?}\n", new_polygon_indices_list);
}

// point0 != point1;
fn interp_attrs_by_line (
    attrs: &mut [Attribute],
    indices: &[u16],
    p0_index: usize,
    p1_index: usize,
    target: (f32, f32), 
    point0: (f32, f32), 
    point1: (f32, f32),
) {
    if attrs.len() == 0 {
        return;
    }

    let delta = point1.0 - point0.0;
    let p0_weight = if delta.abs() < f32::EPSILON {
        (target.1 - point0.1) / (point1.1 - point0.1)
    } else {
        (target.0 - point0.0) / (point1.0 - point0.0)
    };
    let p1_weight = 1.0 - p0_weight;

    for attr in attrs.iter_mut() {
        let index0 = indices[p0_index] as usize * attr.unit;
        let index1 = indices[p1_index] as usize * attr.unit;
        for i in 0..attr.unit {
            let r = p1_weight * attr.value[index0 + i] + p0_weight * attr.value[index1 + i];
            // log::warn!("interp_attrs_by_line======{:?}", (index0, index1, r, &target, &point0, &point1, p0_weight, attr.value[index0 + i], attr.value[index1 + i]));
            attr.value.push(r);
        }
    }
}

const EPSILON: f32 = std::f32::EPSILON * 1024.0;
#[inline]
pub fn eq_f32(v1: f32, v2: f32) -> bool { v1 == v2 || ((v2 - v1).abs() <= EPSILON) }

// fn read_point_3d_f(points: &[f32], indices: &[u16], indices_index: usize) -> Point3D {
//     let ix = (indices[indices_index] * 3) as usize;
//     (points[ix + 0], -points[ix + 1], points[ix + 2])
// }

fn read_point_2d_f(points: &[f32], indices: &[u16], indices_index: usize) -> Point2D {
    let ix = (indices[indices_index] * 2) as usize;
    (points[ix + 0], -points[ix + 1])
}

// fn read_point_3d(points: &[f32], indices: &[u16], indices_index: usize) -> Point3D {
//     let ix = (indices[indices_index] * 3) as usize;
//     (points[ix + 0], points[ix + 1], points[ix + 2])
// }

fn read_point_2d(points: &[f32], indices: &[u16], indices_index: usize) -> Point2D {
    let ix = (indices[indices_index] * 2) as usize;
    (points[ix + 0], points[ix + 1])
}

#[derive(Debug, Clone)]
pub struct LgCfg{
    /**

     * 该属性长度
     */
    pub unit: usize,
    pub data: Vec<f32>,
}
// 将属性流按照线性渐变插值,  返回插值后的属性流
/**

 * in:
 *      points   三维点数据
 *      attrs   多个属性的 各点属性数据集 
 *      polygon_indices   多边形顶点数据
 *      lg_attrs 多种属性值列表
 *      lg_pos   插值区间列表
 *      start    插值计算起点
 *      end    插值计算终点
 * out:
 *      points 中点的属性数据流
 */
pub fn interp_by_lg_0(points: &[f32], polygon_indices: &[u16], attrs: &mut [&mut Vec<f32>], lg_attrs: &Vec<LgCfg>, lg_pos: &[f32], start: (f32, f32), end: (f32, f32)) {
    let dist_x  = end.0 - start.0;
    let dist_y  = end.1 - start.1;
    let dist    = (dist_x.powi(2) + dist_y.powi(2)).sqrt();
    let point_count = polygon_indices.len();


    let lg_count    = lg_pos.len();

    let attr_count  = lg_attrs.len();

    // if attrs.len() == 0 {
    //     let mut index = 0;
    //     while index < attr_count {
    //         attrs.push(Vec::new());
    //         index = index + 1;
    //     }
    // }

    // 有效属性,在插值方向上的起始
    let start_lg    = lg_pos[0];
    let end_lg      = lg_pos[lg_count - 1];
    // 方向上单位向量
    let direct_vec2 = [(end.0 - start.0) / dist, (end.1 - start.1) / dist];

    // let mut point: Point3D;
    let mut point: Point2D;
    
    let mut index = 0;
    while index < point_count {
        // point   = read_point_3d(points, polygon_indices, index);
        point   = read_point_2d(points, polygon_indices, index);
        let dot     = get_dot(point.0 - start.0, point.1 - start.1, direct_vec2[0], direct_vec2[1]);

        let mut attr_index: usize = 0;
        let lg = dot / dist;
        while attr_index < attr_count {
            let src_attr = &lg_attrs[attr_index];
            let pre: usize;
            let nxt: usize;
            let percent: f32;
            if lg <= start_lg {
                percent = 0.0;
                pre = 0;
                nxt = 1;
            } else if lg >= end_lg {
                percent = 1.0;
                pre = lg_count - 2;
                nxt = lg_count - 1;
            } else {
                let (_pre, _nxt) = find_pre_next_grad_direct(lg_pos, lg);
                pre = _pre;
                nxt = _nxt;
                if pre != nxt {
                    percent = (lg - lg_pos[pre]) / (lg_pos[nxt] - lg_pos[pre]);
                } else {
                    percent = 0.0;
                }
            }


            let mut pre_attr: f32;
            let mut nxt_attr: f32;
            let attr_size = src_attr.unit;
            let point_attr_index: u16 = (attr_size as u16) * polygon_indices[index];

            // 填充属性数据直到到当前点位置
            // let mut _l = attrs[attr_index as usize];
            // _l = fill_vec(_l, point_attr_index + (attr_size as u16), 0.0);
            // attrs[attr_index] = _l;
            let mut _cur_len    = attrs[attr_index as usize].len() as u16;
            let _targ_len       = point_attr_index + (attr_size as u16);
            while _cur_len < _targ_len {
                attrs[attr_index as usize].push(0.0);
                _cur_len = _cur_len + 1;
            }

            let mut a_index = 0;
            while a_index < attr_size {
                pre_attr = src_attr.data[pre * attr_size + a_index];
                nxt_attr = src_attr.data[nxt * attr_size + a_index];

                attrs[attr_index][point_attr_index as usize + a_index] = float_clip(pre_attr + (nxt_attr - pre_attr) * percent);

                a_index = a_index + 1;
            }

            attr_index = attr_index + 1;
        }

        index = index + 1;
    }
}

// fn insert_vec(mut data_list: Vec<f32>, data: &[f32], size: u16, index: u16) -> Vec<f32> {
//     let trag_len = size * (index + 1);
//     let mut curr_len = data_list.len() as u16;
//     while curr_len < trag_len {
//         data_list.push(0.0);

//         curr_len = curr_len + 1;
//     }

//     let i_index = size * (index as u16);
//     let mut i: u16 = 0;
//     while i < size {
//         data_list[(i_index + i) as usize] = data[i as usize];

//         i = i + 1;
//     }

//     data_list
// }

// fn fill_vec(mut data_list: Vec<f32>, size: u16, value: f32) -> Vec<f32> {
//     let trag_len = size;
//     let mut i_index = data_list.len() as u16;

//     while i_index < trag_len {
//         data_list.push(value);
        
//         i_index = i_index + 1;
//     }

//     data_list
// }

//将多边形转换为三角形
pub fn to_triangle_0(indices: &[u16], out_indices: &mut Vec<u16>) {
    let mut index: usize = 1;
    let count = indices.len();
    while index <= count - 2 {
        out_indices.push(indices[0]);
        out_indices.push(indices[index]);
        out_indices.push(indices[index + 1]);

        index = index + 1;
    }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////
const VEC_ARR: [f32;34] = [
    1.0, 0.0,
    0.9951847266721969, 0.0980171403295606,
    0.9807852804032304, 0.1950903220161282,
    0.9569403357322088, 0.2902846772544623,
    0.9238795325112867, 0.3826834323650898,
    0.881921264348355,  0.4713967368259976,
    0.8314696123025452, 0.5555702330196022,
    0.773010453362737,  0.6343932841636455,
    0.7071067811865476, 0.7071067811865475,
    0.6343932841636455, 0.7730104533627369,
    0.5555702330196023, 0.8314696123025452,
    0.4713967368259978, 0.8819212643483549,
    0.3826834323650898, 0.9238795325112867,
    0.2902846772544623, 0.9569403357322089,
    0.1950903220161283, 0.9807852804032304,
    0.0980171403295607, 0.9951847266721968,
    0.0, 1.0
];
const RADIUS_4_8: f32       = 32.0;
const RADIUS_8_16: f32      = 128.0;


fn copy_level4() -> Vec<u16> {
    vec![0,4,8,12,16]
}
fn copy_level8() -> Vec<u16> {
    vec![ 0,2,4,6,8,10,12,14,16 ]
}
fn copy_level16() -> Vec<u16> {
    vec![ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 ]
}
fn scale_level(mut lv: u16) -> u16 {
    if lv <= 4 {
        lv = 4;
    } else if lv <= 8 {
        lv = 8;
    } else {
        lv = 16;
    }

    lv
}
/**

 * 正方形切 4分之一圆弧
 * input 
 *      ⚪心
 *          [f32;2]
 *      弧方向向量
 *          [f32;2]
 *      半径
 *          f32
 *      角度
 *          f32
 * output
 *      点列表 * 逆时针
 *          Vec<[f32;2]>
 */
// pub fn get_one_quarter_arc(center_x: f32, center_y: f32, radius: f32, area_id: u8, z: f32) -> Vec<f32> {
pub fn get_one_quarter_arc(center_x: f32, center_y: f32, radius: f32, area_id: u8) -> Point2DVec {
    let segments: Vec<u16>;

    if radius < RADIUS_4_8 {
        segments    = copy_level4();
    } else if radius <= RADIUS_8_16 {
        segments    = copy_level8();
    } else {
        segments    = copy_level16();
    }

    // analy_one_quarter_arc(center_x, center_y, radius, area_id, z, &segments)
    analy_one_quarter_arc(center_x, center_y, radius, area_id, &segments)
}

// pub fn get_one_quarter_arc_with_level(center_x: f32, center_y: f32, radius: f32, area_id: u8, z: f32, level: u16) -> Vec<f32> {
pub fn get_one_quarter_arc_with_level(center_x: f32, center_y: f32, radius: f32, area_id: u8, level: u16) -> Point2DVec {
    let segments: Vec<u16>;

    if level == 4 {
        segments    = copy_level4();
    } else if level == 8 {
        segments    = copy_level8();
    } else {
        segments    = copy_level16();
    }

    // analy_one_quarter_arc(center_x, center_y, radius, area_id, z, &segments)
    analy_one_quarter_arc(center_x, center_y, radius, area_id, &segments)
}
/**

 * @return Vec<f32> : [x0, y0, x1 ,y1 ... ]
 */
// fn analy_one_quarter_arc(center_x: f32, center_y: f32, radius: f32, area_id: u8, z: f32, segments: &Vec<u16>) -> Vec<f32> {
fn analy_one_quarter_arc(center_x: f32, center_y: f32, radius: f32, area_id: u8, segments: &Vec<u16>) -> Point2DVec {
    
    let mut result_points: Vec<f32> = Vec::new();

    let count = segments.len() as u16;
    let mut index: u16 = 0;
    let mut _index: u16 = 0;
    while index <= count - 1 {
        let mut x: f32;
        let mut y: f32;

        if area_id == 1 {
            _index = index;
            _index = segments[index as usize] * 2;

            x = radius * VEC_ARR[(_index) as usize];
            y = radius * VEC_ARR[(_index + 1) as usize];
            x = center_x + x;
            y = center_y + y;
        } else if area_id == 2 {
            _index = index;
            _index = segments[index as usize] * 2;

            x = - radius * VEC_ARR[(_index + 1) as usize];
            y = radius * VEC_ARR[(_index) as usize];
            x = center_x + x;
            y = center_y + y;
        } else if area_id == 3 {
            _index = index;
            _index = segments[index as usize] * 2;

            x = - radius * VEC_ARR[(_index) as usize];
            y = - radius * VEC_ARR[(_index + 1) as usize];
            x = center_x + x;
            y = center_y + y;
        } else {
            _index = index;
            _index = segments[index as usize] * 2;

            x = radius * VEC_ARR[(_index + 1) as usize];
            y = - radius * VEC_ARR[(_index) as usize];
            x = center_x + x;
            y = center_y + y;
        }

        result_points.push(x);
        result_points.push(y);
        // result_points.push(z);

        index = index + 1;
    }

    result_points
}


/**

 * 矩形切 圆角
 * input 
 *      左上坐标
 *          
 *      宽高
 *          
 *      半径
 *          f32
 * output
 *      点列表 * 逆时针
 *          Vec<f32>
 */
// pub fn get_rounded_rect(x: f32, y: f32, w: f32, h: f32, radius: f32, z: f32) -> Vec<f32> {
pub fn get_rounded_rect(x: f32, y: f32, w: f32, h: f32, radius: f32) -> Point2DVec {
    let point_len: usize = 2;
    let mut result: Vec<f32> = Vec::new();
    let mut check_list: Vec<(f32,f32,u8)> = Vec::new();
    check_list.push((x + radius,        y - radius,     2));
    check_list.push((x + radius,        y - h + radius, 3));
    check_list.push((x + w - radius,    y - h + radius, 4));
    check_list.push((x + w - radius,    y - radius,     1));

    for data in check_list {
        let (_x,_y,a) = data;
        let res = get_one_quarter_arc(_x, _y, radius, a);
        let mut index = 0;
        for v in res {
            if index % point_len == 1 {
                result.push(y + y - v);
            } else {
                result.push(v);
            }

            index = index + 1;
        }
    }

    result
}

// pub fn get_rounded_rect_with_level(x: f32, y: f32, w: f32, h: f32, radius: f32, z: f32, level: u16) -> Vec<f32> {
pub fn get_rounded_rect_with_level(x: f32, y: f32, w: f32, h: f32, radius: f32, level: u16) -> Vec<f32> {
    let point_len: usize = 2;
    let mut result: Vec<f32> = Vec::new();
    let mut check_list: Vec<(f32,f32,u8)> = Vec::new();
    check_list.push((x + radius,        y - radius,     2));
    check_list.push((x + radius,        y - h + radius, 3));
    check_list.push((x + w - radius,    y - h + radius, 4));
    check_list.push((x + w - radius,    y - radius,     1));

    for data in check_list {
        let (_x,_y,a) = data;
        // let res = get_one_quarter_arc_with_level(_x, _y, radius, a, z, level);
        let res = get_one_quarter_arc_with_level(_x, _y, radius, a, level);
        // println!("{:?}", res);
        // println!("-------------------------------------");
        let mut index = 0;
        for v in res {
            if index % point_len == 1 {
                result.push(y + y - v);
            } else {
                result.push(v);
            }

            index = index + 1;
        }
    }

    result
}

///////////////////////////////////////////////////////////////////////////////////////
/**

 * input
 *      起点
 *          [x, y]
 *      终点
 *          [x, y]
 *      划分数据
 *          [percent...]
 * output
 *      lines
 *          [
 *              a, b, c
 *          ]
 */
pub type LineCfg = (f32, f32, f32);

fn line_segment_vertical_lines(start_point: &(f32, f32), end_point: &(f32, f32), percents: &[f32]) -> Vec<LineCfg> {
    let dist_x  = end_point.0 - start_point.0;
    let dist_y  = end_point.1 - start_point.1;
    let len     = (dist_x.powi(2) + dist_y.powi(2)).sqrt();
    let direct_vec2 = [ dist_x / len, dist_y / len];
    let v_vec2      = get_vertical_vec2(direct_vec2);
    
    let mut lines: Vec<LineCfg> = Vec::new();
    for percent in percents {
        let percent_len = len * percent;
        let point       = [start_point.0 + direct_vec2[0] * percent_len, start_point.1 + direct_vec2[1] * percent_len];
        let line_cfg    = get_line_with_direct(v_vec2, point[0], point[1]);
        lines.push(line_cfg);
    }

    lines
}

fn get_vertical_vec2(direct_vec2: [f32;2]) -> [f32;2] {
    [direct_vec2[1],-direct_vec2[0]]
}

fn get_line_with_direct(direct_vec2: [f32;2], x: f32, y: f32) -> (f32, f32, f32) {
    let new_x = direct_vec2[0] + x;
    let new_y = direct_vec2[1] + y;
    get_line_with_two_point(x, y, new_x, new_y)
}

fn get_line_with_two_point(x0: f32, y0: f32, x1: f32, y1: f32) -> (f32, f32, f32) {
    if eq_f32(x0, x1) && eq_f32(y0, y1) {
        (1.0, -1.0, 0.0)
    } else {
        (y0 - y1, x1 - x0, x0 * y1 - y0 * x1)
    }
}

// fn get_line_with_slop(slop: f32, x: f32, y: f32) -> (f32, f32, f32) {
//     (slop, -1.0, y - slop * x)
// }

/**

 * 求两直线交点
 * @param line1 目标直线
 * @param line2 目标直线
 */
fn get_two_lines_intersection(line1: LineCfg, line2: LineCfg) -> (bool, f32, f32) {
    let (a0, b0, c0) = line1;
    let (a1, b1, c1) = line2;

    let d = a0 * b1 - a1 * b0;
    let mut x = 0.0;
    let mut y = 0.0;
    let is_get;

    // 线平行
    if eq_f32(d, 0.0) {
        if a0 * b1 == 0.0 && a0 != a1 && b0 != b1 {
            if a0 == 0.0 {
                is_get = true;
                x = c0 / b0;
                y = c1 / a1;
            } else {
                is_get = true;
                x = c0 / a0;
                y = c1 / b1;
            }
        } else {
            is_get = false;
        }
    } else {
        is_get = true;
        x = (b0 * c1 - b1 * c0) / d;
        y = (c0 * a1 - c1 * a0) / d;
    }

    // 目标点与端点差距 极小时,可能因为 目标点所在直线斜率 问题导致判断失误
    // 忽略计算机离散数学误差后参与比较
    if x.is_nan() {
        x = 0.0;
    }
    x = float_clip(x);
    y = float_clip(y);

    (is_get, x, y)
}

fn get_dot(x0: f32, y0: f32, x1: f32, y1: f32) -> f32 {
    float_clip(x0 * x1 + y0 * y1)
}

/**

 * 包含起点,不包含终点
 * @param a 起点
 * @param b 终点
 * @param v 目标
 */
fn is_between(a: f32, b: f32, v: f32) -> bool {
    if eq_f32(a, v) || eq_f32(b, v) {
        return false;
    }

    if b < a {
        return b < v && v <= (a + 0.0);
    } else if a < b {
        return (a - 0.0) <= v && v < b;
    } else {
        return a == v;
    }
}

fn is_between_2d(point0: &(f32, f32), point1: &(f32, f32), target: &(f32, f32)) -> bool {
    if eq_f32(point0.0, point1.0) {
        // println!("满足条件01");
        if is_between(point0.1, point1.1, target.1) == true {
                return true;
        }
    } else {
        // println!("满足条件02");
        if is_between(point0.0, point1.0, target.0) == true {
            return true;
        }
    }
    return false;
}

fn find_pre_next_grad_direct(data_list: &[f32], value: f32) -> (usize, usize) {
    let count = data_list.len();
    let mut pre_index: usize = 0;
    let mut nxt_index: usize = 0;

    let mut index: usize = 0;
    while index <= (count as usize) - 1 {
        if data_list[(index) as usize] <= value {
            pre_index = index;
        } else {
            nxt_index = index;
            break;
        }

        nxt_index = index;

        index = index + 1;
    }

    if pre_index == nxt_index {
        pre_index = nxt_index - 1;
    }

    (pre_index, nxt_index)
}

/**

 * 获得指定方向的 单位方向向量
 */
fn get_direction_vector(angle: f32) -> [f32; 2] {

    let _angle   = angle % 360.0;

    let radius  = ((_angle as f32) / 180.0) * std::f32::consts::PI;

    [radius.cos(), radius.sin()]
}

fn float_clip(v: f32) -> f32 {
    (v * 10000.0).round() / 10000.0
}

type Point2DVec = Vec<f32>;

#[test]
fn test() {
    // let pos_list = vec![
    //     0.0, 0.0,
    //     0.5, 0.0,
    //     0.5, 0.5,
    //     0.0, 0.5
    // ];
    // let uv_list = vec![];
    // let grad_list = vec![
    //     grad_analy::GradCfg {
    //         percent: 0.0, r: 1.0, g: 0.0,   b: 0.0,   a: 1.0
    //     },
    //     grad_analy::GradCfg {
    //         percent: 0.25, r: 1.0, g: 1.0,   b: 0.0,   a: 1.0
    //     },
    //     grad_analy::GradCfg {
    //         percent: 0.5, r: 1.0, g: 0.0,   b: 1.0,   a: 1.0
    //     },
    //     grad_analy::GradCfg {
    //         percent: 0.75, r: 1.0, g: 1.0,   b: 1.0,   a: 1.0
    //     },
    //     grad_analy::GradCfg {
    //         percent: 1.0, r: 1.0, g: 0.0,   b: 0.0,   a: 1.0
    //     }
    // ];
    // let rect = vec![0.0, 0.0, 0.0, 100.0, 100.0, 100.0, 100.0, 0.0];
    
    // let (points, indices) = split_by_radius(0.0, 0.0, 30.0, 30.0, 15.0, 0.1, Some(8));
    // println!("{:?}", points);
    // println!("=======================");
    // println!("{:?}", indices);
    // println!("=======================");

    // let points = vec![0.0, 0.0, 1.0, 0.0, 100.0, 1.0,  100.0, 100.0, 1.0, 100.0, 0.0, 1.0];
    // let (p1, p2) = find_lg_endp(&points, 270.0);
    // println!("{:?}", p1);
    // println!("=======================1");
    // println!("{:?}", p2);
    // println!("=======================2");

    // grad_analy::grad_analy(pos_list, uv_list, grad_list, 50);
    // grad_analy::polygon_grad_analy(pos_list, uv_list, grad_list, 45.0, 1.0);

    // let _sdl = sdl2::init().unwrap();

    // let res = find_lg_endp(&[0.0, 0.0, 0.0, 700.0, 1000.0, 700.0, 1000.0, 0.0], 30.0);
    // println!("{:?}", res);

    // let res = split_by_lg(
    //     vec![0.0, 0.0, -0.1, 0.0, 100.0, -0.1, 100.0, 100.0, -0.1, 100.0, 0.0, -0.1], 
    //     vec![0,1,2,3],
    //     &vec![0.5], 
    //     (0.0,0.0), 
    //     (100.0, 100.0)
    // );
    // println!("{:?}", res);

    // let p1 = (-0.8648649, 3.4594595);
    // let p2 = (33.547604, 23.327509);

    // let points = vec![-0.8648649, 3.4594595, 1.1, -0.8648649, 32.0, 1.1, 28.54054, 32.0, 1.1, 28.54054, 3.4594595, 1.1];
    // let indices = vec![0,1,2,3];
    
    // let (points0, indices0) = split_by_lg(
    //     points, 
    //     indices,
    //     &vec![0.0, 1.0], 
    //     p1, 
    //     p2
    // );
    // println!("{:?}", points0);
    // println!("=======================000");
    // println!("{:?}", indices0);
    // println!("=======================00");
    
    // let attrs = vec![];
    // let res = interp_mult_by_lg(
    //     &points0,
    //     &indices0,
    //     attrs, 
    //     vec![ LgCfg { unit: 1, data: vec![0.0, 0.5, 1.0] }], 
    //     &vec![0.0, 0.5, 1.0],
    //     (0.00, 0.00), 
    //     (100.0, 100.0)
    // );
    // println!("{:?}", res);
    // println!("=======================0");

    // let attrs = res;
    // let res = interp_by_lg(
    //     &points0,
    //     &indices0[1],
    //     attrs, 
    //     &vec![ LgCfg { unit: 1, data: vec![0.0, 0.5, 1.0] }], 
    //     &vec![0.0, 0.5, 1.0],
    //     (0.00, 0.00), 
    //     (100.0, 100.0)
    // );
    // println!("{:?}", res);

    // println!("{:?}", res);
    //     let res = interp_by_lg(
    //     &points0,
    //     &indices0[0],
    //     vec![vec![0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0],vec![100.0, 100.0, 136.60254, 136.60254, 200.0, 200.0, 163.39746, 163.39746]], 
    //     &vec![ LgCfg { unit: 2, data: vec![0.0, 1.0, 0.0, 1.0] }, LgCfg { unit: 2, data: vec![100.0, 100.0, 200.0, 200.0] }], 
    //     &vec![0.0, 1.0],
    //     (0.00, 0.00), 
    //     (118.30127, 68.30127)
    // );
    // println!("{:?}", res);

    let res = split_by_radius(0.0,0.0,50.0,50.0,5.0,Some(3));
    println!("{:?}", res);

    // let res = tool::polygon_tool::straight_line_cut_polygon();
    // println!("{:?}", res);
}