Rerun C++ SDK
Loading...
Searching...
No Matches
position2d.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/position2d.fbs".
3
4#pragma once
5
6#include "../component_descriptor.hpp"
7#include "../datatypes/vec2d.hpp"
8#include "../result.hpp"
9
10#include <array>
11#include <cstdint>
12#include <memory>
13
14namespace rerun::components {
15 /// **Component**: A position in 2D space.
16 struct Position2D {
18
19 public: // START of extensions from position2d_ext.cpp:
20 /// Construct Position2D from x/y values.
21 Position2D(float x, float y) : xy{x, y} {}
22
23 float x() const {
24 return xy.x();
25 }
26
27 float y() const {
28 return xy.y();
29 }
30
31 // END of extensions from position2d_ext.cpp, start of generated code:
32
33 public:
34 Position2D() = default;
35
36 Position2D(rerun::datatypes::Vec2D xy_) : xy(xy_) {}
37
38 Position2D& operator=(rerun::datatypes::Vec2D xy_) {
39 xy = xy_;
40 return *this;
41 }
42
43 Position2D(std::array<float, 2> xy_) : xy(xy_) {}
44
45 Position2D& operator=(std::array<float, 2> xy_) {
46 xy = xy_;
47 return *this;
48 }
49
50 /// Cast to the underlying Vec2D datatype
51 operator rerun::datatypes::Vec2D() const {
52 return xy;
53 }
54 };
55} // namespace rerun::components
56
57namespace rerun {
58 static_assert(sizeof(rerun::datatypes::Vec2D) == sizeof(components::Position2D));
59
60 /// \private
61 template <>
62 struct Loggable<components::Position2D> {
63 static constexpr ComponentDescriptor Descriptor = "rerun.components.Position2D";
64
65 /// Returns the arrow data type this type corresponds to.
66 static const std::shared_ptr<arrow::DataType>& arrow_datatype() {
67 return Loggable<rerun::datatypes::Vec2D>::arrow_datatype();
68 }
69
70 /// Serializes an array of `rerun::components::Position2D` into an arrow array.
71 static Result<std::shared_ptr<arrow::Array>> to_arrow(
72 const components::Position2D* instances, size_t num_instances
73 ) {
74 if (num_instances == 0) {
75 return Loggable<rerun::datatypes::Vec2D>::to_arrow(nullptr, 0);
76 } else if (instances == nullptr) {
77 return rerun::Error(
78 ErrorCode::UnexpectedNullArgument,
79 "Passed array instances is null when num_elements> 0."
80 );
81 } else {
82 return Loggable<rerun::datatypes::Vec2D>::to_arrow(&instances->xy, num_instances);
83 }
84 }
85 };
86} // 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:80
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
Component: A position in 2D space.
Definition position2d.hpp:16
Position2D(float x, float y)
Construct Position2D from x/y values.
Definition position2d.hpp:21
Datatype: A vector in 2D space.
Definition vec2d.hpp:21