@plait/core: isPointInRoundRectangle ignores the bottom-left corner cutout

Open Beginner friendly
#1,171 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Domain
frontend

Research direction

The bug is in isPointInRoundRectangle in packages/core/src/utils/math.ts. The handleLeftBottom y-range check at lines 290-291 is inverted, so compare it with handleRightBottom, which is correct. Run the four-point repro from the issue before and after the change. Done when [1, 9] returns false and the other three corners still return the same results.

Written by the indexing model from the issue text.

Description

isPointInRoundRectangle returns true for points in the bottom-left corner outside the corner arc because the handleLeftBottom y-range check is inverted.

// node repro.mjs (after `npm i @plait/[email protected]`)
import { isPointInRoundRectangle } from "@plait/core";

const rect = { x: 0, y: 0, width: 20, height: 10 };
console.log(isPointInRoundRectangle([1, 1], rect, 4));   // false (top-left corner cut off)
console.log(isPointInRoundRectangle([19, 1], rect, 4));  // false (top-right corner cut off)
console.log(isPointInRoundRectangle([19, 9], rect, 4));  // false (bottom-right corner cut off)
console.log(isPointInRoundRectangle([1, 9], rect, 4));   // true  (bottom-left corner NOT cut off)

Actual output:

false
false
false
true

Expected output:

false
false
false
false

[1, 9] is at distance Math.hypot(3, 3) = 4.24 > 4 from the bottom-left arc center [4, 6], so it lies outside the rounded corner just like the other three corners. In packages/core/src/utils/math.ts lines 290-291, handleLeftBottom checks point[1] >= rectY + height && point[1] <= rectY + height - radius, which is always false for positive radius; it should be point[1] >= rectY + height - radius && point[1] <= rectY + height (matching handleRightBottom).

Version: @plait/[email protected] and develop (e0d76b0942) on Node v26.13.0.

Found with a differential-testing tool; the report was drafted with AI assistance and reviewed and edited by me.

Credit: https://ucsbplse.github.io/

Dominant language
TypeScript
Stars
703
Forks
61
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from worktile/plait

All issues in worktile/plait

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.