// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.procedurallib.random;

import com.hypixel.hytale.math.util.TrigMathUtil;
import javax.annotation.Nonnull;

public class CoordinateRotator implements ICoordinateRandomizer
{
    public static final CoordinateRotator NONE;
    public static final int X0 = 0;
    public static final int Y0 = 1;
    public static final int Z0 = 2;
    public static final int X1 = 3;
    public static final int Y1 = 4;
    public static final int Z1 = 5;
    public static final int X2 = 6;
    public static final int Y2 = 7;
    public static final int Z2 = 8;
    protected final double pitch;
    protected final double yaw;
    @Nonnull
    protected final double[] matrix;
    
    public CoordinateRotator(final double pitch, final double yaw) {
        this.pitch = pitch;
        this.yaw = yaw;
        this.matrix = createRotationMatrix(pitch, yaw);
    }
    
    public double rotateX(final double x, final double y) {
        return x * this.matrix[0] + y * this.matrix[2];
    }
    
    public double rotateY(final double x, final double y) {
        return x * this.matrix[6] + y * this.matrix[8];
    }
    
    public double rotateX(final double x, final double y, final double z) {
        return x * this.matrix[0] + y * this.matrix[1] + z * this.matrix[2];
    }
    
    public double rotateY(final double x, final double y, final double z) {
        return x * this.matrix[3] + y * this.matrix[4] + z * this.matrix[5];
    }
    
    public double rotateZ(final double x, final double y, final double z) {
        return x * this.matrix[6] + y * this.matrix[7] + z * this.matrix[8];
    }
    
    @Override
    public double randomDoubleX(final int seed, final double x, final double y) {
        return this.rotateX(x, y);
    }
    
    @Override
    public double randomDoubleY(final int seed, final double x, final double y) {
        return this.rotateY(x, y);
    }
    
    @Override
    public double randomDoubleX(final int seed, final double x, final double y, final double z) {
        return this.rotateX(x, y, z);
    }
    
    @Override
    public double randomDoubleY(final int seed, final double x, final double y, final double z) {
        return this.rotateY(x, y, z);
    }
    
    @Override
    public double randomDoubleZ(final int seed, final double x, final double y, final double z) {
        return this.rotateZ(x, y, z);
    }
    
    @Nonnull
    @Override
    public String toString() {
        return "CoordinateRotator{pitch=" + this.pitch + ", yaw=" + this.yaw;
    }
    
    public static double[] createRotationMatrix(final double pitch, final double yaw) {
        final double sinYaw = TrigMathUtil.sin(yaw);
        final double cosYaw = TrigMathUtil.cos(yaw);
        final double sinPitch = TrigMathUtil.sin(pitch);
        final double cosPitch = TrigMathUtil.cos(pitch);
        final double px1 = 1.0;
        final double px2 = 0.0;
        final double px3 = 0.0;
        final double py1 = 0.0;
        final double py2 = cosPitch;
        final double py3 = -sinPitch;
        final double pz1 = 0.0;
        final double pz2 = sinPitch;
        final double pz3 = cosPitch;
        final double yx1 = cosYaw;
        final double yx2 = 0.0;
        final double yx3 = sinYaw;
        final double yy1 = 0.0;
        final double yy2 = 1.0;
        final double yy3 = 0.0;
        final double yz1 = -sinYaw;
        final double yz2 = 0.0;
        final double yz3 = cosYaw;
        return new double[] { dot(px1, px2, px3, yx1, yy1, yz1), dot(px1, px2, px3, yx2, yy2, yz2), dot(px1, px2, px3, yx3, yy3, yz3), dot(py1, py2, py3, yx1, yy1, yz1), dot(py1, py2, py3, yx2, yy2, yz2), dot(py1, py2, py3, yx3, yy3, yz3), dot(pz1, pz2, pz3, yx1, yy1, yz1), dot(pz1, pz2, pz3, yx2, yy2, yz2), dot(pz1, pz2, pz3, yx3, yy3, yz3) };
    }
    
    private static double dot(final double x1, final double y1, final double z1, final double x2, final double y2, final double z2) {
        return x1 * x2 + y1 * y2 + z1 * z2;
    }
    
    static {
        NONE = new CoordinateRotator(0.0, 0.0);
    }
}
