Skip to content

Commit

Permalink
add rect binding #15
Browse files Browse the repository at this point in the history
  • Loading branch information
timdewhirst committed Jul 25, 2022
1 parent 46ca432 commit ee33561
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
5 changes: 3 additions & 2 deletions openpiv/pybind/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@


find_package(pybind11 CONFIG REQUIRED)

pybind11_add_module(
pyopenpivcore
core/module.cpp
core/size.cpp
core/point.cpp
core/rect.cpp
core/size.cpp
core/vector.cpp
)
target_link_libraries(
Expand Down
6 changes: 4 additions & 2 deletions openpiv/pybind/core/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

namespace py = pybind11;

void add_size(py::module &);
void add_point(py::module &);
void add_rect(py::module &);
void add_size(py::module &);
void add_vector(py::module &);

PYBIND11_MODULE(pyopenpivcore, m) {
Expand All @@ -22,8 +23,9 @@ PYBIND11_MODULE(pyopenpivcore, m) {
)pbdoc";

// add each binding chunk here
add_size(m);
add_point(m);
add_rect(m);
add_size(m);
add_vector(m);

#ifdef VERSION_INFO
Expand Down
47 changes: 47 additions & 0 deletions openpiv/pybind/core/rect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

// openpiv
#include "core/rect.h"
#include "core/size.h"

using namespace openpiv;
using namespace openpiv::core;

// pybind
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/operators.h>

// std
#include <sstream>

namespace py = pybind11;

void add_rect(py::module& m)
{
// size
py::class_<rect>(m, "rect")
.def(py::init())
.def(py::init<rect::point_t, size>())
.def_static("from_size", &rect::from_size)
.def("bottomLeft", &rect::bottomLeft)
.def("topLeft", &rect::topLeft)
.def("bottomRight", &rect::bottomRight)
.def("topRight", &rect::topRight)
.def("midpoint", &rect::midpoint)
.def("bottom", &rect::bottom)
.def("top", &rect::top)
.def("left", &rect::left)
.def("right", &rect::right)
.def("size", &rect::size)
.def("width", &rect::width)
.def("height", &rect::height)
.def("area", &rect::area)
.def(py::self == py::self)
.def(py::self != py::self)
.def("__repr__",
[](const size& s) {
std::ostringstream ss;
ss << s;
return ss.str();
});
}

0 comments on commit ee33561

Please sign in to comment.