scalePosition<C extends num> function
Returns a function to scale positions by scale factors for each axis.
Set optional sx
, sy
, sz
and sm
scale factors for scaling on a
corresponding axis.
If a point to be scaled do not have an axis even if a scale factor for that axis is given, then such factor is ignored.
Implementation
TransformPosition scalePosition<C extends num>({
C? sx,
C? sy,
C? sz,
C? sm,
}) =>
<T extends Position>(T source) {
final dim = source.coordinateDimension;
if (dim == 2) {
// point is (X, Y)
return source.copyWith(
x: sx != null ? sx * source.x : null,
y: sy != null ? sy * source.y : null,
) as T;
} else {
// point could be (X, Y, Z), (X, Y, M) or (X, Y, Z, M)
return source.copyWith(
x: sx != null ? sx * source.x : null,
y: sy != null ? sy * source.y : null,
z: sz != null && source.is3D ? sz * source.z : null,
m: sm != null && source.isMeasured ? sm * source.m : null,
) as T;
}
};