From 79ffcf891e9024181ed59e3cd40760449572f1b7 Mon Sep 17 00:00:00 2001 From: liabru Date: Thu, 6 Jul 2017 21:51:23 +0100 Subject: [PATCH] added Composite.bounds --- src/body/Composite.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/body/Composite.js b/src/body/Composite.js index ee15d93..885669c 100644 --- a/src/body/Composite.js +++ b/src/body/Composite.js @@ -532,6 +532,24 @@ var Body = require('./Body'); return composite; }; + /** + * Returns the union of the bounds of all of the composite's bodies. + * @method bounds + * @param {composite} composite The composite. + * @returns {bounds} The composite bounds. + */ + Composite.bounds = function(composite) { + var bodies = Matter.Composite.allBodies(composite), + vertices = []; + + for (var i = 0; i < bodies.length; i += 1) { + var body = bodies[i]; + vertices.push(body.bounds.min, body.bounds.max); + } + + return Matter.Bounds.create(vertices); + }; + /* * * Events Documentation