This repository has been archived on 2022-05-21. You can view files and clone it, but cannot push or open issues or pull requests.
glyphs-juke/src/Period.h

33 lines
478 B
C
Raw Normal View History

2021-08-25 03:27:39 +00:00
#pragma once
#include <cstdint>
namespace gj {
struct Period {
public:
2021-08-25 09:17:31 +00:00
Period() : Period(0, 0) {
}
2021-08-25 03:27:39 +00:00
Period(uint64_t st, uint64_t ed) : start(st), end(ed) {
assert(st <= ed);
}
2021-08-25 09:17:31 +00:00
double Normalize(uint64_t now) const {
return (static_cast<int64_t>(now) - start)*1./duration();
}
bool IsHit(uint64_t now) const {
2021-08-25 03:27:39 +00:00
return start <= now && now < end;
}
uint64_t duration() const {
return end - start;
}
uint64_t start;
uint64_t end;
};
}