Function douglasPeuckerWorkspaceSize

Returns the maximum workspace length required by trySimplifyDouglasPeuckerInto() for a polyline containing pointCount stored points.

ulong douglasPeuckerWorkspaceSize(
  ulong pointCount
) pure nothrow @nogc @safe;

Empty, singleton, and two-point polylines require no auxiliary workspace.

For larger inputs, the iterative Douglas-Peucker implementation may defer at most one right-hand section for each intermediate input vertex.

Returns

max(pointCount - 2, 0)

No allocation is performed.

Complexity

O(1) time and O(1) auxiliary space.

Example

Example sizing caller-owned Douglas-Peucker workspace.

import geo;

static assert(
    douglasPeuckerWorkspaceSize(0) == 0
);

static assert(
    douglasPeuckerWorkspaceSize(2) == 0
);

static assert(
    douglasPeuckerWorkspaceSize(5) == 3
);

size_t[3] workspace;

assert(
    workspace.length ==
    douglasPeuckerWorkspaceSize(5)
);