File size: 3,037 Bytes
9ff4bea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/python/mod.rs
# Based on "crates/build/re_type_definitions/rerun/encodings/keypoint_pair.def.rs".

# You can extend this class by creating a "KeypointPairExt" class in "keypoint_pair_ext.py".

from __future__ import annotations

from collections.abc import Sequence
from typing import TYPE_CHECKING, Any

import pyarrow as pa
from attrs import define, field

from .. import encodings
from .._baseclasses import (
    BaseBatch,
)
from .keypoint_pair_ext import KeypointPairExt

__all__ = ["KeypointPair", "KeypointPairArrayLike", "KeypointPairBatch", "KeypointPairLike"]


def _keypoint_pair__keypoint0__special_field_converter_override(x: encodings.KeypointIdLike) -> encodings.KeypointId:
    if isinstance(x, encodings.KeypointId):
        return x
    else:
        return encodings.KeypointId(x)


def _keypoint_pair__keypoint1__special_field_converter_override(x: encodings.KeypointIdLike) -> encodings.KeypointId:
    if isinstance(x, encodings.KeypointId):
        return x
    else:
        return encodings.KeypointId(x)


@define(init=False)
class KeypointPair(KeypointPairExt):
    """**Encoding**: A connection between two [`encodings.KeypointId`][rerun.encodings.KeypointId]s."""

    def __init__(self: Any, keypoint0: encodings.KeypointIdLike, keypoint1: encodings.KeypointIdLike) -> None:
        """
        Create a new instance of the KeypointPair encoding.

        Parameters
        ----------
        keypoint0:
            The first point of the pair.
        keypoint1:
            The second point of the pair.

        """

        # You can define your own __init__ function as a member of KeypointPairExt in keypoint_pair_ext.py
        self.__attrs_init__(keypoint0=keypoint0, keypoint1=keypoint1)

    keypoint0: encodings.KeypointId = field(converter=_keypoint_pair__keypoint0__special_field_converter_override)
    # The first point of the pair.
    #
    # (Docstring intentionally commented out to hide this field from the docs)

    keypoint1: encodings.KeypointId = field(converter=_keypoint_pair__keypoint1__special_field_converter_override)
    # The second point of the pair.
    #
    # (Docstring intentionally commented out to hide this field from the docs)


if TYPE_CHECKING:
    KeypointPairLike = KeypointPair | Sequence[encodings.KeypointIdLike]
    """A type alias for any KeypointPair-like object."""
else:
    KeypointPairLike = Any

KeypointPairArrayLike = KeypointPair | Sequence[KeypointPairLike]
"""A type alias for any KeypointPair-like array object."""


class KeypointPairBatch(BaseBatch[KeypointPairArrayLike]):
    _ARROW_DATATYPE = pa.struct([
        pa.field("keypoint0", pa.uint16(), nullable=False, metadata={}),
        pa.field("keypoint1", pa.uint16(), nullable=False, metadata={}),
    ])

    @staticmethod
    def _native_to_pa_array(data: KeypointPairArrayLike, data_type: pa.DataType) -> pa.Array:
        return KeypointPairExt.native_to_pa_array_override(data, data_type)