<commit_before>﻿module LodRanges

type LodSettings = {
        LodLevels : int
        LodDistanceRatio : float //2.0
        VisibilityDistance : float
        MorphStartRatio : float //
    }

let calculateTotalDetailBalance lodLevels lodDistanceRatio =
    let mutable totalDetailBalance = 0.0
    let mutable currentDetailBalance = 1.0
    for i = 0 to lodLevels - 1 do
        totalDetailBalance <- totalDetailBalance + currentDetailBalance
        currentDetailBalance <- currentDetailBalance * lodDistanceRatio
    totalDetailBalance

type LodRange = {
        VisibilityRange : float
        MorphStart : float
        MorphEnd : float
    }

let makeLodRanges lodSettings =
    let lodNear = 0.0
    let lodFar = lodSettings.VisibilityDistance
    let totalDetailBalance = calculateTotalDetailBalance lodSettings.LodLevels lodSettings.LodDistanceRatio
    let sect = (lodFar - lodNear) / totalDetailBalance

    let mutable previousPosition = lodNear
    let mutable currentDetailBalance = 1.0
    let visibilityRanges = Array.zeroCreate<float> lodSettings.LodLevels
    for i = 0 to lodSettings.LodLevels - 1 do
        let visibilityRange = previousPosition + sect * currentDetailBalance
        visibilityRanges.[i] <- visibilityRange
        previousPosition <- visibilityRange
        currentDetailBalance <- currentDetailBalance * lodSettings.LodDistanceRatio

    let lodRanges = Array.zeroCreate<LodRange> lodSettings.LodLevels
    previousPosition <- lodNear
    for i = 0 to lodSettings.LodLevels - 1 do
        let lodRange = {
                VisibilityRange = visibilityRanges.[i]
                MorphEnd = visibilityRanges.[i]
                MorphStart = previousPosition + (visibilityRanges.[i] - previousPosition) * lodSettings.MorphStartRatio
            }
        lodRanges.[i] <- lodRange
        previousPosition <- lodRange.MorphStart
    lodRanges
//
//      selectionObj->m_morphEnd[i] = selectionObj->m_visibilityRanges[index];
//      selectionObj->m_morphStart[i] = prevPos + (selectionObj->m_morphEnd[i] - prevPos) * selectionObj->m_morphStartRatio;
//
//      prevPos = selectionObj->m_morphStart[i];<commit_msg>Refactor<commit_after>﻿module LodRanges

type LodSettings = {
        LodLevels : int
        LodDistanceRatio : float //2.0
        VisibilityDistance : float
        MorphStartRatio : float //
    }

let calculateTotalDetailBalance lodLevels lodDistanceRatio =
    let mutable totalDetailBalance = 0.0
    let mutable currentDetailBalance = 1.0
    for i = 0 to lodLevels - 1 do
        totalDetailBalance <- totalDetailBalance + currentDetailBalance
        currentDetailBalance <- currentDetailBalance * lodDistanceRatio
    totalDetailBalance

type LodRange = {
        VisibilityRange : float
        MorphStart : float
        MorphEnd : float
    }

let makeLodRanges lodSettings =
    let lodNear = 0.0
    let lodFar = lodSettings.VisibilityDistance
    let totalDetailBalance = calculateTotalDetailBalance lodSettings.LodLevels lodSettings.LodDistanceRatio
    let sect = (lodFar - lodNear) / totalDetailBalance

    let mutable previousPosition = lodNear
    let mutable currentDetailBalance = 1.0
    let visibilityRanges = Array.zeroCreate<float> lodSettings.LodLevels
    for i = 0 to lodSettings.LodLevels - 1 do
        let visibilityRange = previousPosition + sect * currentDetailBalance
        visibilityRanges.[i] <- visibilityRange
        previousPosition <- visibilityRange
        currentDetailBalance <- currentDetailBalance * lodSettings.LodDistanceRatio

    let lodRanges = Array.zeroCreate<LodRange> lodSettings.LodLevels
    for i = 0 to lodSettings.LodLevels - 1 do
        let previous = if i = 0 then 0.0 else lodRanges.[i - 1].MorphStart
        let lodRange = {
                VisibilityRange = visibilityRanges.[i]
                MorphEnd = visibilityRanges.[i]
                MorphStart = previous + (visibilityRanges.[i] - previous) * lodSettings.MorphStartRatio
            }
        lodRanges.[i] <- lodRange
    lodRanges
{'fraction_non_alphanumeric': 0.06721433905899925, 'fraction_numerical': 0.008961911874533234, 'mean_word_length': 2.8896418199419167, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3276317', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1108, 'n_words': 266}