"use strict"; function round2(x) { return Math.round(x * 100) / 100; } module.exports = { slug: "rectangle-room-paint-coverage", title: "Paint needed for a rectangular room", deck_category: "geometry", description: "Computes the liters of paint needed to cover a rectangular room's walls, given openings, number of coats, and coverage per liter.", inputs: [ { name: "length", type: "number", unit: "meters", required: true, description: "Room length.", min: 0 }, { name: "width", type: "number", unit: "meters", required: true, description: "Room width.", min: 0 }, { name: "height", type: "number", unit: "meters", required: true, description: "Wall height.", min: 0 }, { name: "openings_area", type: "number", unit: "square meters", required: true, description: "Total area of doors and windows to subtract.", min: 0 }, { name: "coats", type: "integer", unit: "coats", required: true, description: "Number of coats of paint to apply.", min: 1 }, { name: "coverage_per_liter", type: "number", unit: "square meters per liter", required: true, description: "Manufacturer-stated coverage of the paint, one coat.", min: 0 } ], outputs: [ { name: "wall_area", unit: "square meters", description: "Net paintable wall area, one coat." }, { name: "paint_needed_liters", unit: "liters", description: "Total paint needed for all coats." } ], steps: [ "Wall perimeter = 2 * (length + width).", "Gross wall area = perimeter * height.", "Net wall area = gross wall area - openings_area.", "Paint needed (liters) = net wall area * coats / coverage_per_liter.", "Round both outputs to 2 decimals." ], constants: [], sources: [ { kind: "url", value: "https://www.thisoldhouse.com/painting/21097077/how-much-paint-do-i-need", title: "Paint Calculator: How Much Paint Do I Need?", publisher: "This Old House", retrieved_utc: "2026-09-30T22:29:13Z", note: "Confirms the standard method: wall area (perimeter times height, minus openings) times number of coats, divided by the paint's stated coverage rate per gallon/liter." } ], disclaimer: null, questionText(inputs) { return `How many liters of paint are needed for a ${inputs.length}m by ${inputs.width}m room with ${inputs.height}m walls, ${inputs.openings_area} square meters of openings, ${inputs.coats} coat(s), and paint that covers ${inputs.coverage_per_liter} square meters per liter?`; }, run(inputs) { const { length, width, height, openings_area, coats, coverage_per_liter } = inputs || {}; for (const [name, v] of Object.entries({ length, width, height, openings_area, coverage_per_liter })) { if (typeof v !== "number" || v < 0) throw new Error(`${name} must be a non-negative number`); } if (typeof coats !== "number" || !Number.isInteger(coats) || coats < 1) throw new Error("coats must be a positive integer"); if (coverage_per_liter <= 0) throw new Error("coverage_per_liter must be positive"); const perimeter = 2 * (length + width); const grossArea = perimeter * height; const wallArea = grossArea - openings_area; if (wallArea < 0) throw new Error("openings_area exceeds the gross wall area"); const paintNeeded = (wallArea * coats) / coverage_per_liter; const wallAreaR = round2(wallArea); const paintNeededR = round2(paintNeeded); return { answer: `${paintNeededR.toFixed(2)} liters`, values: { wall_area: wallAreaR, paint_needed_liters: paintNeededR } }; }, examples: [ { name: "worked example", inputs: { length: 4, width: 3, height: 2.5, openings_area: 3, coats: 2, coverage_per_liter: 10 }, expected: { answer: "6.40 liters" }, check: "By hand: perimeter=2*(4+3)=14 m; gross wall area=14*2.5=35 sq m; net area=35-3=32 sq m; paint=32*2/10=6.4 liters." }, { name: "test vector: one coat", inputs: { length: 5, width: 5, height: 3, openings_area: 4, coats: 1, coverage_per_liter: 8 }, expected: { answer: "7.00 liters" }, check: "By hand: perimeter=2*(5+5)=20 m; gross wall area=20*3=60 sq m; net area=60-4=56 sq m; paint=56*1/8=7.00 liters." } ] };