Skip to content

Reject zero-area shapes with meaningful errors - #8

Merged
progys merged 1 commit into
masterfrom
fix-zero-area-shapes
Aug 15, 2026
Merged

progys merged 1 commit into
masterfrom
fix-zero-area-shapes

Conversation

@progys

@progys progys commented Aug 15, 2026

Copy link
Copy Markdown
Owner

Problem

Two robustness issues with zero/degenerate shapes:

  1. Zero-area triangles were silently accepted and stored (e.g. `triangle 0 0 0 0 1 1`). `Triangle.inShape` then divided by `2 * area` = 0, producing `Infinity`/`NaN` and silently returning false for every point.
  2. `donut 0 0 0 2` (zero inner radius) failed with a misleading message — the error surfaced from the inner `Circle` constructor ("Circle radius should be positive number") instead of naming the donut.

Both violate requirement #4 ("meaningful error message and continue the execution").

Fix

  • `Triangle` constructor now rejects collinear/degenerate vertices (`area == 0`) — the divide-by-zero in `inShape` is unreachable by construction.
  • `Donut` constructor validates inner/outer radii positivity with clear messages before constructing its circles.

Tests (21 total, up from 11)

  • `TriangleTest`: degenerate + collinear rejection; inside / outside / on-boundary containment.
  • `DonutTest`: zero/negative/equal-radius rejection; point in ring / hole / outside outer circle.
  • End-to-end: every invalid zero-radius input prints a meaningful message and execution continues.

- Triangle: reject collinear/degenerate vertices (zero area) so inShape
  can no longer divide by zero.
- Donut: validate inner/outer radii positivity with clear messages
  instead of leaking Circle's generic message.
- Tests: degenerate/collinear rejection, containment incl. boundary,
  donut hole/ring/outside, radius validation.
@cursor

cursor Bot commented Aug 15, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@progys
progys merged commit d037f57 into master Aug 15, 2026
4 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.

1 participant