22 #include "pybind11/pybind11.h"
41 using namespace pybind11::literals;
48 uint8_t
const *buffer =
reinterpret_cast<uint8_t
const *
>(
49 PYBIND11_BYTES_AS_STRING(
bytes.ptr()));
50 size_t n =
static_cast<size_t>(PYBIND11_BYTES_SIZE(
bytes.ptr()));
51 return Box::decode(buffer, n);
55 py::module::import(
"lsst.sphgeom.region");
57 py::class_<Box, std::unique_ptr<Box>, Region>
cls(mod,
"Box");
59 cls.attr(
"TYPE_CODE") = py::int_(Box::TYPE_CODE);
61 cls.def_static(
"fromDegrees", &Box::fromDegrees,
"lon1"_a,
"lat1"_a,
63 cls.def_static(
"fromRadians", &Box::fromRadians,
"lon1"_a,
"lat1"_a,
65 cls.def_static(
"empty", &Box::empty);
66 cls.def_static(
"full", &Box::full);
67 cls.def_static(
"halfWidthForCircle", &Box::halfWidthForCircle,
"radius"_a,
69 cls.def_static(
"allLongitudes", &Box::allLongitudes);
70 cls.def_static(
"allLatitudes", &Box::allLatitudes);
72 cls.def(py::init<>());
73 cls.def(py::init<LonLat const &>(),
"point"_a);
74 cls.def(py::init<LonLat const &, LonLat const &>(),
"point1"_a,
"point2"_a);
75 cls.def(py::init<LonLat const &, Angle, Angle>(),
"center"_a,
"width"_a,
77 cls.def(py::init<NormalizedAngleInterval const &, AngleInterval const &>(),
79 cls.def(py::init<Box const &>(),
"box"_a);
81 cls.def(
"__eq__", (
bool (Box::*)(Box
const &)
const) & Box::operator==,
83 cls.def(
"__eq__", (
bool (Box::*)(LonLat
const &)
const) & Box::operator==,
85 cls.def(
"__ne__", (
bool (Box::*)(Box
const &)
const) & Box::operator!=,
87 cls.def(
"__ne__", (
bool (Box::*)(LonLat
const &)
const) & Box::operator!=,
89 cls.def(
"__contains__",
95 cls.def(
"__contains__",
99 cls.def(
"getLon", &Box::getLon);
100 cls.def(
"getLat", &Box::getLat);
101 cls.def(
"isEmpty", &Box::isEmpty);
102 cls.def(
"isFull", &Box::isFull);
103 cls.def(
"getCenter", &Box::getCenter);
104 cls.def(
"getWidth", &Box::getWidth);
105 cls.def(
"getHeight", &Box::getHeight);
110 (
bool (Box::*)(UnitVector3d
const &)
const) &
Box::contains);
111 cls.def(
"isDisjointFrom",
112 (
bool (Box::*)(LonLat
const &)
const) & Box::isDisjointFrom);
113 cls.def(
"isDisjointFrom",
114 (
bool (Box::*)(Box
const &)
const) & Box::isDisjointFrom);
115 cls.def(
"intersects",
116 (
bool (Box::*)(LonLat
const &)
const) & Box::intersects);
117 cls.def(
"intersects", (
bool (Box::*)(Box
const &)
const) & Box::intersects);
118 cls.def(
"isWithin", (
bool (Box::*)(LonLat
const &)
const) & Box::isWithin);
119 cls.def(
"isWithin", (
bool (Box::*)(Box
const &)
const) & Box::isWithin);
120 cls.def(
"clipTo", (Box & (Box::*)(LonLat
const &)) & Box::clipTo);
121 cls.def(
"clipTo", (Box & (Box::*)(Box
const &)) & Box::clipTo);
122 cls.def(
"clippedTo", (Box(Box::*)(LonLat
const &)
const) & Box::clippedTo);
123 cls.def(
"clippedTo", (Box(Box::*)(Box
const &)
const) & Box::clippedTo);
124 cls.def(
"expandTo", (Box & (Box::*)(LonLat
const &)) & Box::expandTo);
125 cls.def(
"expandTo", (Box & (Box::*)(Box
const &)) & Box::expandTo);
126 cls.def(
"expandedTo",
127 (Box(Box::*)(LonLat
const &)
const) & Box::expandedTo);
128 cls.def(
"expandedTo", (Box(Box::*)(Box
const &)
const) & Box::expandedTo);
129 cls.def(
"dilateBy", (Box & (Box::*)(
Angle)) & Box::dilateBy,
"angle"_a);
130 cls.def(
"dilateBy", (Box & (Box::*)(
Angle,
Angle)) & Box::dilateBy,
131 "width"_a,
"height"_a);
132 cls.def(
"dilatedBy", (Box(Box::*)(
Angle)
const) & Box::dilatedBy,
134 cls.def(
"dilatedBy", (Box(Box::*)(
Angle,
Angle)
const) & Box::dilatedBy,
135 "width"_a,
"height"_a);
136 cls.def(
"erodeBy", (Box & (Box::*)(
Angle)) & Box::erodeBy,
"angle"_a);
137 cls.def(
"erodeBy", (Box & (Box::*)(
Angle,
Angle)) & Box::erodeBy,
"width"_a,
139 cls.def(
"erodedBy", (Box(Box::*)(
Angle)
const) & Box::erodedBy,
"angle"_a);
140 cls.def(
"erodedBy", (Box(Box::*)(
Angle,
Angle)
const) & Box::erodedBy,
141 "width"_a,
"height"_a);
142 cls.def(
"getArea", &Box::getArea);
155 cls.def_static(
"decode",
159 cls.def(
"__str__", [](Box
const &
self) {
160 return py::str(
"Box({!s}, {!s})").format(
self.getLon(),
self.getLat());
162 cls.def(
"__repr__", [](Box
const &
self) {
163 return py::str(
"Box({!r}, {!r})").format(
self.getLon(),
self.getLat());
166 [](
const Box &
self) {
return python::encode(
self); },