Skip to content

Commit 9954130

Browse files
author
samme
committed
Line.intersectsRectangle should not reject horizontal/vertical lines
Fixes phaserjs#2942 Rule 1 also implied that zero-length lines should pass when inside the rectangle.
1 parent 1dc1dac commit 9954130

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

v2-community/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
### Bug Fixes
1717

18+
* Phaser.Line.intersectsRectangle() now works correctly for horizontal and vertical lines ([#2942](https://github.com/photonstorm/phaser/issues/2942)).
1819
* removeTextureAtlas now deletes the correct cache object.
1920

2021
## Version 2.7.1 - 28th November 2016

v2-community/src/geom/Line.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,11 @@ Phaser.Line.intersects = function (a, b, asSegment, result) {
633633
*
634634
* An intersection is considered valid if:
635635
*
636-
* The line starts within, or ends within, the Rectangle.
637-
* The line segment intersects one of the 4 rectangle edges.
636+
* The line starts within or ends within the rectangle (even for lines of length 0); or
637+
* The line segment intersects one of the 4 rectangle edges; and
638+
* The rectangle is not empty.
638639
*
639-
* The for the purposes of this function rectangles are considered 'solid'.
640+
* For the purposes of this function rectangles are considered 'solid'.
640641
*
641642
* @method Phaser.Line.intersectsRectangle
642643
* @param {Phaser.Line} line - The line to check for intersection with.
@@ -645,8 +646,8 @@ Phaser.Line.intersects = function (a, b, asSegment, result) {
645646
*/
646647
Phaser.Line.intersectsRectangle = function (line, rect) {
647648

648-
// Quick bail out of the Line and Rect bounds don't intersect
649-
if (!Phaser.Rectangle.intersects(line, rect))
649+
// Quick bail out
650+
if (rect.empty)
650651
{
651652
return false;
652653
}

0 commit comments

Comments
 (0)