Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/melonjs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion packages/melonjs/src/geometries/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

Expand Down
5 changes: 5 additions & 0 deletions packages/melonjs/tests/line.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down