/*
* InfiniPaint
* Copyright (C) 2025-2026 Yousef Khadadeh
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#pragma once
#include
#include
#include
#include
#include
#include "SharedTypes.hpp"
template T lerp_time(T t, T tEnd, T tStart = 0) {
return std::clamp((t - tStart) / (tEnd - tStart), 0, 1);
}
WorldVec lerp_world_vec_double(const WorldVec& v1, const WorldVec& v2, double t);
template std::enable_if_t, T> lerp_vec(const T& v1, const T& v2, TimeType t) {
T item;
for(unsigned i = 0; i < v1.size(); i++)
item[i] = std::lerp(v1[i], v2[i], t);
return item;
}
template std::enable_if_t, T> lerp_vec(T v1, T v2, TimeType t) {
return std::lerp(v1, v2, t);
}
template SkColor4f lerp_vec(const SkColor4f& t1, const SkColor4f& t2, TimeType t) {
return {std::lerp(t1[0], t2[0], t),
std::lerp(t1[1], t2[1], t),
std::lerp(t1[2], t2[2], t),
std::lerp(t1[3], t2[3], t)};
}
bool smooth_two_way_animation_time_check_for_change(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration);
float smooth_two_way_animation_time_get_lerp(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration);
void smooth_two_way_animation_time(float& timeToUpdate, float deltaTime, bool isWay1, float animDuration);
class TimePoint {
public:
TimePoint();
void update_time_point();
void update_time_since();
float get_time_since() const;
operator float() const;
private:
std::chrono::time_point tp;
float timeSince;
};