Skip to content

Raise ValueError from circumcircle for collinear or coincident points - #9434

Merged
kuzeyron merged 1 commit into
kivy:masterfrom
charan-rathore:fix/circumcircle-collinear
Oct 20, 2026
Merged

kuzeyron merged 1 commit into
kivy:masterfrom
charan-rathore:fix/circumcircle-collinear

Conversation

@charan-rathore

Copy link
Copy Markdown
Contributor

Fixes #9432.

circumcircle solves for the circumcenter with a parametric formula whose denominator is zero for collinear or coincident input points, so those inputs crashed with a bare ZeroDivisionError. This raises a descriptive ValueError instead, which lets callers tell degenerate input apart from an internal arithmetic bug. minimum_bounding_circle propagates the same ValueError for all-collinear point sets (it hit the same ZeroDivisionError before; the circumcircle-based path has no meaningful answer for a degenerate set, so a clear error beats a cryptic one).

Tests: adds kivy/tests/test_geometry.py covering the rejected degenerate inputs and the non-degenerate results of circumcircle and minimum_bounding_circle. Verified locally by loading the real kivy/vector.py and kivy/geometry.py directly (the full suite needs the compiled graphics extensions, which CI covers): 3 passed on the patched code, and the collinear/coincident cases raise ZeroDivisionError on unpatched master.

When the three input points are collinear or coincident the
denominator of the parametric solution is zero and the function
crashed with a bare ZeroDivisionError. Raise a descriptive
ValueError instead so callers can tell bad input apart from real
arithmetic bugs. minimum_bounding_circle propagates the same
ValueError for degenerate (all-collinear) point sets.

Adds tests for the rejected degenerate inputs and for the
non-degenerate results of circumcircle and minimum_bounding_circle.

Signed-off-by: Charan Rathore <[email protected]>
@ElliotGarbus
ElliotGarbus requested a review from kuzeyron October 20, 2026 00:04
@ElliotGarbus

Copy link
Copy Markdown
Contributor

@kuzeyron This is ready to merge.

The change is correct (the new test fails on master and passes with the fix, CI is green) and low risk. It's a low-value fix, and nobody has reported the crash.

@kuzeyron
kuzeyron merged commit bdac6a6 into kivy:master Oct 20, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

circumcircle crashes with ZeroDivisionError on collinear or coincident points

3 participants