Skip to content

Commit fb066fe

Browse files
committed
Added Curve.getBounds support (and an override for LineCurve to make it faster).
1 parent 0ab6bc6 commit fb066fe

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

v3/src/paths/curves/Curve.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Based on the three.js Curve classes created by [zz85](http://www.lab4games.net/zz85/blog)
22

33
var Class = require('../../utils/Class');
4+
var FromPoints = require('../../geom/rectangle/FromPoints');
5+
var Rectangle = require('../../geom/rectangle/Rectangle');
46
var Vector2 = require('../../math/Vector2');
57

68
// Local cache vars
@@ -25,6 +27,18 @@ var Curve = new Class({
2527
this.needsUpdate = true;
2628
},
2729

30+
getBounds: function (out)
31+
{
32+
if (out === undefined) { out = new Rectangle(); }
33+
34+
// The length of the curve in pixels
35+
// So we'll have 1 spaced point per 10 pixels
36+
37+
var spaced = Math.max(1, Math.round(this.getLength() / 10));
38+
39+
return FromPoints(this.getSpacedPoints(spaced), out);
40+
},
41+
2842
getStartPoint: function (out)
2943
{
3044
if (out === undefined) { out = new Vector2(); }

v3/src/paths/curves/line/LineCurve.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
var Class = require('../../../utils/Class');
44
var Curve = require('../Curve');
5+
var FromPoints = require('../../../geom/rectangle/FromPoints');
6+
var Rectangle = require('../../../geom/rectangle/Rectangle');
57
var Vector2 = require('../../../math/Vector2');
68

79
// Phaser.Curves.Line
@@ -29,6 +31,13 @@ var LineCurve = new Class({
2931
this.p1 = p1;
3032
},
3133

34+
getBounds: function (out)
35+
{
36+
if (out === undefined) { out = new Rectangle(); }
37+
38+
return FromPoints([ this.p0, this.p1 ], out);
39+
},
40+
3241
getStartPoint: function (out)
3342
{
3443
if (out === undefined) { out = new Vector2(); }

0 commit comments

Comments
 (0)