#include "BasicInterpolator.h"
#include "Block.h"

Framework::Either<Block*, int> BasicInterpolator::interpolateBlocks( Framework::Either<Block*, int> a, Framework::Either<Block*, int> b, double aWeight, double bWeight, Noise* zNoise )
{
    if( aWeight < bWeight )
        return interpolateBlocks( b, a, bWeight, aWeight, zNoise );
    double score = bWeight / aWeight;
    if( score < 0.8 )
    {
        if( b.isA() )
            ((Block*)b)->release();
        return a;
    }
    score = (score - 0.8) * 5;
    if( score < zNoise->getNoise( (score + 60) * 5, 100, 50 ) )
    {
        if( b.isA() )
            ((Block*)b)->release();
        return a;
    }
    if( a.isA() )
        ((Block*)a)->release();
    return b;
}