import 'matrix.dart';
import 'point.dart';

class DSkewTransform {
  DMatrix _matrix = DMatrix();

  DSkewTransform._();

  factory DSkewTransform(
    double angleX,
    double angleY,
    double centerX,
    double centerY,
  ) {
    final st = DSkewTransform._();
    bool flag = (centerX != 0.0) || !(centerY == 0.0);
    if (flag) {
      st._matrix.translate(-centerX, -centerY);
    }
    st._matrix.skew(angleX, angleY);
    if (flag) {
      st._matrix.translate(centerX, centerY);
    }
    return st;
  }

  factory DSkewTransform.withMatrix(DMatrix matrix) {
    final st = DSkewTransform._();
    st._matrix = matrix;
    return st;
  }

  DSkewTransform get inverse {
    final inversedMatrix = _matrix..invert();
    final st = DSkewTransform.withMatrix(inversedMatrix);
    return st;
  }

  DPoint transform(DPoint point) {
    return _matrix.transformWidthPoint(point);
  }
}
