{"record":{"id":"e8e8cef02cfef125","repo":"liabru/matter-js","slug":"bodies-trapezoid-slope-parameter-must-be-1","errorCode":null,"errorMessage":"Bodies.trapezoid: slope parameter must be < 1.","messagePattern":"Bodies\\.trapezoid: slope parameter must be < 1\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/factory/Bodies.js","lineNumber":73,"sourceCode":"    /**\n     * Creates a new rigid body model with a trapezoid hull. \n     * The `slope` is parameterised as a fraction of `width` and must be < 1 to form a valid trapezoid. \n     * The options parameter is an object that specifies any properties you wish to override the defaults.\n     * See the properties section of the `Matter.Body` module for detailed information on what you can pass via the `options` object.\n     * @method trapezoid\n     * @param {number} x\n     * @param {number} y\n     * @param {number} width\n     * @param {number} height\n     * @param {number} slope Must be a number < 1.\n     * @param {object} [options]\n     * @return {body} A new trapezoid body\n     */\n    Bodies.trapezoid = function(x, y, width, height, slope, options) {\n        options = options || {};\n\n        if (slope >= 1) {\n            Common.warn('Bodies.trapezoid: slope parameter must be < 1.');\n        }\n\n        slope *= 0.5;\n        var roof = (1 - (slope * 2)) * width;\n        \n        var x1 = width * slope,\n            x2 = x1 + roof,\n            x3 = x2 + x1,\n            verticesPath;\n\n        if (slope < 0.5) {\n            verticesPath = 'L 0 0 L ' + x1 + ' ' + (-height) + ' L ' + x2 + ' ' + (-height) + ' L ' + x3 + ' 0';\n        } else {\n            verticesPath = 'L 0 0 L ' + x2 + ' ' + (-height) + ' L ' + x3 + ' 0';\n        }\n\n        var trapezoid = { \n            label: 'Trapezoid Body',","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/liabru/matter-js/blob/acb99b6f8784c809b940f1d2cf745427e088e088/src/factory/Bodies.js#L55-L91","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nBodies.trapezoid(x, y, 100, 60, 1.2);\n// after\nBodies.trapezoid(x, y, 100, 60, Math.min(1.2, 0.9));","handlingStrategy":"validation","validationCode":"if (typeof slope !== 'number' || !(slope < 1)) {\n  throw new RangeError('Bodies.trapezoid slope must be a number < 1');\n}","typeGuard":"function isValidSlope(s) {\n  return typeof s === 'number' && Number.isFinite(s) && s < 1;\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["geometry","parameter-validation","bodies"],"backgroundTag":"invalid-argument-value","analyzedSha":"acb99b6f8784c809b940f1d2cf745427e088e088","analyzedAt":"2026-09-02T21:29:27.057Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}