22#include "pybind11/pybind11.h"
23#include "pybind11/stl.h"
24#include "pybind11/numpy.h"
30using namespace py::literals;
38 [](
auto & mod,
auto & cls)
mutable {
40 cls.attr(
"Point") = mod.attr(
"Point2I");
41 cls.attr(
"Extent") = mod.attr(
"Extent2I");
43 py::enum_<Box2I::EdgeHandlingEnum>(cls,
"EdgeHandlingEnum")
44 .value(
"EXPAND", Box2I::EdgeHandlingEnum::EXPAND)
45 .value(
"SHRINK", Box2I::EdgeHandlingEnum::SHRINK)
48 cls.def(py::init<>());
49 cls.def(py::init<Point2I const &, Point2I const &, bool>(),
"minimum"_a,
"maximum"_a,
51 cls.def(py::init<Point2I const &, Extent2I const &, bool>(),
"corner"_a,
"dimensions"_a,
53 cls.def(py::init<IntervalI const &, IntervalI const &>(),
"x"_a,
"y"_a);
54 cls.def(py::init<Box2D const &, Box2I::EdgeHandlingEnum>(),
"other"_a,
55 "edgeHandling"_a = Box2I::EXPAND);
56 cls.def(py::init<Box2I const &>(),
"other"_a);
58 cls.def(
"__eq__", [](Box2I const &self, Box2I const &other) { return self == other; },
60 cls.def(
"__ne__", [](
Box2I const &self,
Box2I const &other) {
return self != other; },
102 cls.def(
"contains", py::overload_cast<Point2I const &>(&
Box2I::contains, py::const_));
103 cls.def(
"contains", py::overload_cast<Box2I const &>(&
Box2I::contains, py::const_));
107 cls.def(
"__contains__", py::overload_cast<Point2I const &>(&
Box2I::contains, py::const_));
108 cls.def(
"__contains__", py::overload_cast<Box2I const &>(&
Box2I::contains, py::const_));
112 cls.def(
"grow", py::overload_cast<int>(&
Box2I::grow));
113 cls.def(
"grow", py::overload_cast<Extent2I const &>(&
Box2I::grow));
117 cls.def(
"include", py::overload_cast<Point2I const &>(&
Box2I::include));
118 cls.def(
"include", py::overload_cast<Box2I const &>(&
Box2I::include));
120 cls.def(
"dilatedBy", py::overload_cast<int>(&
Box2I::dilatedBy, py::const_));
121 cls.def(
"dilatedBy", py::overload_cast<Extent2I const &>(&
Box2I::dilatedBy, py::const_));
122 cls.def(
"erodedBy", py::overload_cast<int>(&
Box2I::erodedBy, py::const_));
123 cls.def(
"erodedBy", py::overload_cast<Extent2I const &>(&
Box2I::erodedBy, py::const_));
127 cls.def(
"expandedTo", py::overload_cast<Point2I const &>(&
Box2I::expandedTo, py::const_));
128 cls.def(
"expandedTo", py::overload_cast<Box2I const &>(&
Box2I::expandedTo, py::const_));
132 cls.def(
"__repr__", [](
Box2I const &self) {
133 return py::str(
"Box2I(corner={}, dimensions={})")
134 .format(py::repr(py::cast(self.getMin())), py::repr(py::cast(self.getDimensions())));
136 cls.def(
"__str__", [](
Box2I const &self) {
137 return py::str(
"(minimum={}, maximum={})")
138 .format(py::str(py::cast(self.getMin())), py::str(py::cast(self.getMax())));
140 cls.def(
"__reduce__", [cls](
Box2I const &self) {
141 return py::make_tuple(cls, make_tuple(py::cast(self.getMin()), py::cast(self.getMax())));
143 auto getSlices = [](
Box2I const &self) {
144 return py::make_tuple(py::slice(self.getBeginY(), self.getEndY(), 1),
145 py::slice(self.getBeginX(), self.getEndX(), 1));
147 cls.def(
"getSlices", getSlices);
148 cls.def_property_readonly(
"slices", getSlices);
150 mod.attr(
"BoxI") = cls;
156 [](
auto & mod,
auto & cls)
mutable {
158 cls.attr(
"Point") = mod.attr(
"Point2D");
159 cls.attr(
"Extent") = mod.attr(
"Extent2D");
164 cls.def(py::init<>());
165 cls.def(py::init<Point2D const &, Point2D const &, bool>(),
"minimum"_a,
"maximum"_a,
167 cls.def(py::init<Point2D const &, Extent2D const &, bool>(),
"corner"_a,
"dimensions"_a,
169 cls.def(py::init<IntervalD const &, IntervalD const &>(),
"x"_a,
"y"_a);
170 cls.def(py::init<Box2I const &>());
171 cls.def(py::init<Box2D const &>());
173 cls.def(
"__eq__", [](Box2D
const &self, Box2D
const &other) {
return self == other; },
175 cls.def(
"__ne__", [](Box2D
const &self, Box2D
const &other) {
return self != other; },
207 cls.def(
"contains", py::overload_cast<Point2D const &>(&
Box2D::contains, py::const_));
208 cls.def(
"contains", py::overload_cast<Box2D const &>(&
Box2D::contains, py::const_));
210 py::vectorize(
static_cast<bool (Box2D::*)(
double x,
double y) const
>(&
Box2D::contains)),
212 cls.def(
"__contains__", py::overload_cast<Point2D const &>(&
Box2D::contains, py::const_));
213 cls.def(
"__contains__", py::overload_cast<Box2D const &>(&
Box2D::contains, py::const_));
217 cls.def(
"grow", py::overload_cast<double>(&
Box2D::grow));
218 cls.def(
"grow", py::overload_cast<Extent2D const &>(&
Box2D::grow));
222 cls.def(
"include", py::overload_cast<Point2D const &>(&
Box2D::include));
223 cls.def(
"include", py::overload_cast<Box2D const &>(&
Box2D::include));
225 cls.def(
"dilatedBy", py::overload_cast<double>(&
Box2D::dilatedBy, py::const_));
226 cls.def(
"dilatedBy", py::overload_cast<Extent2D const &>(&
Box2D::dilatedBy, py::const_));
227 cls.def(
"erodedBy", py::overload_cast<double>(&
Box2D::erodedBy, py::const_));
228 cls.def(
"erodedBy", py::overload_cast<Extent2D const &>(&
Box2D::erodedBy, py::const_));
232 cls.def(
"expandedTo", py::overload_cast<Point2D const &>(&
Box2D::expandedTo, py::const_));
233 cls.def(
"expandedTo", py::overload_cast<Box2D const &>(&
Box2D::expandedTo, py::const_));
237 cls.def(
"__repr__", [](Box2D
const &self) {
238 return py::str(
"Box2D(corner={}, dimensions={})")
239 .format(py::repr(py::cast(self.getMin())), py::repr(py::cast(self.getDimensions())));
241 cls.def(
"__str__", [](Box2D
const &self) {
242 return py::str(
"(minimum={}, maximum={})")
243 .format(py::str(py::cast(self.getMin())), py::str(py::cast(self.getMax())));
245 cls.def(
"__reduce__", [cls](Box2D
const &self) {
246 return py::make_tuple(cls,
make_tuple(py::cast(self.getMin()), py::cast(self.getMax())));
249 mod.attr(
"BoxD") = cls;
A helper class for subdividing pybind11 module across multiple translation units (i....
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...
double getMaxY() const noexcept
void swap(Box2D &other) noexcept
Point2D const getMax() const noexcept
double getMaxX() const noexcept
Box2D dilatedBy(Extent const &buffer) const
Increase the size of the box by the given amount(s) on all sides (returning a new object).
Extent2D const getDimensions() const noexcept
1-d interval accessors
void shift(Extent2D const &offset)
Shift the position of the box by the given offset.
double getMinY() const noexcept
void clip(Box2D const &other) noexcept
Shrink this to ensure that other.contains(*this).
double getWidth() const noexcept
1-d interval accessors
static Box2D makeCenteredBox(Point2D const ¢er, Extent const &size) noexcept
Create a box centered on a particular point.
Box2D erodedBy(Extent const &buffer) const
Decrease the size of the box by the given amount(s) on all sides (returning a new object).
Point2D const getCenter() const noexcept
Return true if the box contains no points.
bool isEmpty() const noexcept
Return true if the box contains no points.
Point2D const getMin() const noexcept
double getMinX() const noexcept
bool isDisjointFrom(Box2D const &other) const noexcept
Return true if there are no points in both this and other.
Interval getY() const
1-d interval accessors
void grow(double buffer)
Increase the size of the box by the given buffer amount in all directions.
Box2D reflectedAboutY(Element y) const
Reflect the box about a horizontal line (returning a new object).
void flipLR(float xExtent)
Flip a bounding box about the y-axis given a parent box of extent (xExtent).
void flipTB(float yExtent)
Flip a bounding box about the x-axis given a parent box of extent (yExtent).
Interval getX() const
1-d interval accessors
Box2D reflectedAboutX(Element x) const
Reflect the box about a vertical line (returning a new object).
double getCenterX() const noexcept
Return true if the box contains no points.
void include(Point2D const &point) noexcept
Expand this to ensure that this->contains(point).
bool contains(Point2D const &point) const noexcept
Return true if the box contains the point.
bool overlaps(Box2D const &other) const noexcept
Return true if any points in other are also in this.
bool intersects(Box2D const &other) const noexcept
Return true if the box contains no points.
double getArea() const noexcept
1-d interval accessors
Box2D clippedTo(Box2D const &other) const
Shrink a box to ensure that it is contained by other (returning a new object).
static double const EPSILON
Value the maximum coordinate is multiplied by to increase it by the smallest possible amount.
Box2D expandedTo(Point const &other) const
Expand a box to ensure that contains(other) is true (returning a new object).
std::vector< Point2D > getCorners() const
Get the corner points.
Box2D shiftedBy(Extent const &offset) const
Shift the position of the box by the given offset (returning a new object).
double getHeight() const noexcept
1-d interval accessors
std::string toString() const
Return true if the box contains no points.
static double const INVALID
Value used to specify undefined coordinate values.
double getCenterY() const noexcept
Return true if the box contains no points.
An integer coordinate rectangle.
int getBeginX() const noexcept
void clip(Box2I const &other) noexcept
Shrink this to ensure that other.contains(*this).
int getMinY() const noexcept
bool isDisjointFrom(Box2I const &other) const noexcept
Return true if there are no points in both this and other.
bool overlaps(Box2I const &other) const noexcept
Return true if any points in other are also in this.
void include(Point2I const &point)
Expand this to ensure that this->contains(point).
int getHeight() const noexcept
Box2I expandedTo(Point const &other) const
Expand the box to ensure that contains(other) is true (returning a new object).
Point2I const getMin() const noexcept
bool isEmpty() const noexcept
Return true if the box contains no points.
Point2I const getMax() const noexcept
int getEndY() const noexcept
Box2I clippedTo(Box2I const &other) const noexcept
Shrink an interval to ensure that it is contained by other (returning a new object).
void grow(int buffer)
Increase the size of the box by the given buffer amount in all directions.
Box2I erodedBy(Extent const &buffer) const
Decrease the size of the box by the given amount(s) on all sides (returning a new object).
Point2I const getBegin() const noexcept
Box2I dilatedBy(Extent const &buffer) const
Increase the size of the box by the given amount(s) on all sides (returning a new object).
int getMinX() const noexcept
static Box2I makeCenteredBox(Point2D const ¢er, Extent const &size)
Create a box centered as closely as possible on a particular point.
int getWidth() const noexcept
int getBeginY() const noexcept
int getMaxX() const noexcept
Interval getX() const
1-d interval accessors
std::vector< Point2I > getCorners() const
Get the corner points.
Box2I reflectedAboutX(Element x) const
Reflect the box about a vertical line (returning a new object).
bool contains(Point2I const &point) const noexcept
Return true if the box contains the point.
void shift(Extent2I const &offset)
Shift the position of the box by the given offset.
std::string toString() const
1-d interval accessors
void flipTB(int yExtent)
Flip a bounding box about the x-axis given a parent box of extent (yExtent).
void swap(Box2I &other) noexcept
int getMaxY() const noexcept
double getCenterY() const noexcept
1-d interval accessors
Box2I reflectedAboutY(Element y) const
Reflect the box about a horizontal line (returning a new object).
Point2I const getEnd() const noexcept
Interval getY() const
1-d interval accessors
Extent2I const getDimensions() const noexcept
double getCenterX() const noexcept
1-d interval accessors
bool intersects(Box2I const &other) const noexcept
1-d interval accessors
Box2I shiftedBy(Extent const &offset) const
Shift the position of the box by the given offset (returning a new object).
Point2D const getCenter() const noexcept
1-d interval accessors
void flipLR(int xExtent)
Flip a bounding box about the y-axis given a parent box of extent (xExtent).
int getEndX() const noexcept
void wrapBox(cpputils::python::WrapperCollection &wrappers)