Grid Coordinate Linear Index

Encode zero-based rectangular grid coordinates to a row-major list index.

Description

Encode zero-based rectangular grid coordinates to a row-major list index.

Row-major storage places each complete row before the next. Converting coordinates to a linear index helps align a two-dimensional grid with a flat list.

When to use this tool

Encode zero-based rectangular grid coordinates to a row-major list index.

  • Prepare the supplied row, column, rows, columns fields for this operation.
  • Compare the complete example with the representation used by your own input before carrying the result into another step.

How to use the tool and how it works

  1. Enter row, column, rows, columns. Use the exact text syntax, units and index conventions explained below.
  2. Run the tool. If input validation fails, correct the supplied fields before interpreting any result.
  3. Read result.index. Interpret false, null and empty lists using the distinctions below; they can be valid outputs.

Validate positive rows/columns and zero-based row/column coordinates within them. Return row*columns+column.1

Input fieldMeaning and representationAccepted input
rowrow.Integer from 0 to rows - 1 inclusive
columncolumn.Integer from 0 to columns - 1 inclusive
rowsrows.Integer from 1 to 1e6 inclusive
columnscolumns.Integer from 1 to 1e6 inclusive
Output fieldInterpretation
resultObject containing the named outputs below.
result.indexThe index value under the stated formula or text convention.
json
{
  "input": {
    "row": 1,
    "column": 2,
    "rows": 2,
    "columns": 3
  },
  "output": {
    "result": {
      "index": 5
    }
  }
}

Limitations and assumptions

  • The tool computes an index without allocating or reading a grid. Row-major order is assumed; x/y coordinates, column-major layouts and byte strides need separate conversion.
  • Every declared top-level field is required and unexpected fields are rejected. Numeric inputs must be finite; ordinary text fields are bounded to 8,192 UTF-16 code units, with tighter operation-specific limits where stated.
  • Ordinary string lists have at most 128 entries of at most 128 code units each; numeric lists and matrices have separate bounded size checks. Nonfinite results and excessively large serialized outputs are rejected.
  • Indexes are zero-based and spans have an exclusive end unless explicitly stated otherwise. A valid false, null or empty-list result is distinct from malformed input.

Alternative or Complementary methods

Use explicit source-index maps when rearranging data or planning missing-value fills. Keep row-major coordinates, cyclic indexes and one-based occurrence numbers distinct, and inspect null donor positions before copying values.

References

  1. Tool behavior and example: Grid Coordinate Linear Index — tool.io

Similar or alternative tools

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies