package com.mojang.math;

import net.minecraft.util.Mth;

public class Vector4f {
    private float x;
    private float y;
    private float z;
    private float w;
    
    public Vector4f() {
    }
    
    public Vector4f(final float float1, final float float2, final float float3, final float float4) {
        this.x = float1;
        this.y = float2;
        this.z = float3;
        this.w = float4;
    }
    
    public Vector4f(final Vector3f e) {
        this(e.x(), e.y(), e.z(), 1.0f);
    }
    
    @Override
    public boolean equals(final Object object) {
        if (this == object) {
            return true;
        }
        if (object == null || this.getClass() != object.getClass()) {
            return false;
        }
        final Vector4f f3 = (Vector4f)object;
        return Float.compare(f3.x, this.x) == 0 && Float.compare(f3.y, this.y) == 0 && Float.compare(f3.z, this.z) == 0 && Float.compare(f3.w, this.w) == 0;
    }
    
    @Override
    public int hashCode() {
        int integer2 = Float.floatToIntBits(this.x);
        integer2 = 31 * integer2 + Float.floatToIntBits(this.y);
        integer2 = 31 * integer2 + Float.floatToIntBits(this.z);
        integer2 = 31 * integer2 + Float.floatToIntBits(this.w);
        return integer2;
    }
    
    public float x() {
        return this.x;
    }
    
    public float y() {
        return this.y;
    }
    
    public float z() {
        return this.z;
    }
    
    public float w() {
        return this.w;
    }
    
    public void mul(final Vector3f e) {
        this.x *= e.x();
        this.y *= e.y();
        this.z *= e.z();
    }
    
    public void set(final float float1, final float float2, final float float3, final float float4) {
        this.x = float1;
        this.y = float2;
        this.z = float3;
        this.w = float4;
    }
    
    public float dot(final Vector4f f) {
        return this.x * f.x + this.y * f.y + this.z * f.z + this.w * f.w;
    }
    
    public boolean normalize() {
        final float float2 = this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
        if (float2 < 1.0E-5) {
            return false;
        }
        final float float3 = Mth.fastInvSqrt(float2);
        this.x *= float3;
        this.y *= float3;
        this.z *= float3;
        this.w *= float3;
        return true;
    }
    
    public void transform(final Matrix4f b) {
        final float float3 = this.x;
        final float float4 = this.y;
        final float float5 = this.z;
        final float float6 = this.w;
        this.x = b.m00 * float3 + b.m01 * float4 + b.m02 * float5 + b.m03 * float6;
        this.y = b.m10 * float3 + b.m11 * float4 + b.m12 * float5 + b.m13 * float6;
        this.z = b.m20 * float3 + b.m21 * float4 + b.m22 * float5 + b.m23 * float6;
        this.w = b.m30 * float3 + b.m31 * float4 + b.m32 * float5 + b.m33 * float6;
    }
    
    public void transform(final Quaternion c) {
        final Quaternion c2 = new Quaternion(c);
        c2.mul(new Quaternion(this.x(), this.y(), this.z(), 0.0f));
        final Quaternion c3 = new Quaternion(c);
        c3.conj();
        c2.mul(c3);
        this.set(c2.i(), c2.j(), c2.k(), this.w());
    }
    
    public void perspectiveDivide() {
        this.x /= this.w;
        this.y /= this.w;
        this.z /= this.w;
        this.w = 1.0f;
    }
    
    @Override
    public String toString() {
        return "[" + this.x + ", " + this.y + ", " + this.z + ", " + this.w + "]";
    }
}
