scalePosition<C extends num> function

TransformPosition scalePosition<C extends num>({
  1. C? sx,
  2. C? sy,
  3. C? sz,
  4. C? sm,
})

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;
      }
    };