Skip to content

Commit 6e5415f

Browse files
committed
Point.interpolate - Interpolates the two given Points, based on the f value (between 0 and 1) and returns a new Point.
1 parent 8dd67ea commit 6e5415f

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ Version 2.0.4 - "Mos Shirare" - in development
112112
* Point.projectUnit - Project two Points onto a Point of unit length.
113113
* Point.multiplyAdd - Adds two 2D Points together and multiplies the result by the given scalar.
114114
* Point.negative - Creates a negative Point.
115+
* Point.interpolate - Interpolates the two given Points, based on the `f` value (between 0 and 1) and returns a new Point.
115116

116117

117118
### Bug Fixes

src/geom/Point.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,24 @@ Phaser.Point.multiplyAdd = function (a, b, s, out) {
623623

624624
};
625625

626+
/**
627+
* Interpolates the two given Points, based on the `f` value (between 0 and 1) and returns a new Point.
628+
*
629+
* @method Phaser.Point.interpolate
630+
* @param {Phaser.Point} a - The first Point object.
631+
* @param {Phaser.Point} b - The second Point object.
632+
* @param {number} f - The level of interpolation between the two points. Indicates where the new point will be, along the line between pt1 and pt2. If f=1, pt1 is returned; if f=0, pt2 is returned.
633+
* @param {Phaser.Point} [out] - Optional Point to store the value in, if not supplied a new Point object will be created.
634+
* @return {Phaser.Point} The new Point object.
635+
*/
636+
Phaser.Point.interpolate = function (a, b, f, out) {
637+
638+
if (typeof out === "undefined") { out = new Phaser.Point(); }
639+
640+
return out.setTo(a.x + (b.x - a.x) * f, a.y + (b.y - a.y) * f);
641+
642+
};
643+
626644
/**
627645
* Return a perpendicular vector (90 degrees rotation)
628646
*

0 commit comments

Comments
 (0)