4 #include <bnb/utils/defs.hpp>
5 #include <bnb/types/config.hpp>
6 #include <bnb/utils/assert.hpp>
7 #include <bnb/utils/logger.hpp>
37 using high_res_timer = std::chrono::high_resolution_clock;
38 using time_stamp_t = std::chrono::time_point<std::chrono::high_resolution_clock>;
62 return point2d{x / p.x, y / p.y};
65 point2d operator/(
float f)
const noexcept
70 point2d operator*(
float a)
const noexcept
75 point2d operator+(
float a)
const noexcept
82 return point2d{x * p.x, y * p.y};
87 return point2d{x - p.x, y - p.y};
92 return point2d{x + p.x, y + p.y};
116 return *
this * *
this;
121 return point3d{x / p.x, y / p.y, z / p.z};
124 point3d operator/(
float f)
const noexcept
126 return point3d{x / f, y / f, z / f};
131 return point3d{x * p.x, y * p.y, z * p.z};
134 point3d operator*(
float a)
const noexcept
136 return point3d{x * a, y * a, z * a};
141 return point3d{x - p.x, y - p.y, z - p.z};
146 return point3d{x + p.x, y + p.y, z + p.z};
158 using type = uint8_t[];
159 using pointer = uint8_t*;
160 using uptr = std::unique_ptr<type, std::function<void(pointer)>>;
164 static data_t create_non_owning(std::shared_ptr<uint8_t> datum,
size_t size)
167 uptr(datum.get(), [](pointer) { }),
171 static data_t create_non_owning(uint8_t* datum,
size_t size)
174 uptr(datum, [](pointer) {}),
178 void reserve(
size_t reserve_size)
180 if (
size < reserve_size) {
181 data = std::make_unique<type>(reserve_size);
196#if BNB_PYBIND_BUILD || BNB_OS_EMSCRIPTEN
199 : data(other.data.get(), [](pointer) { })
202 BNB_ASSERT_MSG(
false,
"bnb::data_t copy constructor!");
203 bnb::logger::print(bnb::severity_level::warning,
"bnb::data_t",
"copy constructor called, possible memory issue!");
209 BNB_ASSERT_MSG(
false,
"bnb::data_t copy operator!");
210 bnb::logger::print(bnb::severity_level::warning,
"bnb::data_t",
"copy operator called, possible memory issue!");
211 data = uptr(other.data.get(), [](pointer) { });
218 using color_plane_data_t = std::uint8_t;
219 using color_plane = std::shared_ptr<color_plane_data_t>;
221 inline color_plane color_plane_vector(std::vector<color_plane_data_t> vector)
226 auto* ptr =
new std::vector<color_plane_data_t>(std::move(vector));
227 return color_plane(ptr->data(), [ptr](color_plane_data_t*) { delete ptr; });
230 inline color_plane color_plane_string(std::string str)
232 auto* ptr =
new std::string(std::move(str));
233 return color_plane(
reinterpret_cast<color_plane_data_t*
>(ptr->data()), [ptr](color_plane_data_t*) { delete ptr; });
236 inline color_plane color_plane_char_arr(
const char* ptr,
size_t size)
238 std::vector<color_plane_data_t> plane(size);
239 memcpy(plane.data(),
reinterpret_cast<const color_plane_data_t*
>(ptr), size);
240 return color_plane_vector(plane);
243 inline color_plane color_plane_weak(
const color_plane_data_t* ptr)
245 return color_plane(
const_cast<color_plane_data_t*
>(ptr), [](color_plane_data_t*) { });
249 inline color_plane color_plane_data(data_t&& data)
251 auto* ptr =
new data_t(std::move(data));
252 return color_plane(ptr->data.get(), [ptr](color_plane_data_t*) { delete ptr; });
camera_orientation
camera image layout is top-left, 0 orientation is portrait, rotation is counterclockwise