module RegisterRandom

export  get_value_from_interval,
        get_random_vector_from_interval,
        get_vector_of_bounds,
        get_random_affine,
        get_random_perspective


@inline function get_random_value_from_interval(bounds::Tuple{T, T}) where {T<:AbstractFloat}
    a::T = bounds[1]
    b::T = bounds[2]
    return ((b-a) * rand(T)) + a;
end


function get_random_vector_from_interval(bounds::Vector{Tuple{T, T}}) where {T<:AbstractFloat}

    params_count::Int64, = size(bounds)

    result::Vector{T} = zeros(T, params_count)
    for (index, bound) in enumerate(bounds)
        result[index] = get_random_value_from_interval(bound)
    end
    return result
end


@inline function get_vector_of_bounds(Î¸::T, Î»::T, Î´::T) where{T<:AbstractFloat}
    
    start::T = 1.0
    @assert(0.0 <= Î» < 1.0)
    return [
                minmax(-Î¸, Î¸),                  # Î¸ parameter
                minmax(start - Î», start + Î»),   # Î»â‚“
                minmax(start - Î», start + Î»),   # Î»ð�šˆ
                minmax(-Î´, Î´),                  # dx
                minmax(-Î´, Î´),                  # dy
            ]
end


@inline function get_vector_of_bounds(Î¸::T, Î»::T, Î´, s::T) where{T<:AbstractFloat}
    
    start::T = 1.0
    @assert(0.0 <= Î» < 1.0)
    return [
                minmax(-Î¸, Î¸),                  # Î¸ parameter
                minmax(start - Î», start + Î»),   # Î»â‚“
                minmax(start - Î», start + Î»),   # Î»ð�šˆ
                minmax(-Î´, Î´),                  # dx
                minmax(-Î´, Î´),                  # dy
                minmax(-s, s),                  # shear x
                minmax(-s, s)                   # shear y
            ]
end

function get_random_affine(Î¸::T, Î»::T, Î´::T) where{T<:AbstractFloat}
    
    bounds::Vector{Tuple{T,T}} = get_vector_of_bounds(Î¸, Î», Î´)

    return get_random_vector_from_interval(bounds)
end


function get_random_perspective(Î¸::T, Î»::T, Î´::T, s::T) where{T<:AbstractFloat}
    
    bounds::Vector{Tuple{T,T}} = get_vector_of_bounds(Î¸, Î», Î´, s)

    return get_random_vector_from_interval(bounds)
end


end