package csa.tiletools.worldgen.mapgen.miny.render.BB;

import csa.tiletools.worldgen.mapgen.processing.CSAProcessing;

public class LineBB
  implements BoundingBox
{
  private float ca;
  private float sa;
  private float lw;
  private float w;
  private float lx;
  private float ly;
  private float l;
  private float t;
  private float r;
  private float b;

  public LineBB(float paramFloat1, float paramFloat2, float paramFloat3, float paramFloat4, float paramFloat5)
  {
    this.w = paramFloat5;
    this.lw = (CSAProcessing.dist(paramFloat1, paramFloat2, paramFloat3, paramFloat4) / 2.0F);
    this.lx = ((paramFloat1 + paramFloat3) / 2.0F);
    this.ly = ((paramFloat2 + paramFloat4) / 2.0F);
    float f = CSAProcessing.atan2(paramFloat4 - paramFloat2, paramFloat3 - paramFloat1);
    this.ca = CSAProcessing.cos(f);
    this.sa = CSAProcessing.sin(f);
    this.l = (CSAProcessing.min(paramFloat1, paramFloat3) - paramFloat5);
    this.r = (CSAProcessing.max(paramFloat1, paramFloat3) + paramFloat5);
    this.t = (CSAProcessing.min(paramFloat2, paramFloat4) - paramFloat5);
    this.b = (CSAProcessing.max(paramFloat2, paramFloat4) + paramFloat5);
  }

    @Override
  public boolean overlap(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    float f1 = (paramInt1 + paramInt3) / 2;
    float f2 = (paramInt2 + paramInt4) / 2;
    float f3 = CSAProcessing.max(paramInt3 - f1, paramInt4 - f2) * 1.414214F;
    float f4 = (f1 - this.lx) * this.ca + (f2 - this.ly) * this.sa;
    float f5 = -(f1 - this.lx) * this.sa + (f2 - this.ly) * this.ca;
    return (f4 >= -this.lw - this.w - f3) && (f4 <= this.lw + this.w + f3) && (f5 >= -this.w - f3) && (f5 <= this.w + f3);
  }

    @Override
  public BBRect getExtends()
  {
    return new BBRect(this.l, this.t, this.r, this.b);
  }
}

