mirror of
https://github.com/liabru/matter-js.git
synced 2024-12-26 13:49:01 -05:00
added minimum area check to Bodies.fromVertices
This commit is contained in:
parent
2b6a8d38af
commit
bf11ee5504
1 changed files with 8 additions and 1 deletions
|
@ -166,6 +166,7 @@ var Bodies = {};
|
|||
* If the vertices are not convex, they will be decomposed if [poly-decomp.js](https://github.com/schteppe/poly-decomp.js) is available.
|
||||
* If the vertices can not be decomposed, the function will use the convex hull.
|
||||
* By default the decomposition will discard collinear edges (to improve performance).
|
||||
* It will also discard any particularly small parts that have an area less than `minimumArea` (to improve stability).
|
||||
* The options parameter is an object that specifies any properties you wish to override the defaults.
|
||||
* See the properties section of the `Matter.Body` module for detailed information on what you can pass via the `options` object.
|
||||
* @method fromVertices
|
||||
|
@ -174,9 +175,10 @@ var Bodies = {};
|
|||
* @param [vector] vertices
|
||||
* @param {object} [options]
|
||||
* @param {bool} [removeCollinear=true]
|
||||
* @param {number} [minimumArea=100]
|
||||
* @return {body}
|
||||
*/
|
||||
Bodies.fromVertices = function(x, y, vertices, options, removeCollinear) {
|
||||
Bodies.fromVertices = function(x, y, vertices, options, removeCollinear, minimumArea) {
|
||||
var canDecompose = true,
|
||||
body,
|
||||
i,
|
||||
|
@ -186,6 +188,7 @@ var Bodies = {};
|
|||
|
||||
options = options || {};
|
||||
removeCollinear = typeof removeCollinear !== 'undefined' ? removeCollinear : true;
|
||||
minimumArea = typeof minimumArea !== 'undefined' ? minimumArea : 100;
|
||||
|
||||
if (Vertices.isConvex(vertices)) {
|
||||
// vertices are convex, so just create a body normally
|
||||
|
@ -229,6 +232,10 @@ var Bodies = {};
|
|||
chunkVertices.push({ x: chunk.vertices[j][0], y: chunk.vertices[j][1] });
|
||||
}
|
||||
|
||||
// skip small chunks
|
||||
if (minimumArea > 0 && Vertices.area(chunkVertices) < minimumArea)
|
||||
continue;
|
||||
|
||||
// create a compound part
|
||||
parts.push(
|
||||
Body.create(Common.extend({
|
||||
|
|
Loading…
Reference in a new issue