apply method

Offset apply(
  1. Offset o,
  2. {required double width,
  3. required double height}
)

convert offset in topleft to others

Implementation

Offset apply(
  Offset o, {
  required double width,
  required double height,
}) {
  var v = this.toInt();
  if (v == null) return o;

  var dx = o.dx;
  var dy = o.dy;

  var halfWidth = width / 2;
  var halfHeight = height / 2;

  // calcute the x: & 0000 1111 = 15
  // 3 1 5 => -1 0 1 => 0 1 2
  // dx += ((v&15) / 2) * halfWidth;
  // if (v&15 == 1) {
  //   dx += halfWidth;
  // } else if (v&15 == 2) {
  //   dx += width;
  // }

  // // calcute the y: & 1111 0000 = 240
  // // 48 16 80 => 0 1 2
  // dy += ((v&240) / 2) * halfHeight;

  return Offset(dx, dy);
}