{"record":{"id":"aeabaa132a7e7749","repo":"TheAlgorithms/JavaScript","slug":"imagewidth-should-be-greater-than-zero","errorCode":null,"errorMessage":"imageWidth should be greater than zero","messagePattern":"imageWidth should be greater than zero","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"Maths/Mandelbrot.js","lineNumber":40,"sourceCode":" * @param {number} imageHeight The height of the rendered image.\n * @param {number} figureCenterX The x-coordinate of the center of the figure.\n * @param {number} figureCenterY The y-coordinate of the center of the figure.\n * @param {number} figureWidth The width of the figure.\n * @param {number} maxStep Maximum number of steps to check for divergent behavior.\n * @param {boolean} useDistanceColorCoding Render in color or black and white.\n * @return {object} The RGB-data of the rendered Mandelbrot set.\n */\nexport function getRGBData(\n  imageWidth = 800,\n  imageHeight = 600,\n  figureCenterX = -0.6,\n  figureCenterY = 0,\n  figureWidth = 3.2,\n  maxStep = 50,\n  useDistanceColorCoding = true\n) {\n  if (imageWidth <= 0) {\n    throw new Error('imageWidth should be greater than zero')\n  }\n\n  if (imageHeight <= 0) {\n    throw new Error('imageHeight should be greater than zero')\n  }\n\n  if (maxStep <= 0) {\n    throw new Error('maxStep should be greater than zero')\n  }\n\n  const rgbData = []\n  const figureHeight = (figureWidth / imageWidth) * imageHeight\n\n  // loop through the image-coordinates\n  for (let imageX = 0; imageX < imageWidth; imageX++) {\n    rgbData[imageX] = []\n    for (let imageY = 0; imageY < imageHeight; imageY++) {\n      // determine the figure-coordinates based on the image-coordinates","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/Maths/Mandelbrot.js#L22-L58","documentation":"The getRGBData function renders the Mandelbrot set as RGB pixel data. imageWidth must be positive because it determines the number of horizontal pixels in the output. Zero or negative width produces an empty or invalid image buffer.","triggerScenarios":"Calling getRGBData(0, 600) or getRGBData(-800, 600). Any imageWidth <= 0 triggers this error before imageHeight or maxStep are checked.","commonSituations":"Zero from a division result, negative from a subtraction, reading dimensions from a config that was not set, or a default value overridden by invalid user input.","solutions":["Pass a positive integer for imageWidth.","Validate dimensions are > 0 before calling getRGBData.","Provide a fallback default when config values for image size are missing or invalid."],"exampleFix":"// before\ngetRGBData(parsedWidth, parsedHeight)\n// after\nif (parsedWidth <= 0 || parsedHeight <= 0) throw new RangeError('dimensions must be positive')\ngetRGBData(parsedWidth, parsedHeight)","handlingStrategy":"validation","validationCode":"if (typeof imageWidth !== 'number' || imageWidth <= 0) {\n  throw new RangeError('imageWidth must be a positive number')\n}\ngetRGBData(imageWidth, imageHeight, figureCenterX, figureCenterY, figureWidth, maxStep, useDistanceColorCoding)","typeGuard":"const isPositiveDimension = (d) => typeof d === 'number' && d > 0","tryCatchPattern":null,"preventionTips":["Validate image dimensions are > 0 before rendering.","Provide sensible fallback defaults when config values for size are missing.","Check all positional arguments since getRGBData has 7 parameters."],"tags":["math","rendering","precondition","fractal"],"backgroundTag":null,"analyzedSha":"5c39e87a9a31f279c60f830ad74a845e4788a517","analyzedAt":"2026-08-13T04:54:54.474Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}