Skip to content

Commit 917dc8f

Browse files
committed
Rectangle.getLineA/B/C/D now returns a Line instead of an untyped object. It also now has an optional argument that allows you to pass a Line in to be populated, rather than creating a new one.
1 parent 3eef321 commit 917dc8f

2 files changed

Lines changed: 47 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@
7575
* Actions.SetX has 2 new arguments: `index` and `direction`.
7676
* Actions.SetXY has 2 new arguments: `index` and `direction`.
7777
* Actions.SetY has 2 new arguments: `index` and `direction`.
78-
* Line.getPointA and Line.getPointB now return Vector2 instances instead of un-typed objects.
78+
* Line.getPointA now returns a Vector2 instead of an untyped object. It also now has an optional argument that allows you to pass a vec2 in to be populated, rather than creating a new one.
79+
* Line.getPointB now returns a Vector2 instead of an untyped object. It also now has an optional argument that allows you to pass a vec2 in to be populated, rather than creating a new one.
80+
* Rectangle.getLineA now returns a Line instead of an untyped object. It also now has an optional argument that allows you to pass a Line in to be populated, rather than creating a new one.
81+
* Rectangle.getLineB now returns a Line instead of an untyped object. It also now has an optional argument that allows you to pass a Line in to be populated, rather than creating a new one.
82+
* Rectangle.getLineC now returns a Line instead of an untyped object. It also now has an optional argument that allows you to pass a Line in to be populated, rather than creating a new one.
83+
* Rectangle.getLineD now returns a Line instead of an untyped object. It also now has an optional argument that allows you to pass a Line in to be populated, rather than creating a new one.
7984

8085

8186

src/geom/rectangle/Rectangle.js

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var Class = require('../../utils/Class');
88
var Contains = require('./Contains');
99
var GetPoint = require('./GetPoint');
1010
var GetPoints = require('./GetPoints');
11+
var Line = require('../line/Line');
1112
var Random = require('./Random');
1213

1314
/**
@@ -231,60 +232,80 @@ var Rectangle = new Class({
231232
return (this.width <= 0 || this.height <= 0);
232233
},
233234

234-
// TOP
235235
/**
236-
* [description]
236+
* Returns a Line object that corresponds to the top of this Rectangle.
237237
*
238238
* @method Phaser.Geom.Rectangle#getLineA
239239
* @since 3.0.0
240240
*
241-
* @return {{x1:number,y1:number,x2:number,y2:number}} [description]
241+
* @param {Phaser.Geom.Line} [line] - A Line object to set the results in. If `undefined` a new Line will be created.
242+
*
243+
* @return {Phaser.Geom.Line} A Line object that corresponds to the top of this Rectangle.
242244
*/
243-
getLineA: function ()
245+
getLineA: function (line)
244246
{
245-
return { x1: this.x, y1: this.y, x2: this.right, y2: this.y };
247+
if (line === undefined) { line = new Line(); }
248+
249+
line.setTo(this.x, this.y, this.right, this.y);
250+
251+
return line;
246252
},
247253

248-
// RIGHT
249254
/**
250-
* [description]
255+
* Returns a Line object that corresponds to the right of this Rectangle.
251256
*
252257
* @method Phaser.Geom.Rectangle#getLineB
253258
* @since 3.0.0
254259
*
255-
* @return {{x1:number,y1:number,x2:number,y2:number}} [description]
260+
* @param {Phaser.Geom.Line} [line] - A Line object to set the results in. If `undefined` a new Line will be created.
261+
*
262+
* @return {Phaser.Geom.Line} A Line object that corresponds to the right of this Rectangle.
256263
*/
257-
getLineB: function ()
264+
getLineB: function (line)
258265
{
259-
return { x1: this.right, y1: this.y, x2: this.right, y2: this.bottom };
266+
if (line === undefined) { line = new Line(); }
267+
268+
line.setTo(this.right, this.y, this.right, this.bottom);
269+
270+
return line;
260271
},
261272

262-
// BOTTOM
263273
/**
264-
* [description]
274+
* Returns a Line object that corresponds to the bottom of this Rectangle.
265275
*
266276
* @method Phaser.Geom.Rectangle#getLineC
267277
* @since 3.0.0
268278
*
269-
* @return {{x1:number,y1:number,x2:number,y2:number}} [description]
279+
* @param {Phaser.Geom.Line} [line] - A Line object to set the results in. If `undefined` a new Line will be created.
280+
*
281+
* @return {Phaser.Geom.Line} A Line object that corresponds to the bottom of this Rectangle.
270282
*/
271-
getLineC: function ()
283+
getLineC: function (line)
272284
{
273-
return { x1: this.right, y1: this.bottom, x2: this.x, y2: this.bottom };
285+
if (line === undefined) { line = new Line(); }
286+
287+
line.setTo(this.right, this.bottom, this.x, this.bottom);
288+
289+
return line;
274290
},
275291

276-
// LEFT
277292
/**
278-
* [description]
293+
* Returns a Line object that corresponds to the left of this Rectangle.
279294
*
280295
* @method Phaser.Geom.Rectangle#getLineD
281296
* @since 3.0.0
282297
*
283-
* @return {{x1:number,y1:number,x2:number,y2:number}} [description]
298+
* @param {Phaser.Geom.Line} [line] - A Line object to set the results in. If `undefined` a new Line will be created.
299+
*
300+
* @return {Phaser.Geom.Line} A Line object that corresponds to the left of this Rectangle.
284301
*/
285-
getLineD: function ()
302+
getLineD: function (line)
286303
{
287-
return { x1: this.x, y1: this.bottom, x2: this.x, y2: this.y };
304+
if (line === undefined) { line = new Line(); }
305+
306+
line.setTo(this.x, this.bottom, this.x, this.y);
307+
308+
return line;
288309
},
289310

290311
/**

0 commit comments

Comments
 (0)