Blender V4.3
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
5#pragma once
6
7#include <cmath>
8
9#include "BLI_assert.h"
10#include "BLI_hash.hh"
11#include "BLI_math_base.h"
13
14namespace blender {
15
19struct SubFrame {
20 private:
21 int frame_;
22 float subframe_;
23
24 public:
25 SubFrame(const int frame = 0, float subframe = 0.0f) : frame_(frame), subframe_(subframe)
26 {
27 BLI_assert(subframe >= 0.0f);
28 BLI_assert(subframe < 1.0f);
29 }
30
32
33 int frame() const
34 {
35 return frame_;
36 }
37
38 float subframe() const
39 {
40 return subframe_;
41 }
42
43 explicit operator float() const
44 {
45 return float(frame_) + float(subframe_);
46 }
47
48 explicit operator double() const
49 {
50 return double(frame_) + double(subframe_);
51 }
52
53 static SubFrame min()
54 {
55 return {INT32_MIN, 0.0f};
56 }
57
58 static SubFrame max()
59 {
60 return {INT32_MAX, std::nexttowardf(1.0f, 0.0)};
61 }
62
63 uint64_t hash() const
64 {
65 return get_default_hash(frame_, subframe_);
66 }
67
69
70 friend bool operator<(const SubFrame &a, const SubFrame &b)
71 {
72 return a.frame_ < b.frame_ || (a.frame_ == b.frame_ && a.subframe_ < b.subframe_);
73 }
74
75 friend bool operator<=(const SubFrame &a, const SubFrame &b)
76 {
77 return a.frame_ <= b.frame_ || (a.frame_ == b.frame_ && a.subframe_ <= b.subframe_);
78 }
79
80 friend bool operator>(const SubFrame &a, const SubFrame &b)
81 {
82 return a.frame_ > b.frame_ || (a.frame_ == b.frame_ && a.subframe_ > b.subframe_);
83 }
84
85 friend bool operator>=(const SubFrame &a, const SubFrame &b)
86 {
87 return a.frame_ >= b.frame_ || (a.frame_ == b.frame_ && a.subframe_ >= b.subframe_);
88 }
89};
90
91} // namespace blender
#define BLI_assert(a)
Definition BLI_assert.h:50
#define BLI_STRUCT_EQUALITY_OPERATORS_2(Type, m1, m2)
typedef double(DMatrix)[4][4]
local_group_size(16, 16) .push_constant(Type b
#define floorf(x)
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
MINLINE float fractf(float a)
uint64_t get_default_hash(const T &v)
Definition BLI_hash.hh:219
#define INT32_MAX
Definition stdint.h:137
#define INT32_MIN
Definition stdint.h:136
unsigned __int64 uint64_t
Definition stdint.h:90
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)