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
#![allow(dead_code)]
#![deny(unused_results)]
use togo::prelude::*;
use crate::offsetraw::OffsetRaw;
static ZERO: f64 = 0.0;
const EPSILON: f64 = 1e-10;
/// Get bounding circle for an arc: returns (center, radius_squared)
/// Storing radius squared to avoid sqrt in distance calculations
fn bounding_circle_arc(arc: &Arc) -> (Point, f64) {
if arc.is_seg() {
// For a segment, bounding circle is at midpoint with half-diagonal as radius
let mid = point((arc.a.x + arc.b.x) / 2.0, (arc.a.y + arc.b.y) / 2.0);
let dx = arc.b.x - arc.a.x;
let dy = arc.b.y - arc.a.y;
let radius_sq = (dx * dx + dy * dy) / 4.0;
(mid, radius_sq)
} else {
// For an arc, bounding circle is the circle it lies on
let radius_sq = arc.r * arc.r;
(arc.c, radius_sq)
}
}
/// Check if two bounding circles intersect or touch
/// Both r1_sq and r2_sq are radius squared to avoid sqrt
fn circles_intersect(c1: Point, r1_sq: f64, c2: Point, r2_sq: f64) -> bool {
let dx = c2.x - c1.x;
let dy = c2.y - c1.y;
let dist_sq = dx * dx + dy * dy;
let r1 = r1_sq.sqrt();
let r2 = r2_sq.sqrt();
let sum_r = r1 + r2;
let sum_r_sq = sum_r * sum_r;
dist_sq <= sum_r_sq + EPSILON
}
/// Get AABB (axis-aligned bounding box) for a segment: (min_x, max_x, min_y, max_y)
#[inline(always)]
fn aabb_segment(seg: &Arc) -> (f64, f64, f64, f64) {
debug_assert!(seg.is_seg());
(seg.a.x.min(seg.b.x), seg.a.x.max(seg.b.x),
seg.a.y.min(seg.b.y), seg.a.y.max(seg.b.y))
}
/// Get AABB (axis-aligned bounding box) for an arc: (min_x, max_x, min_y, max_y)
#[inline(always)]
fn aabb_arc(arc: &Arc) -> (f64, f64, f64, f64) {
debug_assert!(arc.is_arc());
(arc.c.x - arc.r, arc.c.x + arc.r,
arc.c.y - arc.r, arc.c.y + arc.r)
}
/// Check if two AABBs overlap
fn aabb_overlap(min_x0: f64, max_x0: f64, min_y0: f64, max_y0: f64,
min_x1: f64, max_x1: f64, min_y1: f64, max_y1: f64) -> bool {
!(max_x0 < min_x1 || max_x1 < min_x0 || max_y0 < min_y1 || max_y1 < min_y0)
}
pub fn offset_split_arcs(row: &Vec<Vec<OffsetRaw>>, connect: &Vec<Vec<Arc>>) -> Vec<Arc> {
// Merge offsets and offset connections, filter singular arcs
let mut parts: Vec<Arc> = row
.iter()
.flatten()
.map(|offset_raw| offset_raw.arc.clone())
.chain(connect.iter().flatten().cloned())
.filter(|arc| arc.is_valid(EPSILON))
.collect();
let mut parts_final = Vec::new();
//let mut parts_final = Vec::new();
let steps = 100000; // TODO: make this configurable
//let mut splits_count = 0;
let mut kk = 0;
for k in 0..steps {
let mut j_current = usize::MAX;
while parts.len() > 0 {
let part0 = parts.pop().unwrap();
if parts.len() == 0 {
// No more parts to check against
parts_final.push(part0);
break;
}
for j in (0..parts.len()).rev() {
j_current = usize::MAX;
if part0.id == parts[j].id {
// Skip parts comming from the same original arc
continue;
}
// if part0.id == parts[j].id || part0.id == parts[j].id + ID_PADDING {
// // Skip parts comming from the same original arc
// continue;
// }
let part1 = parts[j].clone();
let (parts_new, _) = if part0.is_seg() && part1.is_seg() {
split_line_line(&part0, &part1)
} else if part0.is_arc() && part1.is_arc() {
split_arc_arc(&part0, &part1)
} else if part0.is_seg() && part1.is_arc() {
split_segment_arc(&part0, &part1)
} else if part0.is_arc() && part1.is_seg() {
split_segment_arc(&part1, &part0)
} else {
(Vec::new(), 0)
};
if !parts_new.is_empty() {
j_current = j;
parts.extend(parts_new);
break;
}
}
// this part parts[i] does not intersect with any other part
if j_current == usize::MAX {
parts_final.push(part0);
} else {
// remove the part1 from the parts
_ = parts.remove(j_current);
}
}
if parts.is_empty() {
// No more splits, we are done
kk = k;
break;
}
}
let _kkk = kk;
parts_final
}
// Split two lines at intersection point
pub fn split_line_line(arc0: &Arc, arc1: &Arc) -> (Vec<Arc>, usize) {
let mut res = Vec::new();
// Quick AABB check before expensive segment intersection
let (min_x0, max_x0, min_y0, max_y0) = aabb_segment(arc0);
let (min_x1, max_x1, min_y1, max_y1) = aabb_segment(arc1);
if !aabb_overlap(min_x0, max_x0, min_y0, max_y0, min_x1, max_x1, min_y1, max_y1) {
return (res, 0);
}
let seg0 = segment(arc0.a, arc0.b);
let seg1 = segment(arc1.a, arc1.b);
let intersection = int_segment_segment(&seg0, &seg1);
match intersection {
SegmentSegmentConfig::NoIntersection()
| SegmentSegmentConfig::OnePointTouching(_, _, _)
| SegmentSegmentConfig::TwoPointsTouching(_, _, _, _) => {
// should not enter here, but just in case
// the checks are done in the caller
(res, 0)
}
SegmentSegmentConfig::OnePoint(sp, _, _) => {
// split at one point
let mut line00 = arcseg(sp, arc0.a);
let mut line01 = arcseg(sp, arc0.b);
let mut line10 = arcseg(sp, arc1.a);
let mut line11 = arcseg(sp, arc1.b);
line00.id(arc0.id);
line01.id(arc0.id);
line10.id(arc1.id);
line11.id(arc1.id);
check_and_push(&mut res, &line00);
check_and_push(&mut res, &line01);
check_and_push(&mut res, &line10);
check_and_push(&mut res, &line11);
(res, 4)
}
SegmentSegmentConfig::TwoPoints(p0, p1, p2, p3) => {
// split at two points
let mut line00 = arcseg(p0, p1);
let mut line01 = arcseg(p1, p2);
let mut line10 = arcseg(p2, p3);
line00.id(arc0.id);
line01.id(arc0.id);
line10.id(arc1.id);
check_and_push(&mut res, &line00);
check_and_push(&mut res, &line01);
check_and_push(&mut res, &line10);
(res, 3)
}
}
}
pub fn split_arc_arc(arc0: &Arc, arc1: &Arc) -> (Vec<Arc>, usize) {
let mut res = Vec::new();
// Quick AABB check before expensive arc intersection
let (min_x0, max_x0, min_y0, max_y0) = aabb_arc(arc0);
let (min_x1, max_x1, min_y1, max_y1) = aabb_arc(arc1);
// Check AABB overlap
if !aabb_overlap(min_x0, max_x0, min_y0, max_y0, min_x1, max_x1, min_y1, max_y1) {
return (res, 0);
}
let inter = int_arc_arc(&arc0, &arc1);
match inter {
ArcArcConfig::NoIntersection()
| ArcArcConfig::CocircularOnePoint0(_)
| ArcArcConfig::CocircularOnePoint1(_)
| ArcArcConfig::CocircularTwoPoints(_, _) // The arcs shared endpoints, so theunion is a circle.
| ArcArcConfig::NonCocircularOnePointTouching(_)
| ArcArcConfig::NonCocircularTwoPointsTouching(_, _) => {
// should not enter here, but just in case
// the checks are done in the caller
(res, 0)
}
ArcArcConfig::NonCocircularOnePoint(p) => {
let mut arc00 = arc(arc0.a, p, arc0.c, arc0.r);
let mut arc01 = arc(p, arc0.b, arc0.c, arc0.r);
let mut arc10 = arc(arc1.a, p, arc1.c, arc1.r);
let mut arc11 = arc(p, arc1.b, arc1.c, arc1.r);
arc00.id(arc0.id);
arc01.id(arc0.id);
arc10.id(arc1.id);
arc11.id(arc1.id);
check_and_push(&mut res, &arc00);
check_and_push(&mut res, &arc01);
check_and_push(&mut res, &arc10);
check_and_push(&mut res, &arc11);
(res, 4)
}
ArcArcConfig::NonCocircularTwoPoints(point0, point1) => {
let mut p0 = point0;
let mut p1 = point1;
if points_order(arc0.a, p0, p1) < ZERO {
(p1, p0) = (p0, p1);
}
let mut arc00 = arc(arc0.a, p0, arc0.c, arc0.r);
let mut arc01 = arc(p0, p1, arc0.c, arc0.r);
let mut arc02 = arc(p1, arc0.b, arc0.c, arc0.r);
arc00.id(arc0.id);
arc01.id(arc0.id);
arc02.id(arc0.id);
if points_order(arc1.a, p0, p1) < ZERO {
(p1, p0) = (p0, p1);
}
let mut arc10 = arc(arc1.a, p0, arc1.c, arc1.r);
let mut arc11 = arc(p0, p1, arc1.c, arc1.r);
let mut arc12 = arc(p1, arc1.b, arc1.c, arc1.r);
arc10.id(arc1.id);
arc11.id(arc1.id);
arc12.id(arc1.id);
check_and_push(&mut res, &arc00);
check_and_push(&mut res, &arc01);
check_and_push(&mut res, &arc02);
check_and_push(&mut res, &arc10);
check_and_push(&mut res, &arc11);
check_and_push(&mut res, &arc12);
(res, 6)
}
ArcArcConfig::CocircularOnePointOneArc0(_, _) => {
let mut arc00 = arc(arc0.a, arc1.b, arc0.c, arc0.r);
let mut arc01 = arc(arc1.b, arc0.b, arc0.c, arc0.r);
let mut arc02 = arc(arc0.b, arc0.a, arc0.c, arc0.r);
arc00.id(arc0.id);
arc01.id(arc1.id);
arc02.id(arc0.id);
check_and_push(&mut res, &arc00);
check_and_push(&mut res, &arc01);
check_and_push(&mut res, &arc02);
(res, 3)
}
ArcArcConfig::CocircularOnePointOneArc1(_, _) => {
let mut arc00 = arc(arc1.a, arc0.b, arc0.c, arc0.r);
let mut arc01 = arc(arc0.b, arc1.b, arc0.c, arc0.r);
let mut arc02 = arc(arc1.b, arc1.a, arc0.c, arc0.r);
arc00.id(arc1.id);
arc01.id(arc0.id);
arc02.id(arc1.id);
check_and_push(&mut res, &arc00);
check_and_push(&mut res, &arc01);
check_and_push(&mut res, &arc02);
(res, 3)
}
ArcArcConfig::CocircularOneArc0(_) => {
let mut arc00 = arc(arc0.a, arc0.b, arc0.c, arc0.r);
arc00.id(arc0.id);
check_and_push(&mut res, &arc00);
(res, 1)
}
ArcArcConfig::CocircularOneArc1(_) => {
// Arc0 inside Arc1
let mut arc00 = arc(arc1.a, arc0.a, arc0.c, arc0.r);
let mut arc01 = arc(arc0.a, arc0.b, arc0.c, arc0.r);
let mut arc02 = arc(arc0.b, arc1.b, arc0.c, arc0.r);
arc00.id(arc1.id);
arc01.id(arc0.id);
arc02.id(arc1.id);
check_and_push(&mut res, &arc00);
check_and_push(&mut res, &arc01);
check_and_push(&mut res, &arc02);
(res, 3)
}
ArcArcConfig::CocircularOneArc2(_) => {
// Arc0 and Arc1 overlap, <B0,A0,B1,A1>.
let mut arc00 = arc(arc1.a, arc0.a, arc0.c, arc0.r);
let mut arc01 = arc(arc0.a, arc1.b, arc0.c, arc0.r);
let mut arc02 = arc(arc1.b, arc0.b, arc0.c, arc0.r);
arc00.id(arc1.id);
arc01.id(arc0.id);
arc02.id(arc1.id);
check_and_push(&mut res, &arc00);
check_and_push(&mut res, &arc01);
check_and_push(&mut res, &arc02);
(res, 3)
}
ArcArcConfig::CocircularOneArc3(_) => {
// Arc0 and arc1 overlap in a single arc <A0,B0,A1,B1>.
let mut arc00 = arc(arc0.a, arc1.a, arc0.c, arc0.r);
let mut arc01 = arc(arc1.a, arc0.b, arc0.c, arc0.r);
let mut arc02 = arc(arc0.b, arc1.b, arc0.c, arc0.r);
arc00.id(arc0.id);
arc01.id(arc1.id);
arc02.id(arc0.id);
check_and_push(&mut res, &arc00);
check_and_push(&mut res, &arc01);
check_and_push(&mut res, &arc02);
(res, 3)
}
ArcArcConfig::CocircularOneArc4(_) => {
// Arc1 inside Arc0, <A0,B0,B1,A1>
let mut arc00 = arc(arc0.a, arc1.a, arc0.c, arc0.r);
let mut arc01 = arc(arc1.a, arc1.b, arc0.c, arc0.r);
let mut arc02 = arc(arc1.b, arc0.b, arc0.c, arc0.r);
arc00.id(arc0.id);
arc01.id(arc1.id);
arc02.id(arc0.id);
check_and_push(&mut res, &arc00);
check_and_push(&mut res, &arc01);
check_and_push(&mut res, &arc02);
(res, 3)
}
ArcArcConfig::CocircularTwoArcs(_, _) => {
// The arcs overlap in two disjoint subarcs, each of positive subtended
// <A0,B1>, <A1,B0>
let mut arc00 = arc(arc0.a, arc1.b, arc0.c, arc0.r);
let mut arc01 = arc(arc1.a, arc0.b, arc0.c, arc0.r);
arc00.id(arc0.id);
arc01.id(arc1.id);
check_and_push(&mut res, &arc00);
check_and_push(&mut res, &arc01);
(res, 2)
}
}
}
// Split two lines at intersection point
pub fn split_segment_arc(line0: &Arc, arc1: &Arc) -> (Vec<Arc>, usize) {
debug_assert!(line0.is_seg());
debug_assert!(arc1.is_arc());
let mut res = Vec::new();
// Quick AABB check before expensive segment-arc intersection
let (min_x0, max_x0, min_y0, max_y0) = aabb_segment(line0);
let (min_x1, max_x1, min_y1, max_y1) = aabb_arc(arc1);
// Check AABB overlap
if !aabb_overlap(min_x0, max_x0, min_y0, max_y0, min_x1, max_x1, min_y1, max_y1) {
return (res, 0);
}
let segment = segment(line0.a, line0.b);
let inter = int_segment_arc(&segment, arc1);
match inter {
SegmentArcConfig::NoIntersection()
| SegmentArcConfig::OnePointTouching(_, _)
| SegmentArcConfig::TwoPointsTouching(_, _, _, _) => {
// should not enter here, but just in case
// the checks are done in the caller
(res, 0)
}
SegmentArcConfig::OnePoint(point, _) => {
let mut line00 = arcseg(line0.a, point);
let mut line01 = arcseg(point, line0.b);
let mut arc10 = arc(arc1.a, point, arc1.c, arc1.r);
let mut arc11 = arc(point, arc1.b, arc1.c, arc1.r);
line00.id(line0.id);
line01.id(line0.id);
arc10.id(arc1.id);
arc11.id(arc1.id);
check_and_push(&mut res, &line00);
check_and_push(&mut res, &line01);
check_and_push(&mut res, &arc10);
check_and_push(&mut res, &arc11);
(res, 4)
}
SegmentArcConfig::TwoPoints(point0, point1, _, _) => {
let mut p0 = point0;
let mut p1 = point1;
let mut line00 = arcseg(line0.a, p0);
let mut line01 = arcseg(p0, p1);
let mut line02 = arcseg(p1, line0.b);
if points_order(arc1.a, p0, p1) < ZERO {
(p1, p0) = (p0, p1);
}
let mut arc10 = arc(arc1.a, p0, arc1.c, arc1.r);
let mut arc11 = arc(p0, p1, arc1.c, arc1.r);
let mut arc12 = arc(p1, arc1.b, arc1.c, arc1.r);
line00.id(line0.id);
line01.id(line0.id);
line02.id(line0.id);
arc10.id(arc1.id);
arc11.id(arc1.id);
arc12.id(arc1.id);
check_and_push(&mut res, &line00);
check_and_push(&mut res, &line01);
check_and_push(&mut res, &line02);
check_and_push(&mut res, &arc10);
check_and_push(&mut res, &arc11);
check_and_push(&mut res, &arc12);
(res, 6)
}
}
}
// Check if the line-arc segments have 0.0 length
fn check_and_push(res: &mut Vec<Arc>, seg: &Arc) {
let eps = 1e-10;
if seg.is_valid(eps) {
res.push(seg.clone())
}
}
#[cfg(test)]
mod test_offset_split_arcs {
use std::vec;
use togo::prelude::*;
use super::*;
fn show(arc0: &Arc, arc1: &Arc, arcs: &Vec<Arc>, svg: &mut SVG) {
svg.arcsegment(&arc0, "grey");
svg.arcsegment(&arc1, "grey");
for arc in arcs.iter() {
svg.arcsegment(&arc, "blue");
svg.circle(&circle(arc.a, 1.1), "red");
svg.circle(&circle(arc.b, 1.1), "red");
}
svg.write();
}
#[test]
fn test_arc_arc_01() {
// let mut svg = svg(4.0, 6.0);
let arc0 = arc(point(1.0, 1.0), point(0.0, 0.0), point(1.0, 0.0), 1.0);
let arc1 = arc(point(1.0, 0.0), point(0.0, 1.0), point(0.0, 0.0), 1.0);
let (res, count) = split_arc_arc(&arc0, &arc1);
//show(&arc0, &arc1, &res, &mut svg);
assert_eq!(count, 4);
let p = 0.8660254037844386; // cos(30 degrees)
assert_eq!(
res,
vec![
arc(point(1.0, 1.0), point(0.5, p), point(1.0, 0.0), 1.0),
arc(point(0.5, p), point(0.0, 0.0), point(1.0, 0.0), 1.0),
arc(point(1.0, 0.0), point(0.5, p), point(0.0, 0.0), 1.0),
arc(point(0.5, p), point(0.0, 1.0), point(0.0, 0.0), 1.0),
]
);
}
#[test]
fn test_arc_arc_02() {
// let mut svg = svg(4.0, 6.0);
let arc0 = arc(point(0.0, 0.0), point(1.0, 1.0), point(0.0, 1.0), 1.0);
let arc1 = arc(point(0.0, 1.0), point(1.0, 0.0), point(1.0, 1.0), 1.0);
let (res, count) = split_arc_arc(&arc0, &arc1);
//show(&arc0, &arc1, &res, &mut svg);
assert_eq!(count, 4);
let p = 1.0 - 0.8660254037844386;
assert_eq!(
res,
vec![
arc(point(0.0, 0.0), point(0.5, p), point(0.0, 1.0), 1.0),
arc(point(0.5, p), point(1.0, 1.0), point(0.0, 1.0), 1.0),
arc(point(0.0, 1.0), point(0.5, p), point(1.0, 1.0), 1.0),
arc(point(0.5, p), point(1.0, 0.0), point(1.0, 1.0), 1.0),
]
);
}
#[test]
fn test_arc_arc_03() {
//let mut svg = svg(4.0, 6.0);
let arc0 = arc(point(1.2, 2.2), point(2.2, 1.2), point(1.2, 1.2), 1.0);
let arc1 = arc(point(-1.0, 0.0), point(0.0, 1.0), point(0.0, 0.0), 1.0);
let (_, count) = split_arc_arc(&arc0, &arc1);
//show(&arc0, &arc1, &res, &mut svg);
assert_eq!(count, 6);
}
#[test]
fn test_overlaping_lines() {
let mut svg = svg(200.0, 100.0);
let arc0 = arcseg(point(50.0, 50.0), point(150.0, 50.0));
let arc1 = arcseg(point(100.0, 50.0), point(200.0, 50.0));
let (res, count) = split_line_line(&arc0, &arc1);
show(&arc0, &arc1, &res, &mut svg);
assert_eq!(count, 3);
}
// #[test]
// #[ignore]
// fn test_random_arc_arc_split() {
// let mut rng = StdRng::seed_from_u64(1234);
// let mut input: Vec<OffsetRaw> = Vec::new();
// for _ in 0..50 {
// let arc0 = random_arc(100.0, 500.0, 100.0, 300.0, 2.0, &mut rng);
// let raw = OffsetRaw {
// arc: arc0.clone(),
// orig: point(0.0, 0.0),
// g: 2.0,
// };
// input.push(raw);
// }
// let v: Vec<Vec<OffsetRaw>> = vec![input.clone()];
// let result = offset_split_arcs(&v, &Vec::new());
// let mut svg = svg(600.0, 400.0);
// let mut c = 0;
// for raw in input.iter() {
// svg.offset_segment(&raw.arc, "blue");
// //svg.text(arc.a.x, arc.a.y, &c.to_string(), "blue");
// c = c + 1;
// }
// for arc in result.iter() {
// //svg.arc(&arc, "blue");
// svg.circle(&circle(arc.a, 0.3), "red");
// svg.circle(&circle(arc.b, 0.3), "red");
// }
// svg.write();
// assert_eq!(result.len(), 732);
// }
// #[test]
// #[ignore]
// fn test_random_line_line_split() {
// let mut rng = StdRng::seed_from_u64(1234);
// let mut input: Vec<OffsetRaw> = Vec::new();
// for _ in 0..50 {
// let seg = random_arc(10.0, 590.0, 10.0, 390.0, 0.0, &mut rng);
// let raw = OffsetRaw {
// arc: seg.clone(),
// orig: point(0.0, 0.0),
// g: 2.0,
// };
// input.push(raw);
// }
// let v: Vec<Vec<OffsetRaw>> = vec![input.clone()];
// let result = offset_split_arcs(&v, &Vec::new());
// let mut svg = svg(600.0, 400.0);
// let mut c = 0;
// for raw in input.iter() {
// svg.offset_segment(&raw.arc, "blue");
// //svg.text(arc.a.x, arc.a.y, &c.to_string(), "blue");
// c = c + 1;
// }
// for arc in result.iter() {
// //svg.arc(&arc, "blue");
// svg.circle(&circle(arc.a, 0.3), "red");
// svg.circle(&circle(arc.b, 0.3), "red");
// }
// svg.write();
// assert_eq!(result.len(), 646);
// }
// #[test]
// #[ignore]
// fn test_random_line_arc_split() {
// let mut rng = StdRng::seed_from_u64(1234);
// let mut input: Vec<OffsetRaw> = Vec::new();
// for _ in 0..25 {
// let seg = random_arc(10.0, 590.0, 10.0, 390.0, 0.0, &mut rng);
// let raw = OffsetRaw {
// arc: seg.clone(),
// orig: point(0.0, 0.0),
// g: 2.0,
// };
// input.push(raw);
// }
// for _ in 0..25 {
// let seg = random_arc(100.0, 500.0, 100.0, 300.0, 2.0, &mut rng);
// let raw = OffsetRaw {
// arc: seg.clone(),
// orig: point(0.0, 0.0),
// g: 2.0,
// };
// input.push(raw);
// }
// let v: Vec<Vec<OffsetRaw>> = vec![input.clone()];
// let result = offset_split_arcs(&v, &Vec::new());
// let mut svg = svg(600.0, 400.0);
// let mut c = 0;
// for raw in input.iter() {
// svg.offset_segment(&raw.arc, "blue");
// //svg.text(arc.a.x, arc.a.y, &c.to_string(), "blue");
// c = c + 1;
// }
// for arc in result.iter() {
// //svg.arc(&arc, "blue");
// svg.circle(&circle(arc.a, 0.3), "red");
// svg.circle(&circle(arc.b, 0.3), "red");
// }
// svg.write();
// assert_eq!(result.len(), 890);
// }
#[test]
fn test_cocircular_issue_91() {
let mut svg = svg(200.0, 300.0);
let arc0 = arc(point(29.177446878757827, 250.0), point(-65.145657857171898, 211.46278163768008), point(15.0, 150.0), 101.0);
let arc1 = arc(point(0.82255312124217461, 250.0), point(29.177446878757827, 250.0), point(15.0, 150.0), 101.0);
let (res, _) = split_arc_arc(&arc0, &arc1);
show(&arc0, &arc1, &res, &mut svg);
// assert_eq!(count, 4);
// let p = 0.8660254037844386; // cos(30 degrees)
// assert_eq!(
// res,
// vec![
// arc(point(1.0, 1.0), point(0.5, p), point(1.0, 0.0), 1.0),
// arc(point(0.5, p), point(0.0, 0.0), point(1.0, 0.0), 1.0),
// arc(point(1.0, 0.0), point(0.5, p), point(0.0, 0.0), 1.0),
// arc(point(0.5, p), point(0.0, 1.0), point(0.0, 0.0), 1.0),
// ]
// );
}
#[test]
fn test_split_segment_arc_issue_01() {
let mut svg = svg(200.0, 300.0);
let arc0 = arc(point(51.538461538461533, 246.30769230769232), point(-23.494939167562663, 105.0), point(100.0, 130.0), 126.0);
let seg1 = arcseg(point(-25.599999999999994, -0.80000000000001137), point(-25.599999999999994, 150.80000000000001));
let (res, _) = split_segment_arc(&seg1, &arc0);
show(&arc0, &seg1, &res, &mut svg);
// assert_eq!(count, 4);
// let p = 0.8660254037844386; // cos(30 degrees)
// assert_eq!(
// res,
// vec![
// arc(point(1.0, 1.0), point(0.5, p), point(1.0, 0.0), 1.0),
// arc(point(0.5, p), point(0.0, 0.0), point(1.0, 0.0), 1.0),
// arc(point(1.0, 0.0), point(0.5, p), point(0.0, 0.0), 1.0),
// arc(point(0.5, p), point(0.0, 1.0), point(0.0, 0.0), 1.0),
// ]
// );
}
}