Skip to content

Commit 05aff94

Browse files
authored
Merge pull request phaserjs#2945 from samme/fix-issue-2942
Don't reject horizontal and vertical lines in Line.intersectsRectangle()
2 parents 3b0face + d54478d commit 05aff94

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

v2-community/CHANGELOG.md

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

1717
### Bug Fixes
1818

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

2122
## Version 2.7.1 - 28th November 2016

v2-community/src/geom/Line.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,12 @@ 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; or
637+
* The line segment intersects one of the 4 rectangle edges; and
638+
* The line has a non-zero length; and
639+
* The rectangle is not empty.
638640
*
639-
* The for the purposes of this function rectangles are considered 'solid'.
641+
* For the purposes of this function rectangles are considered 'solid'.
640642
*
641643
* @method Phaser.Line.intersectsRectangle
642644
* @param {Phaser.Line} line - The line to check for intersection with.
@@ -645,8 +647,8 @@ Phaser.Line.intersects = function (a, b, asSegment, result) {
645647
*/
646648
Phaser.Line.intersectsRectangle = function (line, rect) {
647649

648-
// Quick bail out of the Line and Rect bounds don't intersect
649-
if (!Phaser.Rectangle.intersects(line, rect))
650+
// Quick bail out
651+
if (line.length === 0 || rect.empty)
650652
{
651653
return false;
652654
}

0 commit comments

Comments
 (0)