SimpleFlips.fromFlips constructor

SimpleFlips.fromFlips(
  1. Flips flips
)

This is the conversion from the truth table that I drew.

Implementation

factory SimpleFlips.fromFlips(Flips flips) {
  final int angle;
  final int cos;
  final int sin;
  final bool flip;

  if (!flips.diagonally && !flips.vertically && !flips.horizontally) {
    angle = 0;
    cos = 1;
    sin = 0;
    flip = false;
  } else if (!flips.diagonally && !flips.vertically && flips.horizontally) {
    angle = 0;
    cos = 1;
    sin = 0;
    flip = true;
  } else if (flips.diagonally && !flips.vertically && flips.horizontally) {
    angle = 1;
    cos = 0;
    sin = 1;
    flip = false;
  } else if (flips.diagonally && flips.vertically && flips.horizontally) {
    angle = 1;
    cos = 0;
    sin = 1;
    flip = true;
  } else if (!flips.diagonally && flips.vertically && flips.horizontally) {
    angle = 2;
    cos = -1;
    sin = 0;
    flip = false;
  } else if (!flips.diagonally && flips.vertically && !flips.horizontally) {
    angle = 2;
    cos = -1;
    sin = 0;
    flip = true;
  } else if (flips.diagonally && flips.vertically && !flips.horizontally) {
    angle = 3;
    cos = 0;
    sin = -1;
    flip = false;
  } else if (flips.diagonally && !flips.vertically && !flips.horizontally) {
    angle = 3;
    cos = 0;
    sin = -1;
    flip = true;
  } else {
    // this should be exhaustive
    throw 'Invalid combination of booleans: $flips';
  }

  return SimpleFlips(angle, cos, sin, flip: flip);
}