-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
Random.js
34 lines (28 loc) · 870 Bytes
/
Random.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* @author Richard Davey <rich@phaser.io>
* @copyright 2013-2024 Phaser Studio Inc.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Point = require('../point/Point');
/**
* Returns a random point on a given Line.
*
* @function Phaser.Geom.Line.Random
* @since 3.0.0
*
* @generic {Phaser.Geom.Point} O - [out,$return]
*
* @param {Phaser.Geom.Line} line - The Line to calculate the random Point on.
* @param {(Phaser.Geom.Point|object)} [out] - An instance of a Point to be modified.
*
* @return {(Phaser.Geom.Point|object)} A random Point on the Line.
*/
var Random = function (line, out)
{
if (out === undefined) { out = new Point(); }
var t = Math.random();
out.x = line.x1 + t * (line.x2 - line.x1);
out.y = line.y1 + t * (line.y2 - line.y1);
return out;
};
module.exports = Random;