forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerimeterPoint.js
More file actions
49 lines (40 loc) · 1.15 KB
/
Copy pathPerimeterPoint.js
File metadata and controls
49 lines (40 loc) · 1.15 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Point = require('../point/Point');
var DegToRad = require('../../math/DegToRad');
/**
* [description]
*
* @function Phaser.Geom.Rectangle.PerimeterPoint
* @since 3.0.0
*
* @param {Phaser.Geom.Rectangle} rectangle - [description]
* @param {integer} angle - [description]
* @param {Phaser.Geom.Point} [out] - [description]
*
* @return {Phaser.Geom.Point} [description]
*/
var PerimeterPoint = function (rectangle, angle, out)
{
if (out === undefined) { out = new Point(); }
angle = DegToRad(angle);
var s = Math.sin(angle);
var c = Math.cos(angle);
var dx = (c > 0) ? rectangle.width / 2 : rectangle.width / -2;
var dy = (s > 0) ? rectangle.height / 2 : rectangle.height / -2;
if (Math.abs(dx * s) < Math.abs(dy * c))
{
dy = (dx * s) / c;
}
else
{
dx = (dy * c) / s;
}
out.x = dx + rectangle.centerX;
out.y = dy + rectangle.centerY;
return out;
};
module.exports = PerimeterPoint;