Segmentspan

Method

A union of spans,
with every gap intact.

Each row is one continuous closed interval [start,end]. The result lists their ascending separated union components and exact length totals.

The small input language

Write one pair of plain decimal coordinates per row, separated by exactly one comma. There is no header, quote syntax, thousands separator, comment or unit suffix. Outer ASCII spaces and tabs around fields are ignored. Use 0.5 rather than .5, an optional minus rather than a plus sign, and no exponent.

Coordinates accept up to twelve fractional digits and must lie between -1000000000 and1000000000 inclusive. Leading zeros are accepted and negative zero becomes zero. Start must not exceed end. A reversed pair rejects rather than silently swapping. Errors identify the row and, where applicable, start or end field.

LF and CRLF endings are accepted. Empty rows created solely by final line terminators are removed. A blank row before or between pairs rejects. A spaces/tabs-only row also rejects, even at the end. Lone CR, Unicode whitespace substitutes and a leading BOM are outside this input language. A browser textarea may normalize pasted line endings before the script receives them.

Closed and continuous

A closed interval includes its endpoints. [1,2] and [2,3] touch at2, so their union is [1,3], length2. The included endpoint has zero continuous length; this is not an integer item count that adds one for an endpoint.

[3,3] is a valid point with zero length. A point inside another component is already included. An isolated point outside every other segment remains its own zero-length component, while duplicate identical points merge. A zero total length need not represent an empty set.

Union, rather than a containing hull

The algorithm sorts accepted pairs by start and then end. It starts a new component only when the next start is strictly greater than the current end. Otherwise the pair overlaps or touches, and the end extends to the greater end. Every positive gap remains, however small at accepted precision.

Reporting only the earliest start and latest end would instead give a containing hull. For [1,2] and [3,5], that hull is [1,5], length4. The actual union has two components with covered length3. Segmentspan reports the union.

Exact decimal lengths

Accepted decimals become signed BigInt integers at a scale of10^12. Comparisons, subtraction and additions use those exact integers. Binary floating-point addition, display rounding and overlap tolerances do not decide whether endpoints touch. A gap of0.000000000001 remains positive.

Each component length is end minus start. Union covered length adds those lengths; raw summed length adds the lengths of all input rows, including duplicates. Points add zero. Coordinates must share your chosen unit. If coordinates use centimetres, lengths also use centimetres; the calculator performs no conversion.

What multiplicity excess means

Multiplicity excess is raw summed length minus union covered length. It measures extra counted length when the rows are added separately. It is not generally the length of the region covered at least twice. Three copies of [0,2] have raw length6, union length2 and excess4; their multiply covered region itself has length2.

This distinction matters with three or more overlaps. The tool does not produce a coverage-depth map, a double-covered-length result or a waste estimate. It does not identify material that can safely be removed or establish the accuracy of a measurement.

Explicit bounds

Calculate, edit, page and export

Calculate coverage validates every row before success. A bad row prevents a partial result. Every input edit hides old totals/components, disables exports and clears old copy fallback text. Reset example restores and recalculates the original three pairs.

The table shows100 components per page. Previous and Next preserve ascending order. Grand totals and complete text/JSON reports include every component, including later pages and isolated points. Copy complete notes requests clipboard access only after you choose it; on failure a local text box offers manual copying. A delayed response cannot relabel an edited or reset result as current.

Primary reference context

Official PostgreSQL Range Types discusses inclusive endpoints and differences between continuous and discrete semantics. Its Range and Multirange Functions and Operators distinguish disjoint unions from a containing range merge. These are mathematical/database context, not dependencies or SQL syntax supported here.

The input grammar, bounds, closed-only convention, exact arithmetic and interface are product choices. See the original examples or return to the calculator.