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

IndexOutOfRangeException in Geometry.TangentCC #208

Closed
dsn27 opened this issue Dec 21, 2024 · 0 comments
Closed

IndexOutOfRangeException in Geometry.TangentCC #208

dsn27 opened this issue Dec 21, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@dsn27
Copy link
Collaborator

dsn27 commented Dec 21, 2024

Description:
An IndexOutOfRangeException is raised in Geometry.TangentCC when it attempts to process the result from TangentPointCircle.
The issue arises because TangentPointCircle can return an empty array, but TangentCC is not prepared to handle this case.

CADability.Geometry.TangentCC(CADability.GeoPoint2D, double, CADability.GeoPoint2D, double) in Geometry.cs
CADability.Curve2D.Curves2D.TangentLines(CADability.Curve2D.ICurve2D, CADability.Curve2D.ICurve2D) in Curves2D.cs
CADability.Shapes.Border.ConvexHull() in Border.cs
CADability.Shapes.Border.GetSmallestEnclosingRectangle() in Border.cs

Expected Behavior:
TangentCC should handle cases where TangentPointCircle returns an empty array gracefully, either by:

  • Returning an empty result.
  • Throwing a meaningful exception with a descriptive message.

Actual Behavior:
An IndexOutOfRangeException is thrown because TangentCC assumes TangentPointCircle always returns at least two points.

Suggested Fix:
Add validation in TangentCC to check if the result from TangentPointCircle is null or empty before processing further.

The TangentPointCircle method should be updated to handle floating-point inaccuracies using a tolerance check:

if (pc < radius - Precision.eps) 
    return new GeoPoint2D[0]; // no solution
@dsn27 dsn27 added the bug Something isn't working label Dec 21, 2024
@dsn27 dsn27 self-assigned this Dec 21, 2024
@dsn27 dsn27 closed this as completed Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant