Rerun C++ SDK
Loading...
Searching...
No Matches
vector2d.hpp
1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/store/re_types/definitions/rerun/components/vector2d.fbs".
3
4#pragma once
5
6#include "../datatypes/vec2d.hpp"
7#include "../result.hpp"
8
9#include <array>
10#include <cstdint>
11#include <memory>
12
13namespace rerun::components {
14 /// **Component**: A vector in 2D space.
15 struct Vector2D {
17
18 public: // START of extensions from vector2d_ext.cpp:
19 /// Construct Vector2D from x/y values.
20 Vector2D(float x, float y) : vector{x, y} {}
21
22 /// Construct Vec2D from x/y float pointer.
23 explicit Vector2D(const float* xy) : vector{xy[0], xy[1]} {}
24
25 float x() const {
26 return vector.x();
27 }
28
29 float y() const {
30 return vector.y();
31 }
32
33 // END of extensions from vector2d_ext.cpp, start of generated code:
34
35 public:
36 Vector2D() = default;
37
38 Vector2D(rerun::datatypes::Vec2D vector_) : vector(vector_) {}
39
40 Vector2D& operator=(rerun::datatypes::Vec2D vector_) {
41 vector = vector_;
42 return *this;
43 }
44
45 Vector2D(std::array<float, 2> xy_) : vector(xy_) {}
46
47 Vector2D& operator=(std::array<float, 2> xy_) {
48 vector = xy_;
49 return *this;
50 }
51
52 /// Cast to the underlying Vec2D datatype
53 operator rerun::datatypes::Vec2D() const {
54 return vector;
55 }
56 };
57} // namespace rerun::components
58
59namespace rerun {
60 static_assert(sizeof(rerun::datatypes::Vec2D) == sizeof(components::Vector2D));
61
62 /// \private
63 template <>
64 struct Loggable<components::Vector2D> {
65 static constexpr const char Name[] = "rerun.components.Vector2D";
66
67 /// Returns the arrow data type this type corresponds to.
68 static const std::shared_ptr<arrow::DataType>& arrow_datatype() {
69 return Loggable<rerun::datatypes::Vec2D>::arrow_datatype();
70 }
71
72 /// Serializes an array of `rerun::components::Vector2D` into an arrow array.
73 static Result<std::shared_ptr<arrow::Array>> to_arrow(
74 const components::Vector2D* instances, size_t num_instances
75 ) {
76 if (num_instances == 0) {
77 return Loggable<rerun::datatypes::Vec2D>::to_arrow(nullptr, 0);
78 } else if (instances == nullptr) {
79 return rerun::Error(
80 ErrorCode::UnexpectedNullArgument,
81 "Passed array instances is null when num_elements> 0."
82 );
83 } else {
84 return Loggable<rerun::datatypes::Vec2D>::to_arrow(
85 &instances->vector,
86 num_instances
87 );
88 }
89 }
90 };
91} // namespace rerun
Status outcome object (success or error) returned for fallible operations.
Definition error.hpp:95
All built-in components. See Types in the Rerun manual.
Definition rerun.hpp:79
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:22
Component: A vector in 2D space.
Definition vector2d.hpp:15
Vector2D(const float *xy)
Construct Vec2D from x/y float pointer.
Definition vector2d.hpp:23
Vector2D(float x, float y)
Construct Vector2D from x/y values.
Definition vector2d.hpp:20
Datatype: A vector in 2D space.
Definition vec2d.hpp:20