Skip to content

Commit

Permalink
Merge pull request #97 from robotpy/apriltag-point-unpack
Browse files Browse the repository at this point in the history
Make AprilTagDetection.Point unpackable
  • Loading branch information
virtuald authored Jul 5, 2024
2 parents 764a1dc + 24659ef commit 0093529
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
13 changes: 12 additions & 1 deletion subprojects/robotpy-apriltag/gen/AprilTagDetection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ classes:
AprilTagDetection::Point pt{x, y};
return std::make_unique<AprilTagDetection::Point>(std::move(pt));
}), py::arg("x"), py::arg("y"))
.def("__len__", [](const AprilTagDetection::Point &self) { return 2; })
.def("__getitem__", [](const AprilTagDetection::Point &self, int index) {
switch (index) {
case 0:
return self.x;
case 1:
return self.y;
default:
throw std::out_of_range("AprilTagDetection.Point index out of range");
}
})
.def("__repr__", [](const AprilTagDetection::Point &self) {
return py::str("Point(x={}, y={})").format(self.x, self.y);
return py::str("AprilTagDetection.Point(x={}, y={})").format(self.x, self.y);
})
9 changes: 9 additions & 0 deletions subprojects/robotpy-apriltag/tests/test_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
import pytest


def test_point():
point = robotpy_apriltag.AprilTagDetection.Point()

x, y = point

assert x == 0
assert y == 0


def _load_grayscale_image(fname):
full_path = pathlib.Path(__file__).parent / fname
img = cv2.imread(str(full_path))
Expand Down

0 comments on commit 0093529

Please sign in to comment.