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

package com.hypixel.hytale.procedurallib.random;

import com.hypixel.hytale.procedurallib.property.NoiseProperty;
import javax.annotation.Nonnull;
import java.util.Arrays;

public class CoordinateRandomizer implements ICoordinateRandomizer
{
    public static final ICoordinateRandomizer EMPTY_RANDOMIZER;
    protected final AmplitudeNoiseProperty[] xNoise;
    protected final AmplitudeNoiseProperty[] yNoise;
    protected final AmplitudeNoiseProperty[] zNoise;
    
    public CoordinateRandomizer(final AmplitudeNoiseProperty[] xNoise, final AmplitudeNoiseProperty[] yNoise, final AmplitudeNoiseProperty[] zNoise) {
        this.xNoise = xNoise;
        this.yNoise = yNoise;
        this.zNoise = zNoise;
    }
    
    public AmplitudeNoiseProperty[] getXNoise() {
        return this.xNoise;
    }
    
    public AmplitudeNoiseProperty[] getYNoise() {
        return this.yNoise;
    }
    
    public AmplitudeNoiseProperty[] getZNoise() {
        return this.zNoise;
    }
    
    @Override
    public double randomDoubleX(final int seed, final double x, final double y) {
        double offsetX = 0.0;
        for (final AmplitudeNoiseProperty property : this.xNoise) {
            offsetX += (property.property.get(seed, x, y) * 2.0 - 1.0) * property.amplitude;
        }
        return x + offsetX;
    }
    
    @Override
    public double randomDoubleY(final int seed, final double x, final double y) {
        double offsetY = 0.0;
        for (final AmplitudeNoiseProperty property : this.yNoise) {
            offsetY += (property.property.get(seed, x, y) * 2.0 - 1.0) * property.amplitude;
        }
        return y + offsetY;
    }
    
    @Override
    public double randomDoubleX(final int seed, final double x, final double y, final double z) {
        double offsetX = 0.0;
        for (final AmplitudeNoiseProperty property : this.xNoise) {
            offsetX += (property.property.get(seed, x, y, z) * 2.0 - 1.0) * property.amplitude;
        }
        return x + offsetX;
    }
    
    @Override
    public double randomDoubleY(final int seed, final double x, final double y, final double z) {
        double offsetY = 0.0;
        for (final AmplitudeNoiseProperty property : this.yNoise) {
            offsetY += (property.property.get(seed, x, y, z) * 2.0 - 1.0) * property.amplitude;
        }
        return y + offsetY;
    }
    
    @Override
    public double randomDoubleZ(final int seed, final double x, final double y, final double z) {
        double offsetZ = 0.0;
        for (final AmplitudeNoiseProperty property : this.zNoise) {
            offsetZ += (property.property.get(seed, x, y, z) * 2.0 - 1.0) * property.amplitude;
        }
        return z + offsetZ;
    }
    
    @Nonnull
    @Override
    public String toString() {
        return "CoordinateRandomizer{xNoise=" + Arrays.toString(this.xNoise) + ", yNoise=" + Arrays.toString(this.yNoise) + ", zNoise=" + Arrays.toString(this.zNoise);
    }
    
    static {
        EMPTY_RANDOMIZER = new EmptyCoordinateRandomizer();
    }
    
    public static class AmplitudeNoiseProperty
    {
        protected NoiseProperty property;
        protected double amplitude;
        
        public AmplitudeNoiseProperty(final NoiseProperty property, final double amplitude) {
            this.property = property;
            this.amplitude = amplitude;
        }
        
        public NoiseProperty getProperty() {
            return this.property;
        }
        
        public void setProperty(final NoiseProperty property) {
            this.property = property;
        }
        
        public double getAmplitude() {
            return this.amplitude;
        }
        
        public void setAmplitude(final double amplitude) {
            this.amplitude = amplitude;
        }
        
        @Nonnull
        @Override
        public String toString() {
            return "AmplitudeNoiseProperty{property=" + String.valueOf(this.property) + ", amplitude=" + this.amplitude;
        }
    }
    
    private static class EmptyCoordinateRandomizer implements ICoordinateRandomizer
    {
        @Override
        public double randomDoubleX(final int seed, final double x, final double y) {
            return x;
        }
        
        @Override
        public double randomDoubleY(final int seed, final double x, final double y) {
            return y;
        }
        
        @Override
        public double randomDoubleX(final int seed, final double x, final double y, final double z) {
            return x;
        }
        
        @Override
        public double randomDoubleY(final int seed, final double x, final double y, final double z) {
            return y;
        }
        
        @Override
        public double randomDoubleZ(final int seed, final double x, final double y, final double z) {
            return z;
        }
        
        @Nonnull
        @Override
        public String toString() {
            return "EmptyCoordinateRandomizer{}";
        }
    }
}
