phaser/src/geom/line/GetMidPoint.js

33 lines
859 B
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2019-01-15 16:20:22 +00:00
* @copyright 2019 Photon Storm Ltd.
2018-02-12 16:01:20 +00:00
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Point = require('../point/Point');
2017-10-13 13:11:54 +00:00
/**
* Get the midpoint of the given line.
2017-10-13 13:11:54 +00:00
*
* @function Phaser.Geom.Line.GetMidPoint
* @since 3.0.0
*
2018-03-27 13:27:08 +00:00
* @generic {Phaser.Geom.Point} O - [out,$return]
*
* @param {Phaser.Geom.Line} line - The line to get the midpoint of.
* @param {(Phaser.Geom.Point|object)} [out] - An optional point object to store the midpoint in.
2017-10-13 13:11:54 +00:00
*
* @return {(Phaser.Geom.Point|object)} The midpoint of the Line.
2017-10-13 13:11:54 +00:00
*/
var GetMidPoint = function (line, out)
{
if (out === undefined) { out = new Point(); }
out.x = (line.x1 + line.x2) / 2;
out.y = (line.y1 + line.y2) / 2;
return out;
};
module.exports = GetMidPoint;