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

package com.hypixel.hytale.procedurallib.logic;

import com.hypixel.hytale.math.util.MathUtil;
import com.hypixel.hytale.procedurallib.NoiseFunction;

public class PointNoise implements NoiseFunction
{
    private final double x;
    private final double y;
    private final double z;
    private final double innerRadius2;
    private final double outerRadius2;
    private final transient double invRange2;
    
    public PointNoise(final double x, final double y, final double z, final double innerRadius, final double outerRadius) {
        this.x = x;
        this.y = y;
        this.z = z;
        this.innerRadius2 = innerRadius * innerRadius;
        this.outerRadius2 = outerRadius * outerRadius;
        final double range = this.outerRadius2 - this.innerRadius2;
        this.invRange2 = ((range == 0.0) ? 1.0 : (1.0 / range));
    }
    
    @Override
    public double get(final int seed, final int seedOffset, final double x, final double y) {
        final double dist2 = MathUtil.lengthSquared(x - this.x, y - this.y);
        if (dist2 <= this.innerRadius2) {
            return -1.0;
        }
        if (dist2 >= this.outerRadius2) {
            return 1.0;
        }
        return -1.0 + 2.0 * (dist2 - this.innerRadius2) * this.invRange2;
    }
    
    @Override
    public double get(final int seed, final int seedOffset, final double x, final double y, final double z) {
        final double dist2 = MathUtil.lengthSquared(x - this.x, y - this.y, this.z - z);
        if (dist2 <= this.innerRadius2) {
            return -1.0;
        }
        if (dist2 >= this.outerRadius2) {
            return 1.0;
        }
        return -1.0 + 2.0 * (dist2 - this.innerRadius2) * this.invRange2;
    }
}
