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

package com.hypixel.hytale.server.worldgen.cave.shape.distorted;

import com.hypixel.hytale.math.util.MathUtil;
import com.hypixel.hytale.server.worldgen.cave.CaveType;
import javax.annotation.Nonnull;
import com.hypixel.hytale.math.vector.Vector3d;
import com.hypixel.hytale.procedurallib.logic.GeneralNoise;

public abstract class AbstractDistortedExtrusion extends AbstractDistortedShape
{
    protected final GeneralNoise.InterpolationFunction interpolation;
    
    public AbstractDistortedExtrusion(@Nonnull final Vector3d o, @Nonnull final Vector3d v, final double width, final double height, final GeneralNoise.InterpolationFunction interpolation) {
        super(o, v, width, height);
        this.interpolation = interpolation;
    }
    
    protected abstract double getDistanceSq(final double p0, final double p1, final double p2);
    
    protected abstract double getHeightComponent(final double p0, final double p1, final double p2);
    
    @Override
    public double getHeightAtProjection(final int seed, final double x, final double z, final double t, final double centerY, @Nonnull final CaveType caveType, @Nonnull final ShapeDistortion distortion) {
        double width = this.getWidthAt(t);
        width *= caveType.getHeightRadiusFactor(seed, x, z, MathUtil.floor(centerY));
        final double dist2 = this.getDistanceSq(x, z, t);
        double width2 = width * width;
        if (dist2 > width2) {
            return 0.0;
        }
        width *= distortion.getWidthFactor(seed, x, z);
        width2 = width * width;
        if (dist2 > width2) {
            return 0.0;
        }
        final double height = this.getHeightAt(t);
        if (height == 0.0) {
            return 0.0;
        }
        double alpha = this.getHeightComponent(width, width2, dist2);
        alpha = MathUtil.clamp(alpha, 0.0, 1.0);
        alpha = this.interpolation.interpolate(alpha);
        return height * alpha;
    }
}
