0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-30 10:20:52 -05:00

added doc and warning for Bodies.trapezioid slope parameter range, closes #1075

This commit is contained in:
liabru 2023-03-18 12:42:29 +00:00
parent 6bda7e86d5
commit 7ea5bc1352

View file

@ -54,6 +54,7 @@ var Vector = require('../geometry/Vector');
/** /**
* Creates a new rigid body model with a trapezoid hull. * 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. * 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. * See the properties section of the `Matter.Body` module for detailed information on what you can pass via the `options` object.
* @method trapezoid * @method trapezoid
@ -61,13 +62,17 @@ var Vector = require('../geometry/Vector');
* @param {number} y * @param {number} y
* @param {number} width * @param {number} width
* @param {number} height * @param {number} height
* @param {number} slope * @param {number} slope Must be a number < 1.
* @param {object} [options] * @param {object} [options]
* @return {body} A new trapezoid body * @return {body} A new trapezoid body
*/ */
Bodies.trapezoid = function(x, y, width, height, slope, options) { Bodies.trapezoid = function(x, y, width, height, slope, options) {
options = options || {}; options = options || {};
if (slope >= 1) {
Common.warn('Bodies.trapezoid: slope parameter must be < 1.');
}
slope *= 0.5; slope *= 0.5;
var roof = (1 - (slope * 2)) * width; var roof = (1 - (slope * 2)) * width;