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
use crate::prelude::*;
#[doc(hidden)]
#[derive(Debug, PartialEq)]
pub enum TangentArcArc {
OneArc(Arc),
TwoArcs(Arc, Arc),
ThreeArcs(Arc, Arc, Arc),
}
/// Given two arcs, computes the external tangent (CCW) points between them.
/// Returns new parts of the original arcs and connecting tangent part.
// pub fn tangent_arc_arc(arc1: &Arc, arc2: &Arc) -> TangentArcArc {
// }
#[cfg(test)]
mod test_tangent_arc_arc {
//use super::*;
// #[test]
// fn test_tangent_arc_arc_two_lines() {
// // Two line segments
// let line1 = arcseg(point(0.0, 0.0), point(1.0, 0.0));
// let line2 = arcseg(point(2.0, 0.0), point(3.0, 0.0));
// let result = tangent_arc_arc(&line1, &line2);
// match result {
// TangentArcArc::OneArc(arc) => {
// assert!(arc.is_line());
// assert_eq!(arc.a, point(1.0, 0.0)); // End of first line
// assert_eq!(arc.b, point(2.0, 0.0)); // Start of second line
// }
// _ => panic!("Expected OneArc for two line segments"),
// }
// }
// #[test]
// fn test_tangent_line_to_arc() {
// // Line segment to circular arc
// let line = arcseg(point(0.0, 0.0), point(1.0, 0.0));
// let arc = arc(point(3.0, 0.0), point(2.0, 1.0), point(2.0, 0.0), 1.0);
// let result = tangent_arc_arc(&line, &arc);
// match result {
// TangentArcArc::OneArc(connecting_arc) => {
// assert!(connecting_arc.is_line());
// assert_eq!(connecting_arc.a, point(1.0, 0.0)); // End of line
// assert_eq!(connecting_arc.b, point(3.0, 0.0)); // Start of arc
// }
// _ => panic!("Expected OneArc for line to arc"),
// }
// }
// #[test]
// fn test_tangent_arc_to_line() {
// // Circular arc to line segment
// let arc = arc(point(0.0, 1.0), point(1.0, 0.0), point(0.0, 0.0), 1.0);
// let line = arcseg(point(2.0, 0.0), point(3.0, 0.0));
// let result = tangent_arc_arc(&arc, &line);
// match result {
// TangentArcArc::OneArc(connecting_arc) => {
// assert!(connecting_arc.is_line());
// assert_eq!(connecting_arc.a, point(1.0, 0.0)); // End of arc
// assert_eq!(connecting_arc.b, point(2.0, 0.0)); // Start of line
// }
// _ => panic!("Expected OneArc for arc to line"),
// }
// }
// #[test]
// fn test_tangent_arc_to_arc_simple() {
// // Two circular arcs that are well separated
// let arc1 = arc(point(1.0, 0.0), point(0.0, 1.0), point(0.0, 0.0), 1.0);
// let arc2 = arc(point(4.0, 0.0), point(3.0, 1.0), point(3.0, 0.0), 1.0);
// let result = tangent_arc_arc(&arc1, &arc2);
// // Should get either OneArc, TwoArcs, or ThreeArcs
// match result {
// TangentArcArc::OneArc(_) => {
// // Simple connection is acceptable
// }
// TangentArcArc::TwoArcs(arc_a, arc_b) => {
// // More sophisticated tangent connection
// assert!(arc_a.is_line() || arc_a.is_arc());
// assert!(arc_b.is_line() || arc_b.is_arc());
// }
// TangentArcArc::ThreeArcs(arc_a, arc_b, arc_c) => {
// // Most sophisticated smooth connection
// assert!(arc_a.is_line() || arc_a.is_arc());
// assert!(arc_b.is_line() || arc_b.is_arc());
// assert!(arc_c.is_line() || arc_c.is_arc());
// }
// }
// }
// #[test]
// fn test_tangent_arc_to_arc_overlapping() {
// // Two overlapping circular arcs
// let arc1 = arc(point(1.0, 0.0), point(0.0, 1.0), point(0.0, 0.0), 1.0);
// let arc2 = arc(point(1.5, 0.0), point(0.5, 1.0), point(0.5, 0.0), 1.0);
// let result = tangent_arc_arc(&arc1, &arc2);
// // Should handle overlapping case gracefully
// match result {
// TangentArcArc::OneArc(arc) => {
// // Fallback to simple connection is expected for overlapping arcs
// assert!(arc.is_line());
// }
// _ => {
// // Other solutions are also acceptable
// }
// }
// }
// #[test]
// fn test_tangent_arc_to_arc_different_sizes() {
// // Arcs with different radii
// let arc1 = arc(point(1.0, 0.0), point(0.0, 1.0), point(0.0, 0.0), 1.0); // radius 1
// let arc2 = arc(point(5.0, 0.0), point(3.0, 2.0), point(3.0, 0.0), 2.0); // radius 2
// let result = tangent_arc_arc(&arc1, &arc2);
// // Should handle different radii
// match result {
// TangentArcArc::OneArc(_) => {}
// TangentArcArc::TwoArcs(_, _) => {}
// TangentArcArc::ThreeArcs(_, _, _) => {}
// }
// }
// #[test]
// fn test_tangent_arc_to_arc_concentric() {
// // Two concentric arcs (same center, different radii)
// let arc1 = arc(point(1.0, 0.0), point(0.0, 1.0), point(0.0, 0.0), 1.0);
// let arc2 = arc(point(2.0, 0.0), point(0.0, 2.0), point(0.0, 0.0), 2.0);
// let result = tangent_arc_arc(&arc1, &arc2);
// // Should handle concentric case (fallback to simple connection expected)
// match result {
// TangentArcArc::OneArc(arc) => {
// assert!(arc.is_line());
// }
// _ => {
// // Other solutions might be possible depending on implementation
// }
// }
// }
// #[test]
// fn test_compute_external_tangent_points() {
// // Test the helper function directly
// let c1 = point(0.0, 0.0);
// let r1 = 1.0;
// let c2 = point(4.0, 0.0);
// let r2 = 1.0;
// let result = compute_external_tangent_points(c1, r1, c2, r2);
// assert!(result.is_some());
// if let Some((t1, t2)) = result {
// // Tangent points should be on the circle boundaries
// let dist1 = (t1 - c1).norm();
// let dist2 = (t2 - c2).norm();
// assert!((dist1 - r1).abs() < 1e-10, "t1 not on first circle: {} vs {}", dist1, r1);
// assert!((dist2 - r2).abs() < 1e-10, "t2 not on second circle: {} vs {}", dist2, r2);
// }
// }
// #[test]
// fn test_compute_external_tangent_points_different_radii() {
// // Test with different radii
// let c1 = point(0.0, 0.0);
// let r1 = 1.0;
// let c2 = point(5.0, 0.0);
// let r2 = 2.0;
// let result = compute_external_tangent_points(c1, r1, c2, r2);
// assert!(result.is_some());
// if let Some((t1, t2)) = result {
// // Verify tangent points are on circles
// let dist1 = (t1 - c1).norm();
// let dist2 = (t2 - c2).norm();
// assert!((dist1 - r1).abs() < 1e-10);
// assert!((dist2 - r2).abs() < 1e-10);
// }
// }
// #[test]
// fn test_compute_external_tangent_points_impossible() {
// // Test case where external tangent is impossible (one circle inside other)
// let c1 = point(0.0, 0.0);
// let r1 = 1.0;
// let c2 = point(0.5, 0.0); // Very close
// let r2 = 2.0; // Large radius
// let result = compute_external_tangent_points(c1, r1, c2, r2);
// // Should return None for impossible case
// assert!(result.is_none());
// }
// #[test]
// fn test_angle_computation() {
// // Test angle computation functions
// let arc = arc(point(1.0, 0.0), point(0.0, 1.0), point(0.0, 0.0), 1.0);
// let start_angle = compute_arc_start_angle(&arc);
// let end_angle = compute_arc_end_angle(&arc);
// // Start should be at 0 radians (positive x-axis)
// assert!((start_angle - 0.0).abs() < 1e-10, "Start angle: {}", start_angle);
// // End should be at π/2 radians (positive y-axis)
// assert!((end_angle - std::f64::consts::PI/2.0).abs() < 1e-10, "End angle: {}", end_angle);
// }
// #[test]
// fn test_angle_computation_line() {
// // Test angle computation for line segments
// let line = arcseg(point(0.0, 0.0), point(1.0, 1.0));
// let start_angle = compute_arc_start_angle(&line);
// let end_angle = compute_arc_end_angle(&line);
// // For lines, both should give the direction angle (45 degrees = π/4)
// let expected_angle = std::f64::consts::PI / 4.0;
// assert!((start_angle - expected_angle).abs() < 1e-10);
// assert!((end_angle - expected_angle).abs() < 1e-10);
// }
}