From 7ea5bc135290dbe5db79e22017a67b23ff6bc890 Mon Sep 17 00:00:00 2001 From: liabru Date: Sat, 18 Mar 2023 12:42:29 +0000 Subject: [PATCH] added doc and warning for `Bodies.trapezioid` slope parameter range, closes #1075 --- src/factory/Bodies.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/factory/Bodies.js b/src/factory/Bodies.js index c55e6150..2a373a1e 100644 --- a/src/factory/Bodies.js +++ b/src/factory/Bodies.js @@ -54,6 +54,7 @@ var Vector = require('../geometry/Vector'); /** * Creates a new rigid body model with a trapezoid hull. + * The `slope` is parameterised as a fraction of `width` and must be < 1 to form a valid trapezoid. * 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 trapezoid @@ -61,13 +62,17 @@ var Vector = require('../geometry/Vector'); * @param {number} y * @param {number} width * @param {number} height - * @param {number} slope + * @param {number} slope Must be a number < 1. * @param {object} [options] * @return {body} A new trapezoid body */ Bodies.trapezoid = function(x, y, width, height, slope, options) { options = options || {}; + if (slope >= 1) { + Common.warn('Bodies.trapezoid: slope parameter must be < 1.'); + } + slope *= 0.5; var roof = (1 - (slope * 2)) * width;