FS#2588 - Draw > Circle > Circle2TP: Exceptions expected
Andrew:
Apollonius.getSolutionsPCC(...) calls for ShapeAlgorithms.getTangents(circle1, circle2)
What returns an array with tangent lines to the 2 circles.
- Empty when concentric (*)
- With 4 elements, the two external tangent lines and the two internal tangent lines if they exists.
Both or one endless internal tangent line(s) exists when the distance between the centers exceeds or equals the sum of the radii. Both the external exists when the smaller circle is not fully inside the larger circle, concentric disregarding the size is already excluded. When a smaller circle is internally tangent, only one endless tangent line exists.
Apollonius.getSolutionsPCC tests for an empty array but does not verify that the first external tangent exists.
In the case that it isn’t a line piece as expected:
var p1 = tangents[0].getClosestPointOnShape(circle1.getCenter(), false);
Will throw an exception ... Halting the code in debugger mode.
Reproducible in the attached file
I can not find any other use of ShapeAlgorithms.getTangents in open sources without verifying the returned tangents.
Further I detect a flaw in ShapeAlgorithms.getTangents(...)
var dist1 = circleCenter1.getDistanceTo(circleCenter2); ... // outer tangents: var dist2 = circleRadius2 - circleRadius1; if (dist1>dist2) { ...
When circleRadius1 > circleRadius2 the subtraction becomes negative and the comparison is always true.
To my knowledge dist2 must be the subtraction in absolute.
OR
Circle 2 must be the larger one but that is not a condition here.
(*) Remark that with concentric or circles in each other there are still solutions possible.
And in general there are up to 4 possible solutions for Circle2TP.
That would be a next contribution for Apollonius.js I am working on.
Regards,
CVH