Skip to content

Commit 0093529

Browse files
authored
Merge pull request #97 from robotpy/apriltag-point-unpack
Make AprilTagDetection.Point unpackable
2 parents 764a1dc + 24659ef commit 0093529

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

subprojects/robotpy-apriltag/gen/AprilTagDetection.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ classes:
2929
AprilTagDetection::Point pt{x, y};
3030
return std::make_unique<AprilTagDetection::Point>(std::move(pt));
3131
}), py::arg("x"), py::arg("y"))
32+
.def("__len__", [](const AprilTagDetection::Point &self) { return 2; })
33+
.def("__getitem__", [](const AprilTagDetection::Point &self, int index) {
34+
switch (index) {
35+
case 0:
36+
return self.x;
37+
case 1:
38+
return self.y;
39+
default:
40+
throw std::out_of_range("AprilTagDetection.Point index out of range");
41+
}
42+
})
3243
.def("__repr__", [](const AprilTagDetection::Point &self) {
33-
return py::str("Point(x={}, y={})").format(self.x, self.y);
44+
return py::str("AprilTagDetection.Point(x={}, y={})").format(self.x, self.y);
3445
})

subprojects/robotpy-apriltag/tests/test_detection.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
import pytest
88

99

10+
def test_point():
11+
point = robotpy_apriltag.AprilTagDetection.Point()
12+
13+
x, y = point
14+
15+
assert x == 0
16+
assert y == 0
17+
18+
1019
def _load_grayscale_image(fname):
1120
full_path = pathlib.Path(__file__).parent / fname
1221
img = cv2.imread(str(full_path))

0 commit comments

Comments
 (0)