mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 15:12:18 +00:00
Fix Phaser.Line.intersectsPoints for floating point inaccuracy. Round the result to 3 decimals, should be enough precision and solves the problems.
See: http://www.html5gamedevs.com/topic/6840-phaserlineintersects-does-not-work-for-floats/
This commit is contained in:
parent
1e9d0b2438
commit
266eb10765
1 changed files with 7 additions and 2 deletions
|
@ -375,8 +375,13 @@ Phaser.Line.intersectsPoints = function (a, b, e, f, asSegment, result) {
|
|||
return null;
|
||||
}
|
||||
|
||||
result.x = ((b1 * c2) - (b2 * c1)) / denom;
|
||||
result.y = ((a2 * c1) - (a1 * c2)) / denom;
|
||||
/*
|
||||
Round to 3 decimals here, due to javascript floating point is 'broken'
|
||||
http://stackoverflow.com/questions/11832914/round-to-at-most-2-decimal-places-in-javascript
|
||||
See workaround explanation there in accepted answer there..
|
||||
*/
|
||||
result.x = Math.round( ((((b1 * c2) - (b2 * c1)) / denom)+0.00001)*1000 ) / 1000;
|
||||
result.y = Math.round( ((((a2 * c1) - (a1 * c2)) / denom)+0.00001)*1000 ) / 1000;
|
||||
|
||||
if (asSegment)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue