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

package com.hypixel.hytale.builtin.hytalegenerator.density.nodes;

import com.hypixel.hytale.builtin.hytalegenerator.VectorUtil;
import javax.annotation.Nonnull;
import it.unimi.dsi.fastutil.doubles.Double2DoubleFunction;
import com.hypixel.hytale.math.vector.Vector3d;
import com.hypixel.hytale.builtin.hytalegenerator.density.Density;

public class AxisDensity extends Density
{
    public static final double ZERO_DELTA = 1.0E-9;
    private static final Vector3d ZERO_VECTOR;
    @Nonnull
    private final Double2DoubleFunction distanceCurve;
    @Nonnull
    private final Vector3d axis;
    private final boolean isAnchored;
    
    public AxisDensity(@Nonnull final Double2DoubleFunction distanceCurve, @Nonnull final Vector3d axis, final boolean isAnchored) {
        this.distanceCurve = distanceCurve;
        this.axis = axis;
        this.isAnchored = isAnchored;
    }
    
    @Override
    public double process(@Nonnull final Context context) {
        if (this.axis.length() == 0.0) {
            return 0.0;
        }
        if (this.isAnchored) {
            return this.processAnchored(context);
        }
        final double distance = VectorUtil.distanceToLine3d(context.position, AxisDensity.ZERO_VECTOR, this.axis);
        return this.distanceCurve.get(distance);
    }
    
    private double processAnchored(@Nonnull final Context context) {
        if (context == null) {
            return 0.0;
        }
        final Vector3d anchor = context.densityAnchor;
        if (anchor == null) {
            return 0.0;
        }
        final Vector3d position = context.position.clone().subtract(anchor);
        final double distance = VectorUtil.distanceToLine3d(position, AxisDensity.ZERO_VECTOR, this.axis);
        return this.distanceCurve.get(distance);
    }
    
    static {
        ZERO_VECTOR = new Vector3d();
    }
}
