Skip to content

Commit 9757d83

Browse files
committed
add limit function to Point
1 parent 2c41814 commit 9757d83

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

v2-community/src/geom/Point.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,24 @@ Phaser.Point.prototype = {
374374

375375
},
376376

377+
/**
378+
* Alters the Point object so it's magnitude is at most the max value.
379+
*
380+
* @method Phaser.Point#limit
381+
* @param {number} max - The maximum magnitude for the Point.
382+
* @return {Phaser.Point} This Point object.
383+
*/
384+
limit: function (max) {
385+
386+
if (this.getMagnitudeSq() > max * max)
387+
{
388+
this.setMagnitude(max);
389+
}
390+
391+
return this;
392+
393+
},
394+
377395
/**
378396
* Determine if this point is at 0,0.
379397
*

0 commit comments

Comments
 (0)