liabru/matter-js · warning
Bodies.trapezoid: slope parameter must be < 1.
Error message
Bodies.trapezoid: slope parameter must be < 1.
What it means
Bodies.trapezoid computes the top roof width as (1 - slope*2) * width, which becomes zero or negative for slope >= 1. The library warns when the slope parameter is >= 1, then continues, producing a degenerate (zero/negative-width) trapezoid.
Source
Thrown at src/factory/Bodies.js:73
/**
* 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
* @param {number} x
* @param {number} y
* @param {number} width
* @param {number} height
* @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;
var x1 = width * slope,
x2 = x1 + roof,
x3 = x2 + x1,
verticesPath;
if (slope < 0.5) {
verticesPath = 'L 0 0 L ' + x1 + ' ' + (-height) + ' L ' + x2 + ' ' + (-height) + ' L ' + x3 + ' 0';
} else {
verticesPath = 'L 0 0 L ' + x2 + ' ' + (-height) + ' L ' + x3 + ' 0';
}
var trapezoid = {
label: 'Trapezoid Body',View on GitHub (pinned to acb99b6f87)
Solutions
- Pass a slope strictly less than 1 (e.g. 0.5) — it is the per-side taper fraction of width.
- If you intended an angle, convert it: slope = Math.tan(angle/2) style fraction, or clamp: slope = Math.min(slope, 0.99).
- For steep/pointed shapes, use Bodies.polygon or Bodies.fromVertices instead of trapezoid.
Example fix
// before Bodies.trapezoid(x, y, 100, 60, 1.2); // after Bodies.trapezoid(x, y, 100, 60, Math.min(1.2, 0.9));
Defensive patterns
Strategy: validation
Validate before calling
if (typeof slope !== 'number' || !(slope < 1)) {
throw new RangeError('Bodies.trapezoid slope must be a number < 1');
} Type guard
function isValidSlope(s) {
return typeof s === 'number' && Number.isFinite(s) && s < 1;
} Prevention
- Remember trapezoid slope is a width-fraction taper (< 1), not an angle.
- Clamp dynamic slopes: slope = Math.min(slope, 0.99) before calling.
- Prefer Bodies.polygon/fromVertices for shapes needing steep tapers.
When it happens
Trigger: Calling Bodies.trapezoid(x, y, width, height, slope, options) with slope >= 1 — e.g. slope of 1, 1.5, or negative-derived values outside the expected (0..1) range.
Common situations: Confusing this slope (a fraction of width per side, expected < 1) with an angle in radians/degrees or a ratio like height/width; computing slope dynamically from dimensions so it can exceed 1 for tall narrow shapes.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
AI-assisted analysis of liabru/matter-js@acb99b6f87 (2026-09-02).
Data as JSON: /api/errors/e8e8cef02cfef125.
Report an issue: GitHub.