Skip to content

DistPoint2Circle2 providing incorrect distance #215

Description

@nsmela

Ran some tests, found a bug. It may have existed before:

DistPoint2Circle2

Expected: 5.0d +/- 9.9999999999999995E-07d
But was: 7.0710678118654755d
Off by: -2.0710678118654755d

Gemini's explanation:

In geometry3Sharp, adding a scalar (double) to a Vector2d adds that scalar to both components ($x+s, y+s$).
For a radius of 5, this resulted in (0,0) + 5 = (5,5).
The distance from center (0,0) to (5,5) is $\sqrt{5^2 + 5^2} \approx 7.071$, causing the test failure.

Fix:
#

CircleClosest = circle.Center + circle.Radius;

#
CircleClosest = circle.Center + circle.Radius * PmC / lengthPmC;

CircleClosest = circle.Center;
CircleClosest.x += circle.Radius;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions