Blender V5.0
BLI_sub_frame.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include <cmath>
12
13#include "BLI_assert.h"
14#include "BLI_hash.hh"
15#include "BLI_math_base.h"
17
18namespace blender {
19
23struct SubFrame {
24 private:
25 int frame_;
26 float subframe_;
27
28 public:
29 SubFrame(const int frame = 0, float subframe = 0.0f) : frame_(frame), subframe_(subframe)
30 {
31 BLI_assert(subframe >= 0.0f);
32 BLI_assert(subframe < 1.0f);
33 }
34
35 SubFrame(const float frame) : SubFrame(int(floorf(frame)), fractf(frame)) {}
36
37 int frame() const
38 {
39 return frame_;
40 }
41
42 float subframe() const
43 {
44 return subframe_;
45 }
46
47 explicit operator float() const
48 {
49 return float(frame_) + float(subframe_);
50 }
51
52 explicit operator double() const
53 {
54 return double(frame_) + double(subframe_);
55 }
56
57 static SubFrame min()
58 {
59 return {INT32_MIN, 0.0f};
60 }
61
62 static SubFrame max()
63 {
64 return {INT32_MAX, std::nexttowardf(1.0f, 0.0)};
65 }
66
67 uint64_t hash() const
68 {
69 return get_default_hash(frame_, subframe_);
70 }
71
73
74 friend bool operator<(const SubFrame &a, const SubFrame &b)
75 {
76 return a.frame_ < b.frame_ || (a.frame_ == b.frame_ && a.subframe_ < b.subframe_);
77 }
78
79 friend bool operator<=(const SubFrame &a, const SubFrame &b)
80 {
81 return a.frame_ < b.frame_ || (a.frame_ == b.frame_ && a.subframe_ <= b.subframe_);
82 }
83
84 friend bool operator>(const SubFrame &a, const SubFrame &b)
85 {
86 return a.frame_ > b.frame_ || (a.frame_ == b.frame_ && a.subframe_ > b.subframe_);
87 }
88
89 friend bool operator>=(const SubFrame &a, const SubFrame &b)
90 {
91 return a.frame_ > b.frame_ || (a.frame_ == b.frame_ && a.subframe_ >= b.subframe_);
92 }
93};
94
95} // namespace blender
#define BLI_assert(a)
Definition BLI_assert.h:46
#define BLI_STRUCT_EQUALITY_OPERATORS_2(Type, m1, m2)
unsigned long long int uint64_t
nullptr float
#define INT32_MAX
#define INT32_MIN
uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:233
#define floorf
#define fractf
uint64_t hash() const
static SubFrame max()
SubFrame(const float frame)
friend bool operator<=(const SubFrame &a, const SubFrame &b)
static SubFrame min()
SubFrame(const int frame=0, float subframe=0.0f)
friend bool operator>=(const SubFrame &a, const SubFrame &b)
float subframe() const
friend bool operator>(const SubFrame &a, const SubFrame &b)