26#include <pybind11/pybind11.h>
27#include <pybind11/numpy.h>
30#include <pybind11/stl.h>
43using namespace py::literals;
50void declarePolygon(lsst::cpputils::python::WrapperCollection &wrappers) {
52 py::class_<
Polygon, std::shared_ptr<Polygon>, typehandling::Storable>(wrappers.
module,
"Polygon"),
53 [](
auto &mod,
auto &cls) {
55 cls.def(py::init<Polygon::Box const &>());
56 cls.def(py::init<Polygon::Box const &, TransformPoint2ToPoint2 const &>());
57 cls.def(py::init<Polygon::Box const &, lsst::geom::AffineTransform const &>());
58 cls.def(py::init<std::vector<Polygon::Point> const &>());
60 table::io::python::addPersistableMethods<Polygon>(cls);
64 "__eq__", [](Polygon const &self, Polygon const &other) { return self == other; },
67 "__ne__", [](
Polygon const &self,
Polygon const &other) {
return self != other; },
81 cls.def(
"contains", (std::vector<bool> (
Polygon::*)(std::vector<lsst::geom::Point2I>
const&)
const) &
Polygon::contains);
88 cls.def(
"intersectionSingle", (std::shared_ptr<Polygon>(
Polygon::*)(
Polygon const &)
const) &
90 cls.def(
"intersectionSingle",
93 cls.def(
"intersection",
94 (std::vector<std::shared_ptr<Polygon>>(
Polygon::*)(
Polygon const &)
const) &
96 cls.def(
"intersection",
99 cls.def(
"unionSingle",
101 cls.def(
"unionSingle", (std::shared_ptr<Polygon>(
Polygon::*)(
Polygon::Box const &)
const) &
105 cls.def(
"union", (std::vector<std::shared_ptr<Polygon>>(
Polygon::*)(
Polygon const &)
const) &
110 cls.def(
"symDifference",
111 (std::vector<std::shared_ptr<Polygon>>(
Polygon::*)(
Polygon const &)
const) &
113 cls.def(
"symDifference",
122 (std::shared_ptr<Polygon>(
Polygon::*)(lsst::geom::AffineTransform
const &)
const) &
128 cls.def(
"createImage", (std::shared_ptr<afw::image::Image<float>>(
Polygon::*)(
129 lsst::geom::Box2I
const &)
const) &
131 cls.def(
"createImage", (std::shared_ptr<afw::image::Image<float>>(
Polygon::*)(
143 declarePolygon(wrappers);
lsst::geom::Point2D Point
std::shared_ptr< Polygon > unionSingle(Polygon const &other) const
Returns the union of two polygons.
bool overlaps(Polygon const &other) const
Returns whether the polygons overlap each other.
Box getBBox() const
Return bounding box.
std::shared_ptr< Polygon > convexHull() const
Produce a polygon from the convex hull.
std::vector< std::pair< Point, Point > > getEdges() const
Get vector of edges.
std::shared_ptr< Polygon > intersectionSingle(Polygon const &other) const
Returns the intersection of two polygons.
std::shared_ptr< afw::image::Image< float > > createImage(lsst::geom::Box2I const &bbox) const
Create image of polygon.
std::shared_ptr< Polygon > subSample(size_t num) const
Sub-sample each edge.
std::vector< std::shared_ptr< Polygon > > intersection(Polygon const &other) const
Returns the intersection of two polygons.
Point calculateCenter() const
size_t getNumEdges() const
Return number of edges.
std::shared_ptr< Polygon > transform(TransformPoint2ToPoint2 const &transform) const
Transform the polygon.
double calculateArea() const
std::vector< Point > getVertices() const
Get vector of vertices.
std::vector< std::shared_ptr< Polygon > > union_(Polygon const &other) const
Returns the union of two polygons.
std::vector< std::shared_ptr< Polygon > > symDifference(Polygon const &other) const
Return the symmetric difference of two polygons.
bool contains(Point const &point) const
Returns whether the polygon contains the point.
double calculatePerimeter() const
An exception that indicates the single-polygon assumption has been violated.
A helper class for subdividing pybind11 module across multiple translation units (i....
void addSignatureDependency(std::string const &name)
Indicate an external module that provides a type used in function/method signatures.
void addInheritanceDependency(std::string const &name)
Indicate an external module that provides a base class for a subsequent addType call.
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...
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
auto wrapException(std::string const &pyName, std::string const &pyBase, bool setModuleName=true)
Wrap a C++ exception as a Python exception.
Reports errors that are due to events beyond the control of the program.
void wrapPolygon(lsst::cpputils::python::WrapperCollection &)
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Extent< int, 2 > Extent2I