Blender V5.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
8
9#pragma once
10
11#include <cmath>
12
13#include "BLI_assert.hh"
14#include "BLI_hash.hh"
15#include "BLI_math_base_c.hh"
16
17namespace blender {
18
22struct SubFrame {
23 private:
24 int frame_;
25 float subframe_;
26
27 public:
28 SubFrame(const int frame = 0, float subframe = 0.0f) : frame_(frame), subframe_(subframe)
29 {
30 BLI_assert(subframe >= 0.0f);
31 BLI_assert(subframe < 1.0f);
32 }
33
34 SubFrame(const float frame) : SubFrame(int(floorf(frame)), fractf(frame)) {}
35
36 int frame() const
37 {
38 return frame_;
39 }
40
41 float subframe() const
42 {
43 return subframe_;
44 }
45
46 explicit operator float() const
47 {
48 return float(frame_) + float(subframe_);
49 }
50
51 explicit operator double() const
52 {
53 return double(frame_) + double(subframe_);
54 }
55
56 static SubFrame min()
57 {
58 return {INT32_MIN, 0.0f};
59 }
60
61 static SubFrame max()
62 {
63 return {INT32_MAX, std::nexttowardf(1.0f, 0.0)};
64 }
65
66 uint64_t hash() const
67 {
68 return get_default_hash(frame_, subframe_);
69 }
70
71 friend bool operator==(const SubFrame &a, const SubFrame &b) = default;
72
73 friend bool operator<(const SubFrame &a, const SubFrame &b)
74 {
75 return a.frame_ < b.frame_ || (a.frame_ == b.frame_ && a.subframe_ < b.subframe_);
76 }
77
78 friend bool operator<=(const SubFrame &a, const SubFrame &b)
79 {
80 return a.frame_ < b.frame_ || (a.frame_ == b.frame_ && a.subframe_ <= b.subframe_);
81 }
82
83 friend bool operator>(const SubFrame &a, const SubFrame &b)
84 {
85 return a.frame_ > b.frame_ || (a.frame_ == b.frame_ && a.subframe_ > b.subframe_);
86 }
87
88 friend bool operator>=(const SubFrame &a, const SubFrame &b)
89 {
90 return a.frame_ > b.frame_ || (a.frame_ == b.frame_ && a.subframe_ >= b.subframe_);
91 }
92};
93
94} // namespace blender
#define INT32_MAX
#define INT32_MIN
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
MINLINE float fractf(float a)
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:252
#define floorf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
uint64_t hash() const
static SubFrame max()
SubFrame(const float frame)
friend bool operator<(const SubFrame &a, const SubFrame &b)
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)=default
friend bool operator>(const SubFrame &a, const SubFrame &b)