TheAlgorithms/JavaScript · error · Error
maxStep should be greater than zero
Error message
maxStep should be greater than zero
What it means
In getRGBData, maxStep is the maximum number of Mandelbrot iterations per pixel. It must be positive because zero or negative means no iterations are performed, producing meaningless all-black or undefined output. This check fires last, after imageWidth and imageHeight.
Source
Thrown at Maths/Mandelbrot.js:48
export function getRGBData(
imageWidth = 800,
imageHeight = 600,
figureCenterX = -0.6,
figureCenterY = 0,
figureWidth = 3.2,
maxStep = 50,
useDistanceColorCoding = true
) {
if (imageWidth <= 0) {
throw new Error('imageWidth should be greater than zero')
}
if (imageHeight <= 0) {
throw new Error('imageHeight should be greater than zero')
}
if (maxStep <= 0) {
throw new Error('maxStep should be greater than zero')
}
const rgbData = []
const figureHeight = (figureWidth / imageWidth) * imageHeight
// loop through the image-coordinates
for (let imageX = 0; imageX < imageWidth; imageX++) {
rgbData[imageX] = []
for (let imageY = 0; imageY < imageHeight; imageY++) {
// determine the figure-coordinates based on the image-coordinates
const figureX = figureCenterX + (imageX / imageWidth - 0.5) * figureWidth
const figureY =
figureCenterY + (imageY / imageHeight - 0.5) * figureHeight
const distance = getDistance(figureX, figureY, maxStep)
// color the corresponding pixel based on the selected coloring-function
rgbData[imageX][imageY] = useDistanceColorCodingView on GitHub (pinned to 5c39e87a9a)
Solutions
- Pass a positive integer for maxStep (the default is 50).
- Validate maxStep > 0 before calling.
- Be careful with positional arguments since getRGBData has 7 parameters.
Example fix
// before getRGBData(800, 600, -0.6, 0, 3.2, 0) // after getRGBData(800, 600, -0.6, 0, 3.2, 50)
Defensive patterns
Strategy: validation
Validate before calling
if (typeof maxStep !== 'number' || maxStep <= 0) {
throw new RangeError('maxStep must be a positive number')
}
getRGBData(imageWidth, imageHeight, figureCenterX, figureCenterY, figureWidth, maxStep, useDistanceColorCoding) Type guard
const isPositiveMaxStep = (s) => typeof s === 'number' && s > 0
Prevention
- Validate maxStep > 0 before calling, using the default of 50 as a reference.
- Be careful with positional arguments since getRGBData has 7 parameters.
- Avoid passing quality factors that can evaluate to zero or negative values.
When it happens
Trigger: Calling getRGBData(800, 600, -0.6, 0, 3.2, 0) or getRGBData(800, 600, -0.6, 0, 3.2, -50). Any maxStep <= 0 triggers this error (assuming width and height are valid).
Common situations: maxStep read from a config that defaults to 0, computed from a quality factor that evaluated to a non-positive number, or accidentally passing the wrong positional argument.
Related errors
- imageWidth should be greater than zero
- imageHeight should be greater than zero
- Number must be greater than zero.
- Number must be greater than zero.
- Number must be greater than zero.
AI-assisted analysis of TheAlgorithms/JavaScript@5c39e87a9a (2026-08-13).
Data as JSON: /api/errors/27e635e11be5eb6f.
Report an issue: GitHub.