import 'dart:math';

import './vector.dart';

double _toRadians(num deg) {
  return (deg * pi) / 180.0;
}

class Rectangle {
  final double x1;
  final double y1;
  late double x2;
  late double y2;
  late double angle;

  Rectangle(this.x1, this.y1, double x2, double y2) {
    angle = atan((y2 - y1) / (x2 - x1));
    Vector v = Vector(x2 - x1, y2 - y1);
    v.normalize();
    v.rotate(_toRadians(90.0));
    v = v.translate(x2, y2, 50.0);
    x2 = v.x;
    y2 = v.y;
  }

  bool collides(Rectangle b) {
    if (x2 < b.x1 || b.x2 < x1) return false;
    if (y2 < b.y1 || b.y2 < y1) return false;
    return true;
  }

  Vector get vector {
    return Vector(x2 - x1, y2 - y1);
  }
}
