<commit_before>#include "linearcurve.h"

#include <cmath>

LinearCurve::LinearCurve()
{
    steps = 5;
}

LinearCurve::LinearCurve(const LinearCurve &x)
{
    this->ctrl = x.ctrl;
    this->steps = x.steps;
}

LinearCurve::LinearCurve(int steps)
{
    this->steps = steps;
}

LinearCurve::LinearCurve(int steps, const QList<QPoint> &ctrl)
{
    this->steps = steps;
    this->ctrl = ctrl;
}

double LinearCurve::value(double x)
{
    int lo = 1, hi = ctrl.count() - 1;
    int mid = (lo + hi) / 2;

    while (mid > 1 && lo < hi-1)
    {
        if (x <= ctrl.at(mid-1).x())
            hi = mid - 1;
        else if (x > ctrl.at(mid).x())
            lo = mid + 1;
        else
            break;
    }

    const QPoint &p1 = ctrl.at(mid-1);
    const QPoint &p2 = ctrl.at(mid);

    return p1.y() + (lround(x) - p1.x()) * (p2.y() - p1.y()) / (p2.x() - p1.x());
}

void LinearCurve::setControlPoints(const QList<QPoint> &ctrl)<commit_msg>Linear interpolation fixed.<commit_after>#include "linearcurve.h"

#include <cmath>

LinearCurve::LinearCurve()
{
    steps = 5;
}

LinearCurve::LinearCurve(const LinearCurve &x)
{
    this->ctrl = x.ctrl;
    this->steps = x.steps;
}

LinearCurve::LinearCurve(int steps)
{
    this->steps = steps;
}

LinearCurve::LinearCurve(int steps, const QList<QPoint> &ctrl)
{
    this->steps = steps;
    this->ctrl = ctrl;
}

double LinearCurve::value(double x)
{
    int mid = 1;
    while (ctrl.at(mid).x() < x && mid < ctrl.count()-1)
        ++mid;

    const QPoint &p1 = ctrl.at(mid);
    const QPoint &p2 = ctrl.at(mid-1);

    return p1.y() + (lround(x) - p1.x()) * (p2.y() - p1.y()) / (p2.x() - p1.x());
}

void LinearCurve::setControlPoints(const QList<QPoint> &ctrl)
{'fraction_non_alphanumeric': 0.18490345231129315, 'fraction_numerical': 0.017554125219426564, 'mean_word_length': 2.7665198237885464, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, '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': '569840', 'n_tokens_mistral': 681, 'n_tokens_neox': 678, 'n_words': 141}