From 75c558daabfc6d3fc2fe4fca2e764d389dd3d80e Mon Sep 17 00:00:00 2001 From: mmporong Date: Sat, 31 Oct 2026 20:00:43 +0900 Subject: [PATCH] =?UTF-8?q?fix(line):=20=EC=84=A0=EB=B6=84=20=EC=97=B0?= =?UTF-8?q?=EC=9E=A5=EC=84=A0=EC=9D=98=20=EC=A0=90=EC=9D=84=20=ED=8F=AC?= =?UTF-8?q?=ED=95=A8=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/melonjs/CHANGELOG.md | 1 + packages/melonjs/src/geometries/line.ts | 7 ++++++- packages/melonjs/tests/line.spec.ts | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/melonjs/CHANGELOG.md b/packages/melonjs/CHANGELOG.md index fa37f15a7d..27d454a34d 100644 --- a/packages/melonjs/CHANGELOG.md +++ b/packages/melonjs/CHANGELOG.md @@ -24,6 +24,7 @@ ### Fixed - Input: a child cropped out of view by a container with `clipping`, or scrolled out of a `UIPanel`, no longer gets pointer events where it is not drawn +- Geometry: `Line#contains()` checks the segment endpoints as well as collinearity; a point on the line beyond either endpoint was reported as contained (thanks @mmporong) - UI: a `UITextButton` moved after it was built draws its background where it is, not where it was first put - UI: a blocking `UIPanel` stays opaque to hover for as long as the pointer is on it, not only on the frame the pointer enters - UI: a draggable `UIBaseElement` pressed with no hover first, as a touch tap is, no longer throws, and drags by touch; in the world, rather than floating, it no longer jumps by the camera position when dragged diff --git a/packages/melonjs/src/geometries/line.ts b/packages/melonjs/src/geometries/line.ts index 781cf70770..d693429961 100644 --- a/packages/melonjs/src/geometries/line.ts +++ b/packages/melonjs/src/geometries/line.ts @@ -48,7 +48,12 @@ export class Line extends Polygon { //(Cy - Ay) * (Bx - Ax) = (By - Ay) * (Cx - Ax) return ( - (_y - start.y) * (end.x - start.x) === (end.y - start.y) * (_x - start.x) + (_y - start.y) * (end.x - start.x) === + (end.y - start.y) * (_x - start.x) && + _x >= Math.min(start.x, end.x) && + _x <= Math.max(start.x, end.x) && + _y >= Math.min(start.y, end.y) && + _y <= Math.max(start.y, end.y) ); } diff --git a/packages/melonjs/tests/line.spec.ts b/packages/melonjs/tests/line.spec.ts index 1996de187b..32c22a1ffb 100644 --- a/packages/melonjs/tests/line.spec.ts +++ b/packages/melonjs/tests/line.spec.ts @@ -60,6 +60,11 @@ describe("Shape : Line", () => { expect(line.contains(29, 61)).toEqual(false); }); + it("does not contain collinear points beyond its endpoints", () => { + expect(line.contains(56, 120)).toEqual(false); + expect(line.contains(-28, -60)).toEqual(false); + }); + it("Line Bounding Rect width is 28", () => { expect(bounds.width).toEqual(28); });