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