Added Path.getBounds.

This commit is contained in:
Richard Davey 2017-09-29 17:27:53 +01:00
parent 832c17b7c5
commit f005380d67

View file

@ -6,6 +6,7 @@ var EllipseCurve = require('./curves/ellipse/EllipseCurve');
var GameObjectFactory = require('../scene/plugins/GameObjectFactory');
var LineCurve = require('./curves/line/LineCurve');
var MoveTo = require('./MoveTo');
var Rectangle = require('../geom/rectangle/Rectangle');
var SplineCurve = require('./curves/spline/SplineCurve');
var Vector2 = require('../math/Vector2');
@ -112,6 +113,42 @@ var Path = new Class({
return this.ellipseTo(radius, radius, 0, 360, clockwise, rotation);
},
getBounds: function (out, accuracy)
{
if (out === undefined) { out = new Rectangle(); }
if (accuracy === undefined) { accuracy = 16; }
out.x = Number.MAX_SAFE_INTEGER;
out.y = Number.MAX_SAFE_INTEGER;
var bounds = new Rectangle();
var maxRight = Number.MIN_SAFE_INTEGER;
var maxBottom = Number.MIN_SAFE_INTEGER;
for (var i = 0; i < this.curves.length; i++)
{
var curve = this.curves[i];
if (!curve.active)
{
continue;
}
curve.getBounds(bounds, accuracy);
out.x = Math.min(out.x, bounds.x);
out.y = Math.min(out.y, bounds.y);
maxRight = Math.max(maxRight, bounds.right);
maxBottom = Math.max(maxBottom, bounds.bottom);
}
out.right = maxRight;
out.bottom = maxBottom;
return out;
},
toJSON: function ()
{
var out = [];