Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 208 - IndexOutOfRange #209

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CADability/Geometry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,9 @@ public static GeoPoint2D[] TangentPointCircle(GeoPoint2D p, GeoPoint2D c, double
// PC is distance between P and C, pc2 is PC^2
var pc2 = dx * dx + dy * dy;
var pc = Math.Sqrt(pc2);
if (pc < radius) return new GeoPoint2D[0]; // no solution

if (pc < radius - Precision.eps)
return new GeoPoint2D[0]; // no solution

// R is radius of circle centered in P, r2 is R^2
var r2 = pc2 - radius * radius;
Expand Down Expand Up @@ -1741,6 +1743,9 @@ public static GeoPoint2D[] TangentCC(GeoPoint2D center1, double radius1, GeoPoin
dc.Add(new Circle2D(center2, radius2));
#endif
GeoPoint2D[] tan = TangentPointCircle(center1, center2, radius2 - radius1); // must be two points
if (tan == null || tan.Length != 2)
throw new InvalidOperationException("TangentPointCircle did not return the expected tangent points.");

// must be 2 points
GeoVector2D v = tan[0] - center2;
v.Length = radius1;
Expand All @@ -1759,7 +1764,13 @@ public static GeoPoint2D[] TangentCC(GeoPoint2D center1, double radius1, GeoPoin
v.Length = radius1 * d / (radius1 + radius2);
GeoPoint2D c = center1 + v; // homothetic center
GeoPoint2D[] tan1 = TangentPointCircle(c, center1, radius1);
if (tan1 == null || tan1.Length != 2)
throw new InvalidOperationException("TangentPointCircle did not return the expected tangent points.");

GeoPoint2D[] tan2 = TangentPointCircle(c, center2, radius2);
if (tan2 == null || tan2.Length != 2)
throw new InvalidOperationException("TangentPointCircle did not return the expected tangent points.");

// must be two points for each
if (Geometry.OnSameSide(tan1[0], tan2[0], center1, center2))
{
Expand Down