Function sum
Strictly sums one selected logical raster plane into an explicitly selected accumulator type.
RasterSumResult!Accumulator sum(Accumulator, Sample)(
scope RasterView!Sample source,
size_t planeIndex
) nothrow @nogc @safe
if (isSupportedRasterSumPair!(Sample, Accumulator));
Call forms:
auto result = sum!double(source, planeIndex); auto result = source.sum!double(planeIndex);
Accumulator selection is mandatory. There is no implicit default widening.
Legal Sample -> Accumulator pairs require every possible Sample value to be exactly representable in Accumulator.
Integer samples and accumulators:
- signed -> signed when Accumulator is at least as wide; - unsigned -> unsigned when Accumulator is at least as wide; - unsigned -> signed only when Accumulator is strictly wider; - signed -> unsigned is rejected.
Floating samples and accumulators:
- float -> float; - float -> double; - double -> double.
Integer/floating cross-family accumulation and real are rejected.
Numerical semantics:
- logical traversal is strict row-major order; - integer addition is checked before commit and fails on accumulator overflow; - floating addition uses ordinary D/IEEE arithmetic in Accumulator; - NaN and infinity participate normally; - valid empty input succeeds with the additive identity; - invalid plane selection fails; - failure never exposes a partial sum as the result value.
Physical layout does not change logical order. All validated resident signed affine layouts are semantically supported.
The operation allocates nothing, retains no source, and performs no hidden parallel/tree reassociation.
The float -> double specialization reuses the already-qualified v0.1 strict engine so the generic API does not regress that established path.
Example
Example compiling ordinary and UFCS generic strict sum forms.
import raster;
RasterView!float source;
const ordinary =
sum!double(
source,
0
);
const ufcs =
source .sum!double(
0
);
assert(!ordinary .ok);
assert(!ufcs .ok);
assert(
ordinary .error
== RasterSumError .invalidPlane
);
assert(ufcs .error == ordinary .error);