#include "interval.h"
#include <iostream>
#include <cmath>

Interval::Interval(double l, double r) {
    start = l;
    end = r;
    if (l == r) {
        is_point = true;
    }
}

Interval::Interval(double l) {
    start = l;
    end = l;
    is_point = true;
}

double Interval::integral(double inf, double sup){
    if (is_point) {
        return (sup - inf) * std::exp(start);
    } else {
        double speed = end - start;
        return std::exp(start) * (std::exp(sup * speed) - std::exp(inf * speed)) / speed;
    }
}

double Interval::total_cost() {
    return integral(0, 1);
}

double Interval::stochastic_limit(double t) {
    if (is_point) {
        return (t > start);
    } else if (t <= end) {
        return (t - start)/(end - start);
    } else {
        return 1;
    }
}
