This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
/
monotone.c
executable file
·4446 lines (4121 loc) · 185 KB
/
monotone.c
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
/*!The Graphic Box Library
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright (C) 2009 - 2017, TBOOX Open Source Group.
*
* @author ruki
* @file monotone.c
* @ingroup utils
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
#define TB_TRACE_MODULE_NAME "monotone"
#define TB_TRACE_MODULE_DEBUG (1)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
*/
#include "monotone.h"
#include "geometry.h"
#include "event_queue.h"
#include "active_region.h"
#ifdef __gb_debug__
# include "profiler.h"
#endif
/* //////////////////////////////////////////////////////////////////////////////////////
* macros
*/
// enable profiler for debug?
#ifdef __gb_debug__
# define GB_TESSELLATOR_PROFILER_ENABLE
#endif
/* //////////////////////////////////////////////////////////////////////////////////////
* declaration
*/
static tb_void_t gb_tessellator_sweep_event(gb_tessellator_impl_t* impl, gb_mesh_vertex_ref_t event);
static gb_tessellator_active_region_ref_t gb_tessellator_find_left_top_region(gb_tessellator_impl_t* impl, gb_tessellator_active_region_ref_t region);
static gb_tessellator_active_region_ref_t gb_tessellator_find_left_bottom_region(gb_tessellator_impl_t* impl, gb_tessellator_active_region_ref_t region);
static tb_void_t gb_tessellator_insert_down_going_edges(gb_tessellator_impl_t* impl, gb_tessellator_active_region_ref_t region_left, gb_mesh_edge_ref_t edge_head, gb_mesh_edge_ref_t edge_tail, gb_mesh_edge_ref_t edge_left_top, tb_bool_t fix_dirty_regions);
static gb_mesh_edge_ref_t gb_tessellator_finish_top_regions(gb_tessellator_impl_t* impl, gb_tessellator_active_region_ref_t region_head, gb_tessellator_active_region_ref_t region_tail);
/* //////////////////////////////////////////////////////////////////////////////////////
* private implementation
*/
static __tb_inline__ tb_uint8_t gb_tessellator_winding_is_inside(gb_tessellator_impl_t* impl, tb_int32_t winding)
{
// done
switch (impl->rule)
{
case GB_TESSELLATOR_RULE_ODD: return (winding & 1);
case GB_TESSELLATOR_RULE_NONZERO: return (winding != 0);
default: break;
}
// error
tb_assert(0);
return 0;
}
static tb_void_t gb_tessellator_fix_region_edge(gb_tessellator_impl_t* impl, gb_tessellator_active_region_ref_t region, gb_mesh_edge_ref_t edge)
{
// check
tb_assert(impl && impl->mesh && region && region->fixedge && edge);
// trace
tb_trace_d("fix a temporary edge: %{tess_region} => %{mesh_edge}", region, edge);
// remove the temporary edge
gb_mesh_edge_delete(impl->mesh, region->edge);
// replace the new edge
region->edge = edge;
// clear the "fixedge" mark
region->fixedge = 0;
// update the region reference to the edge
gb_tessellator_edge_region_set(edge, region);
}
/* fix the region order at the top edge
*
* theoretically, this should always be true.
*
* however, splitting an edge into two pieces can change the results of previous tests
* because of some numerical errors when we are calculating intersections.
*
* so we need fix it in fix_all_dirty_regions().
*
* @note this will generate one degenerate face with only two edges after fixing.
*
* before:
*
* .
* edge_left .
* . .
* .
* . . edge_left'
* . the previous region order have been changed
* . . .
* . . edge_right'
* .. .
* . ----------------> x (intersection with numerical error)
* .. splitting . .
* . . . .
* . . . .
* . . . .
* . . .
* . . . .
* . .
* edge_right
*
* after:
*
* .
*
* .
* edge_new
* .
*
* *
* .. edge_left/right (with a degenerate face)
* ..
* x (intersection with numerical error)
* . .
* . .
* . .
* . .
* . .
* . .
* . .
*
* so
*
* . . .
* edge_left . edge_left . .
* . region_left . .
* . (rface.inside) . . edge_new (rface.inside = region_left.inside)
* . . fixed .
* . . . . . . . -----------> * . . . . .
* . edge_right edge_right . . ..
* . . . . . . . . .. edge_left/right (with a degenerate face)
* .. intersection . . ..
* . x ------------> x x intersection with numerical error
* .. intersection with numerical error .. ..
* . . . . . .
* . . . . . .
* . . . . . .
* . . . . . .
* . . . . . .
* . . . . . .
* edge_right
*
* so we need fix the following case:
*
* . .
* . .
* . . ------------ . ---- . --------> fix it
* . . . .
* .. . .
* . ..
* .. ..
* . . . .
* L . . . .
* . R . . L . R
* . . .
*
*/
static tb_bool_t gb_tessellator_fix_region_order_at_top(gb_tessellator_impl_t* impl, gb_tessellator_active_region_ref_t region_left)
{
// check
tb_assert(impl && impl->mesh && region_left);
// the right region
gb_tessellator_active_region_ref_t region_right = gb_tessellator_active_regions_right(impl, region_left);
tb_assert(region_right);
// the edge of the left region
gb_mesh_edge_ref_t edge_left = region_left->edge;
tb_assert(edge_left);
// the edge of the right region
gb_mesh_edge_ref_t edge_right = region_right->edge;
tb_assert(edge_right);
// the destination of the left edge
gb_mesh_vertex_ref_t edge_left_dst = gb_mesh_edge_dst(edge_left);
tb_assert(edge_left_dst);
// the destination of the right edge
gb_mesh_vertex_ref_t edge_right_dst = gb_mesh_edge_dst(edge_right);
tb_assert(edge_right_dst);
// check
tb_assert(!gb_tessellator_vertex_eq(edge_left_dst, edge_right_dst));
/*
* .
* .
* .
* .
* . ----- . --------> fix it
* . .
* . .
* . .
* .
* . .
* . .
* . .
* . .
* . .
* edge_left edge_right
*/
if (gb_tessellator_vertex_in_top_or_hleft(edge_right_dst, edge_left_dst))
{
/* we need not fix it if the edge_left.dst is in the edge_right's left
*
* edge_right
* .
* .
* .
* edge_left .
* . .
* .
* . .
* .
* . .
* .
* . .
* .
* . .
* .
* .
*/
if (gb_tessellator_vertex_in_edge_left(edge_left_dst, edge_right_dst, gb_mesh_edge_org(edge_right)))
return tb_false;
/* the right edge will be split, so we need mark it and it's left edge as "dirty"
*
* fix_all_dirty_regions()
* <-------------------------
*
* edge_left edge_right edge_xxx
* (dirty) (dirty)
* | |-----------|
* | recheck
* |-------------------|
* recheck
*
*/
region_left->dirty = 1;
region_right->dirty = 1;
/* split the right edge and create a new edge
*
* edge_new
* .
* .
* lface x dst_new
* .
* .
* .
* . ----- . --------> fix it
* . .
* . .
* . .
* .
* . .
* . .
* . .
* . lface .
* . .
* edge_left edge_right
*/
gb_mesh_edge_ref_t edge_new = gb_mesh_edge_split(impl->mesh, edge_right);
tb_assert(edge_new);
/* splice the left edge and right edges
*
* edge_new
* .
*
* .
*
* . --------> fixed
* .
* .
* . .
* .
* .
* . .
* .
* .
* . .
* edge_left edge_right
*/
gb_mesh_edge_splice(impl->mesh, gb_mesh_edge_sym(edge_left), edge_new);
// the destination of the left edge cannot be changed
tb_assert(edge_left_dst == gb_mesh_edge_org(edge_new));
tb_assert(edge_left_dst == gb_mesh_edge_dst(edge_left));
tb_assert(edge_left_dst == gb_mesh_edge_dst(edge_right));
/* update the inside of the new edge
*
* @note only region_left.inside have been calculated and validate.
*
* the new edge may be the last right edge before calculating intersection and fixing region order
*
* .
* .
* region_left . edge_right
* (inside) .
* .
* edge_left . .
* . .
* .
* . .
* . .
* . .
* . .
*
* the region order was violated with some numerical error after calculating intersection
*
* . .
* . lface.inside = region_left.inside => .
* . .
* . .
* . .
* . fixed .
* . . . . . . ----------------------> . . x . .
* . . . .
* . . . .
* . . . .
* . . . . region_right
* . . .
* . . . .
* . . . region_left .
* . . region_right . .
* . . . .
* . . . .
* . . . .
* . region_left . . .
* . . . .
* edge_left edge_right edge_left edge_right
*/
gb_tessellator_face_inside_set(gb_mesh_edge_lface(edge_new), region_left->inside);
}
/*
* .
* .
* .
* .
* . ------- . -----------> fix it
* . .
* . .
* . .
* . .
* .
* . .
* . .
* . .
* . .
* edge_left edge_right
*/
else
{
/* we need not fix it if the edge_right.dst is in the edge_left's right
*
* edge_left
* .
* .
* .
* . edge_right
* . .
* .
* . .
* .
* . .
* .
* . .
* .
* . .
* .
* .
*/
if (gb_tessellator_vertex_in_edge_right(edge_right_dst, edge_left_dst, gb_mesh_edge_org(edge_left)))
return tb_false;
/* the left edge will be split, so we need mark it and it's left edge as "dirty"
*
* fix_all_dirty_regions()
* <-------------------------
*
* edge_left2 edge_left edge_right
* (dirty) (dirty)
* | |-----------|
* | recheck
* |-------------------|
* recheck
*
*/
gb_tessellator_active_region_ref_t region_left2 = gb_tessellator_active_regions_left(impl, region_left);
tb_assert(region_left2);
region_left->dirty = 1;
region_left2->dirty = 1;
/* split the left edge and create a new edge
*
* edge_new
* .
* .
* (dst_new) x
* .
* edge_right.lnext .
* . .
* . ------- . -----------> fix it
* . .
* . .
* . .
* . .
* .
* . .
* . .
* . .
* . .
* edge_left edge_right
*/
gb_mesh_edge_ref_t edge_new = gb_mesh_edge_split(impl->mesh, edge_left);
tb_assert(edge_new);
/* splice the left edge and right edges
*
* edge_new
* .
*
* .
* .
* . --------------------> fixed
* .
* .
* . .
* .
* .
* . .
* .
* .
* . .
* edge_left edge_right
*/
gb_mesh_edge_splice(impl->mesh, gb_mesh_edge_lnext(edge_right), gb_mesh_edge_sym(edge_left));
// the destination of the right edge cannot be changed
tb_assert(edge_right_dst == gb_mesh_edge_org(edge_new));
tb_assert(edge_right_dst == gb_mesh_edge_dst(edge_left));
tb_assert(edge_right_dst == gb_mesh_edge_dst(edge_right));
/* update the inside of the new edge
*
* @note only region_left.inside have been calculated and validate.
*
* the new edge may be the last right edge before calculating intersection and fixing region order
*
* .
* . edge_left
* .
* . region_left(inside)
* .
* . . edge_right
* . .
* .
* . .
* . .
* . .
* . .
*
*
* the region order was violated with some numerical error after calculating intersection
*
* edge_new
* . .
* . .
* . region_left .
* . (rface.inside) . rface.inside = region_left.inside
* . .
* . . . . . . --------------------------> . . x . .
* . . fixed . .
* . . . .
* . . . .
* . . . . region_right
* . . .
* . . region_right . .
* . . . region_left .
* . . . .
* . . . .
* edge_left edge_right edge_left edge_right
*/
gb_tessellator_face_inside_set(gb_mesh_edge_rface(edge_new), region_left->inside);
}
// trace
tb_trace_d("fix the top order for region: %{tess_region}", region_left);
// fixed
return tb_true;
}
/* fix the region order at the bottom edge
*
* the main purpose is to splice down-going edges with the same
* destinate vertex and nearly identical slopes.
*
* the region order may be violated
* because sometimes we can't distinguish the slopes numerically.
*
* . ..
* . ..
* . ..
* . ..
* . ..
* . ..
* . ..
* .. ----- ..---> fix it
* . .
* . .
*
* however the splicing can also help us to recover from numerical errors.
*
* . .
* . . .
* . L . R . .
* . . . L . R
* . . . .
* .. . .
* . ..
* .. ---------- .. ---------------> fix it
*
* we also can fix those cases where we can't check for intersection.
* - the left or right edge is a fixedge edge.
*
* . (fixable edge) . (fixable edge)
* . . .
* . L . R . .
* . . . L . R
* . . . .
* .. . .
* . ..
* .. ..
* . . . .
* . . ---- . -- . ---------------> fix it
* . .
*/
static tb_bool_t gb_tessellator_fix_region_order_at_bottom(gb_tessellator_impl_t* impl, gb_tessellator_active_region_ref_t region_left)
{
// check
tb_assert(impl && impl->mesh && region_left);
// the right region
gb_tessellator_active_region_ref_t region_right = gb_tessellator_active_regions_right(impl, region_left);
tb_assert(region_right);
// the edge of the left region
gb_mesh_edge_ref_t edge_left = region_left->edge;
tb_assert(edge_left);
// the edge of the right region
gb_mesh_edge_ref_t edge_right = region_right->edge;
tb_assert(edge_right);
// the origin of the left edge
gb_mesh_vertex_ref_t edge_left_org = gb_mesh_edge_org(edge_left);
tb_assert(edge_left_org);
// the origin of the right edge
gb_mesh_vertex_ref_t edge_right_org = gb_mesh_edge_org(edge_right);
tb_assert(edge_right_org);
/*
* edge_left edge_right edge_left edge_right edge_left edge_right edge_left/right
* . . . . . . ..
* . . . . . . ..
* . . . . . . ..
* . . . . . . ..
* . . . . . . ..
* . . . . . . ..
* . . or . . or . . ..
* .. . . . . ..
* . . . . . .
* .. . . . . .
* . . .. . . .
* . . . .. .
* . . ----------------- .. ------------------- . -------------- . --> fix it
* .
* .
*/
if (gb_tessellator_vertex_in_top_or_hleft_or_eq(edge_left_org, edge_right_org))
{
/* we need not fix it if the edge_left.org is in the edge_right's left
*
* edge_left edge_right
* . .
* .
* . .
* .
* . .
* .
* . .
* .
* . .
* .
* . .
* .
* . .
* .
* .
*/
if (gb_tessellator_vertex_in_edge_left(edge_left_org, gb_mesh_edge_dst(edge_right), edge_right_org))
return tb_false;
/* before:
*
* edge_left edge_right edge_left/right
* . . ..
* . . ..
* . . ..
* . . ..
* . . ..
* . . ..
* . . ..
* .. ..
* . ..
* .. ..
* . . ..
* . . ..
* . . ----------- .. --> fix it
* . .
* . .
*
* after:
*
* edge_left edge_right edge_left/right
* . . ..
* . ..
* . ..
* . . ..
* . ..
* . ..
* . . ..
* . ..
* . ..
* . . ..
* . ..
* . ..
* . ---------- . --> fixed
* . .
* . .
* edge_new edge_new
*
*/
if (!gb_tessellator_vertex_eq(edge_left_org, edge_right_org))
{
/* the right edge will be split, so we need mark it and it's left edge as "dirty"
*
* fix_all_dirty_regions()
* <-------------------------
*
* edge_left edge_right edge_xxx
* (dirty) (dirty)
* | |-----------|
* | recheck
* |-------------------|
* recheck
*
*/
region_left->dirty = 1;
region_right->dirty = 1;
/* split the right edge and create a new edge
*
* edge_left edge_right
* . lface .
* . .
* . .
* . .
* . .
* . .
* . .
* ..
* .
* ..
* . . lface
* . .
* . . . . . edge_left.oprev
* .
* x org_new
* .
* .
* edge_new
*
*/
gb_mesh_edge_split(impl->mesh, gb_mesh_edge_sym(edge_right));
/* splice the left edge and right edges
*
* edge_left edge_right
* . .
* .
* .
* . .
* .
* .
* . .
* .
* .
* . .
* .
* .
* . . . . -------------> fixed
* .
* .
* edge_new (org_new have been removed)
*/
gb_mesh_edge_splice(impl->mesh, gb_mesh_edge_oprev(edge_left), edge_right);
// the origin of the left edge cannot be changed
tb_assert(edge_left_org == gb_mesh_edge_org(edge_left));
tb_assert(edge_left_org == gb_mesh_edge_org(edge_right));
}
/* edge_left.org lies on the edge_right.org
*
* before:
*
* edge_left edge_right edge_left/right
* . . ..
* . . ..
* . . ..
* . . ..
* . . ..
* . . ..
* . . ..
* .. ..
* . ..
* .. ----------- .. ----> fix it (coordinate is equal, but the order is incorrect)
*
* after:
*
* edge_left edge_right edge_left/right
* . . ..
* . . ..
* . . ..
* . . ..
* . . ..
* . . ..
* . . ..
* .. ..
* . ------------ . ----> fixed
*/
else if (edge_left_org != edge_right_org)
{
// trace
tb_trace_d("splice and remove the event vertex: %{mesh_vertex}", edge_left_org);
/* remove the origin of the left edge first
*
* edge_left edge_right
* . lface .
* . .
* . .
* . .
* . .
* . .
* . .
* ..
* .
* .x(removed)
* . lface
* .
* . edge_left.oprev
*/
gb_tessellator_event_queue_remove(impl, edge_left_org);
/* splice the left edge and right edges
*
* edge_left edge_right
* . .
* . .
* . .
* . .
* . .
* . .
* . .
* ..
* .
*/
gb_mesh_edge_splice(impl->mesh, edge_right, gb_mesh_edge_oprev(edge_left));
}
/* we need not fix it,
* but we need remove one edge with same slope for inserting down-going edges
*
* edge_left/right
* ..
* ..
* ..
* ..
* .. (one edge will be removed after inserting down-going edges)
* ..
* ..
* ..
* .
*/
else return gb_mesh_edge_dst(edge_left) == gb_mesh_edge_dst(edge_right);
}
/*
* edge_left edge_right
* . .
* . .
* . .
* . .
* . .
* . .
* . .
* ..
* .
* ..
* . .
* . .
* . - . -----------------> fix it
* .
* .
*
*/
else
{
/* we need not fix it if the edge_right.org is in the edge_left's right
*
* edge_left edge_right
* . .
* .
* . .
* .
* . .
* .
* . .
* .
* . .
* .
* . .
* .
* . .
* .
* .
*/
if (gb_tessellator_vertex_in_edge_right(edge_right_org, gb_mesh_edge_dst(edge_left), edge_left_org))
return tb_false;
/* the left edge will be split, so we need mark it and it's left edge as "dirty"
*
* fix_all_dirty_regions()
* <-------------------------
*
* edge_left2 edge_left edge_right
* (dirty) (dirty)
* | |-----------|
* | recheck
* |-------------------|
* recheck
*
*/
gb_tessellator_active_region_ref_t region_left2 = gb_tessellator_active_regions_left(impl, region_left);
tb_assert(region_left2);
region_left->dirty = 1;
region_left2->dirty = 1;
/* split the left edge and create a new edge
*
* edge_left edge_right
* . .
* . .
* . .
* . .
* . .
* . .
* . .
* ..
* .
* ..
* . .
* . .
* . - . -----------------> fix it
* .
* org_new x
* .
* .
* edge_new
*/
gb_mesh_edge_ref_t edge_new = gb_mesh_edge_split(impl->mesh, gb_mesh_edge_sym(edge_left));
tb_assert(edge_new && edge_new == gb_mesh_edge_oprev(edge_left));
/* splice the left edge and right edges
*
* edge_left edge_right
* . .
* .
* .
* . .
* .
* .
* . .
* .
* .
* . .
* .
* .
* . ---------------------> fixed
* .
* .
* edge_new (org_new have been removed)
*/
gb_mesh_edge_splice(impl->mesh, edge_right, edge_new);
// the origin of the right edge cannot be changed
tb_assert(edge_right_org == gb_mesh_edge_org(edge_left));
tb_assert(edge_right_org == gb_mesh_edge_org(edge_right));
}
// trace
tb_trace_d("fix the bottom order for region: %{tess_region}", region_left);
// fixed
return tb_true;
}
/* we need fix four case because of the calculated intersection with some small numerical errors.
*
* the case 1 and 2 when calling insert_down_doing_edges():
*
* - the new left and right edges with the intersection point may violate the region order
* because the calculated intersection has some small numerical errors.
*
* case 1:
*
* edge_left
* .
* . .
* . .
* . .
* . .
* . .
* . event .
* . * . . edge_left_new
* . . . .
* . -------------- x <--- intersection with numerical error
* . .
* . .
* . .
* . .
* . .
* .
* .
* .
* edge_right
*
* or case 2:
*
* . edge_right
* . .
* . .
* . .
* . .
* edge_right_new . .
* . event.
* . . * .
* . . . .
* x <------------ . ----------------- intersection with numerical error
* . .
* . .
* . .
* . .
* . .
* .
* .
* .
* edge_left