23 #include "pybind11/pybind11.h"
24 #include "pybind11/stl.h"
29 namespace py = pybind11;
36 using PySpan = py::class_<Span, std::shared_ptr<Span>>;
44 SpanIterator(
const Span &s) :
_it{s.begin()},
_end{s.end()} {};
47 throw py::stop_iteration();
57 static void declareSpanIterator(py::module &mod) {
58 py::class_<SpanIterator>
cls(mod,
"SpanIterator");
59 cls.def(
"__iter__", [](SpanIterator &it) -> SpanIterator & {
return it; });
60 cls.def(
"__next__", &SpanIterator::next);
64 py::module mod(
"span");
66 py::module::import(
"lsst.afw.geom.coordinates");
68 declareSpanIterator(mod);
70 PySpan
cls(mod,
"Span");
71 cls.def(py::init<int, int, int>());
72 cls.def(py::init<>());
73 cls.def(
"__eq__", &Span::operator==, py::is_operator());
74 cls.def(
"__ne__", &Span::operator!=, py::is_operator());
75 cls.def(
"__lt__", &Span::operator<, py::is_operator());
81 cls.def(
"__iter__", [](
const Span &s) {
return SpanIterator(s); });
82 cls.def(
"getX0", (
int (Span::*)()
const) &
Span::getX0);
83 cls.def(
"getX1", (
int (Span::*)()
const) &
Span::getX1);
84 cls.def(
"getY", (
int (Span::*)()
const) &
Span::getY);
93 cls.def(
"contains", (
bool (Span::*)(
int,
int)
const) & Span::contains);
94 cls.def(
"contains", (
bool (Span::*)(
Point2I const &)
const) & Span::contains);
int getEndX() const
End (exclusive) x-value.
int getMaxX() const
Maximum x-value.
int getWidth() const
Return the number of pixels.
int getX0() const
Return the starting x-value.
std::string toString() const
Return a string-representation of a Span.
int getMinX() const
Minimum x-value.
int getY() const
Return the y-value.
void shift(int dx, int dy)
bool isEmpty() const
Return true if the span contains no pixels.
int getBeginX() const
Begin (inclusive) x-value.
Point2I const getMax() const
Point corresponding to maximum x.
int getX1() const
Return the ending x-value.
SpanPixelIterator Iterator
An iterator over points in the Span.
bool contains(int x) const
Point2I const getMin() const
Point corresponding to minimum x.