Skip to content

Commit

Permalink
Merge branch 'line-pointOnLine'
Browse files Browse the repository at this point in the history
  • Loading branch information
samme committed Aug 3, 2017
2 parents c692afb + e4272de commit c3d64b3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ If you code with [TypeScript](http://www.typescriptlang.org/) there are comprehe

### Updates

* Added an `epsilon` argument for fuzzy comparisons in Phaser.Line#pointOnLine and Phaser.Line#pointOnSegment (#312).
* Removed obsolete PIXI TypeScript definitions.
* Removed [filters/pixi](https://github.com/photonstorm/phaser-ce/tree/v2.8.3/filters/pixi). They require PIXI.AbstractFilter, which was removed in 2.7.0.
* Updated NPM dependencies (except [typescript](https://www.npmjs.com/package/typescript); photonstorm/phaser#2198) and added [package-lock.json](https://docs.npmjs.com/files/package-lock.json).
Expand Down
14 changes: 8 additions & 6 deletions src/geom/Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,35 +222,37 @@ Phaser.Line.prototype = {
},

/**
* Tests if the given coordinates fall on this line. See pointOnSegment to test against just the line segment.
* Tests if the given coordinates fall on this line. See {@link #pointOnSegment} to test against just the line segment.
*
* @method Phaser.Line#pointOnLine
* @param {number} x - The line to check against this one.
* @param {number} y - The line to check against this one.
* @param {number} [epsilon=0] - Range for a fuzzy comparison, e.g., 0.0001.
* @return {boolean} True if the point is on the line, false if not.
*/
pointOnLine: function (x, y) {
pointOnLine: function (x, y, epsilon) {

return ((x - this.start.x) * (this.end.y - this.start.y) === (this.end.x - this.start.x) * (y - this.start.y));
return Phaser.Math.fuzzyEqual((x - this.start.x) * (this.end.y - this.start.y), (this.end.x - this.start.x) * (y - this.start.y), epsilon || 0);

},

/**
* Tests if the given coordinates fall on this line and within the segment. See pointOnLine to test against just the line.
* Tests if the given coordinates fall on this line and within the segment. See {@link #pointOnLine} to test against just the line.
*
* @method Phaser.Line#pointOnSegment
* @param {number} x - The line to check against this one.
* @param {number} y - The line to check against this one.
* @param {number} [epsilon=0] - Range for a fuzzy comparison, e.g., 0.0001.
* @return {boolean} True if the point is on the line and segment, false if not.
*/
pointOnSegment: function (x, y) {
pointOnSegment: function (x, y, epsilon) {

var xMin = Math.min(this.start.x, this.end.x);
var xMax = Math.max(this.start.x, this.end.x);
var yMin = Math.min(this.start.y, this.end.y);
var yMax = Math.max(this.start.y, this.end.y);

return (this.pointOnLine(x, y) && (x >= xMin && x <= xMax) && (y >= yMin && y <= yMax));
return (this.pointOnLine(x, y, epsilon) && (x >= xMin && x <= xMax) && (y >= yMin && y <= yMax));

},

Expand Down
4 changes: 2 additions & 2 deletions typescript/phaser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2467,8 +2467,8 @@ declare module Phaser {
fromSprite(startSprite: Phaser.Sprite, endSprite: Phaser.Sprite, useCenter?: boolean): Phaser.Line;
intersects(line: Phaser.Line, asSegment?: boolean, result?: Phaser.Point): Phaser.Point;
midPoint(out?: Phaser.Point): Phaser.Point;
pointOnLine(x: number, y: number): boolean;
pointOnSegment(x: number, y: number): boolean;
pointOnLine(x: number, y: number, epsilon?: number): boolean;
pointOnSegment(x: number, y: number, epsilon?: number): boolean;
random(out?: Phaser.Point): Phaser.Point;
reflect(line: Phaser.Line): number;
rotate(angle: number, asDegrees?: boolean): Phaser.Line;
Expand Down

0 comments on commit c3d64b3

Please sign in to comment.