mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 21:53:59 +00:00
Add Geom.Rectangle.FromXY
This commit is contained in:
parent
f57c0a3b17
commit
dfe4219f65
2 changed files with 38 additions and 0 deletions
37
src/geom/rectangle/FromXY.js
Normal file
37
src/geom/rectangle/FromXY.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* @author samme
|
||||
* @copyright 2020 Photon Storm Ltd.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
var Rectangle = require('./Rectangle');
|
||||
|
||||
/**
|
||||
* Create the smallest Rectangle containing two coordinate pairs.
|
||||
*
|
||||
* @function Phaser.Geom.Rectangle.FromXY
|
||||
* @since 3.23.0
|
||||
*
|
||||
* @generic {Phaser.Geom.Rectangle} O - [out,$return]
|
||||
*
|
||||
* @param {number} x1 - The X coordinate of the first point.
|
||||
* @param {number} y1 - The Y coordinate of the first point.
|
||||
* @param {number} x2 - The X coordinate of the second point.
|
||||
* @param {number} y2 - The Y coordinate of the second point.
|
||||
* @param {Phaser.Geom.Rectangle} [out] - Optional Rectangle to adjust.
|
||||
*
|
||||
* @return {Phaser.Geom.Rectangle} The adjusted `out` Rectangle, or a new Rectangle if none was provided.
|
||||
*/
|
||||
var FromXY = function (x1, y1, x2, y2, out)
|
||||
{
|
||||
if (out === undefined) { out = new Rectangle(); }
|
||||
|
||||
return out.setTo(
|
||||
Math.min(x1, x2),
|
||||
Math.min(y1, y2),
|
||||
Math.abs(x1 - x2),
|
||||
Math.abs(y1 - y2)
|
||||
);
|
||||
};
|
||||
|
||||
module.exports = FromXY;
|
|
@ -22,6 +22,7 @@ Rectangle.FitOutside = require('./FitOutside');
|
|||
Rectangle.Floor = require('./Floor');
|
||||
Rectangle.FloorAll = require('./FloorAll');
|
||||
Rectangle.FromPoints = require('./FromPoints');
|
||||
Rectangle.FromXY = require('./FromXY');
|
||||
Rectangle.GetAspectRatio = require('./GetAspectRatio');
|
||||
Rectangle.GetCenter = require('./GetCenter');
|
||||
Rectangle.GetPoint = require('./GetPoint');
|
||||
|
|
Loading…
Reference in a new issue