getIndex

get index of element in 1-dim array by N-dim coordinate

coord_t
getIndex
pure
(
A
B
)
(
in A[] size
,
in B[] crd
)
if (
isIntegral!A &&
isIntegral!B
)
in { assert (size.length == crd.length, "array length mismatch"); assert (isAllCompPositive(size), "negative size"); assert (isAllCompPositive(crd), "negative coordinate"); assert (all!"a[0]>a[1]"(zip(size, crd)), "range violation"); }

Parameters

size
Type: A[]

N-dim array of sizes by each dimension

crd
Type: B[]

N-dim array of coordinates in N-dim space

Return Value

Type: coord_t

index in 1-dim array

Examples

assertEq( getIndex( [3,3], [1,1] ), 4 );
assertEq( getIndex( [4,3], [1,1] ), 5 );
assertEq( getIndex( [3,3,3], [1,1,1] ), 13 );

Meta