Commit 8d3ac4b2 authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[python][geometry] register dimensionality fields

parent 263272e3
......@@ -20,8 +20,10 @@
#define FRACKIT_PYTHON_GEOMETRY_BOX_HH
#include <pybind11/pybind11.h>
#include <frackit/geometry/geometry.hh>
#include <frackit/geometry/box.hh>
#include "registerdimensionproperties.hh"
namespace Frackit::Python {
......@@ -40,6 +42,9 @@ void registerBox(py::module& module)
"xmin"_a, "ymin"_a, "zmin"_a, "xmax"_a, "ymax"_a, "zmax"_a);
cls.def(py::init<const Point&, Point>(), "firstCorner"_a, "secondCorner"_a);
// dimensionality properties
registerDimensionProperties(cls);
// getter functions
cls.def("name", &Box::name, "name of the geometry class");
cls.def("volume", &Box::volume, "returns the volume of the box");
......
......@@ -22,9 +22,11 @@
#include <string>
#include <pybind11/pybind11.h>
#include <frackit/geometry/geometry.hh>
#include <frackit/geometry/ellipticalgeometry.hh>
#include <frackit/geometry/circle.hh>
#include "registerdimensionproperties.hh"
namespace Frackit::Python {
......@@ -40,6 +42,9 @@ namespace Detail {
std::string className("Circle_" + std::to_string(worldDim));
py::class_<Circle, Geometry, EllipticalGeometry> cls(module, className.c_str());
// dimensionality properties
registerDimensionProperties(cls);
// define constructors
using namespace py::literals;
using Point = typename Circle::Point;
......
......@@ -24,6 +24,7 @@
#include <pybind11/pybind11.h>
#include <frackit/geometry/geometry.hh>
#include <frackit/geometry/cylinder.hh>
#include "registerdimensionproperties.hh"
namespace Frackit::Python {
......@@ -44,8 +45,12 @@ void registerCylinder(py::module& module)
cls.def(py::init<const Circle&, ctype>(), "bottomCircle"_a, "height"_a);
cls.def(py::init<const Disk&, ctype>(), "bottom"_a, "height"_a);
// dimensionality properties
registerDimensionProperties(cls);
// getter functions
cls.def("name", &Cylinder::name, "name of the geometry class");
cls.def("base1", &Cylinder::base1, "first basis vector orthogonal to center line");
cls.def("base2", &Cylinder::base2, "second basis vector orthogonal to center line");
cls.def("base3", &Cylinder::base3, "basis vector parallel to center line");
......
......@@ -20,8 +20,10 @@
#define FRACKIT_PYTHON_GEOMETRY_CYLINDER_SURFACE_HH
#include <pybind11/pybind11.h>
#include <frackit/geometry/geometry.hh>
#include <frackit/geometry/cylindersurface.hh>
#include "registerdimensionproperties.hh"
namespace Frackit::Python {
......@@ -40,8 +42,12 @@ void registerCylinderSurface(py::module& module)
cls.def(py::init<ctype, ctype>(), "radius"_a, "height"_a);
cls.def(py::init<const Circle&, ctype>(), "bottomCircle"_a, "height"_a);
// dimensionality properties
registerDimensionProperties(cls);
// getter functions
cls.def("name", &CylinderSurface::name, "name of the geometry class");
cls.def("base1", &CylinderSurface::base1, "first basis vector orthogonal to center line");
cls.def("base2", &CylinderSurface::base2, "second basis vector orthogonal to center line");
cls.def("base3", &CylinderSurface::base3, "basis vector parallel to center line");
......
......@@ -24,6 +24,7 @@
#include <pybind11/pybind11.h>
#include <frackit/geometry/geometry.hh>
#include <frackit/geometry/direction.hh>
#include "registerdimensionproperties.hh"
namespace Frackit::Python {
......@@ -44,6 +45,9 @@ namespace Detail {
cls.def(py::init<>());
cls.def(py::init<const Vector&>(), "vector"_a);
// dimensionality properties
registerDimensionProperties(cls);
// member functions
cls.def("name", &Direction::name, "name of the geometry class");
cls.def("invert", &Direction::invert, "inverts the direction");
......
......@@ -24,6 +24,7 @@
#include <frackit/geometry/geometry.hh>
#include <frackit/geometry/ellipticalgeometry.hh>
#include <frackit/geometry/disk.hh>
#include "registerdimensionproperties.hh"
namespace Frackit::Python {
......@@ -42,6 +43,9 @@ void registerDisk(py::module& module)
py::class_<Disk, Geometry, EllipticalGeometry> cls(module, "Disk");
cls.def(py::init<const Ellipse&>(), "ellipse"_a);
// dimensionality properties
registerDimensionProperties(cls);
// member functions
cls.def("name", &Disk::name, "name of the geometry");
cls.def("area", &Disk::area, "area of the disk");
......
......@@ -22,9 +22,11 @@
#include <string>
#include <pybind11/pybind11.h>
#include <frackit/geometry/geometry.hh>
#include <frackit/geometry/ellipticalgeometry.hh>
#include <frackit/geometry/ellipse.hh>
#include "registerdimensionproperties.hh"
namespace Frackit::Python {
......@@ -47,6 +49,9 @@ namespace Detail {
cls.def(py::init<const Point&, const Direction&, const Direction&, ctype, ctype>(),
"center"_a, "majorAxis"_a, "minorAxis"_a, "majorAxisLength"_a, "minorAxisLength"_a);
// dimensionality properties
registerDimensionProperties(cls);
// member functions
cls.def("name", &Ellipse::name, "name of the geometry");
......
......@@ -23,6 +23,7 @@
#include <pybind11/pybind11.h>
#include <frackit/geometry/ellipsearc.hh>
#include "registerdimensionproperties.hh"
namespace Frackit::Python {
......@@ -44,6 +45,9 @@ namespace Detail {
cls.def(py::init<const Ellipse&, const Point&, const Point&>(),
"supportingEllipse"_a, "source"_a, "target"_a);
// dimensionality properties
registerDimensionProperties(cls);
// member functions
cls.def("name", &EllipseArc::name, "name of the geometry");
cls.def("source", &EllipseArc::source, "source point of the arc");
......
......@@ -25,6 +25,7 @@
#include <frackit/geometry/geometry.hh>
#include <frackit/geometry/line.hh>
#include "registerdimensionproperties.hh"
namespace Frackit::Python {
......@@ -45,6 +46,9 @@ namespace Detail {
py::class_<Line, Geometry> cls(module, className.c_str());
cls.def(py::init<const Point&, const Direction&>(), "supportPoint"_a, "direction"_a);
// dimensionality properties
registerDimensionProperties(cls);
// member functions
cls.def("name", &Line::name, "name of the geometry");
cls.def("direction", &Line::direction, "direction of the line");
......
......@@ -25,6 +25,7 @@
#include <frackit/geometry/geometry.hh>
#include <frackit/geometry/plane.hh>
#include "registerdimensionproperties.hh"
namespace Frackit::Python {
......@@ -51,6 +52,9 @@ namespace Detail {
cls.def(py::init<const Point&, const Direction&, const Direction&, const Direction&>(),
"supportPoint"_a, "base1"_a, "base2"_a, "normal"_a);
// dimensionality properties
registerDimensionProperties(cls);
// getter functions
cls.def("name", &Plane::name, "name of the geometry");
cls.def("normal", &Plane::normal, "normal direction");
......
......@@ -28,6 +28,7 @@
#include <frackit/geometry/geometry.hh>
#include <frackit/geometry/point.hh>
#include "registerdimensionproperties.hh"
namespace Frackit::Python {
......@@ -48,6 +49,9 @@ namespace Detail {
std::string className("PointBase_" + std::to_string(worldDim));
py::class_<Base, Geometry> cls(module, className.c_str());
// dimensionality properties
registerDimensionProperties(cls);
// member function
cls.def("name", &Base::name, "name of the geometry class");
......@@ -59,11 +63,9 @@ namespace Detail {
// equality checks
using namespace py::literals;
cls.def("isEqual",
py::overload_cast<const Impl&>(&Base::isEqual, py::const_),
cls.def("isEqual", py::overload_cast<const Impl&>(&Base::isEqual, py::const_),
"p"_a, "equality check with default tolerance");
cls.def("isEqual",
py::overload_cast<const Impl&, ctype>(&Base::isEqual, py::const_),
cls.def("isEqual", py::overload_cast<const Impl&, ctype>(&Base::isEqual, py::const_),
"p"_a, "b"_a, "equality check with default tolerance");
}
......
......@@ -25,6 +25,7 @@
#include <frackit/geometry/geometry.hh>
#include <frackit/geometry/quadrilateral.hh>
#include "registerdimensionproperties.hh"
namespace Frackit::Python {
......@@ -45,6 +46,9 @@ namespace Detail {
cls.def(py::init<const Point&, const Point&, const Point&, const Point&>(),
"p1"_a, "p2"_a, "p3"_a, "p4"_a);
// dimensionality properties
registerDimensionProperties(cls);
// member functions
cls.def("name", &Quad::name, "name of the geometry");
cls.def("area", &Quad::area, "area of the quadrilateral");
......
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*****************************************************************************
* See the file COPYING for full copying permissions. *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
#ifndef FRACKIT_PYTHON_GEOMETRY_REGISTER_DIMENSION_PROPERTIES_HH
#define FRACKIT_PYTHON_GEOMETRY_REGISTER_DIMENSION_PROPERTIES_HH
#include <pybind11/pybind11.h>
namespace Frackit::Python {
namespace py = pybind11;
template<class Geometry, class... options>
void registerDimensionProperties(py::class_<Geometry, options...>& cls)
{
cls.def_property_readonly_static("myDimension", [] (py::object /*self*/) { return Geometry::myDimension(); }, "dimension of the geometry");
cls.def_property_readonly_static("worldDimension", [] (py::object /*self*/) { return Geometry::worldDimension(); }, "space dimension");
}
} // end namespace Frackit::Python
#endif
......@@ -25,6 +25,7 @@
#include <frackit/geometry/geometry.hh>
#include <frackit/geometry/segment.hh>
#include "registerdimensionproperties.hh"
namespace Frackit::Python {
......@@ -44,6 +45,9 @@ namespace Detail {
py::class_<Segment, Geometry> cls(module, className.c_str());
cls.def(py::init<const Point&, const Point&>(), "source"_a, "target"_a);
// dimensionality properties
registerDimensionProperties(cls);
// member functions
cls.def("name", &Segment::name, "name of the geometry");
cls.def("source", &Segment::source, "source point of the segment");
......
......@@ -25,6 +25,7 @@
#include <frackit/geometry/geometry.hh>
#include <frackit/geometry/triangle.hh>
#include "registerdimensionproperties.hh"
namespace Frackit::Python {
......@@ -44,6 +45,9 @@ namespace Detail {
py::class_<Triangle, Geometry> cls(module, className.c_str());
cls.def(py::init<const Point&, const Point&, const Point&>(), "p1"_a, "p2"_a, "p3"_a);
// dimensionality properties
registerDimensionProperties(cls);
// member functions
cls.def("name", &Triangle::name, "name of the geometry");
cls.def("area", &Triangle::area, "area of the triangle");
......
......@@ -29,6 +29,7 @@
#include <frackit/precision/precision.hh>
#include <frackit/geometry/geometry.hh>
#include <frackit/geometry/vector.hh>
#include "registerdimensionproperties.hh"
namespace Frackit::Python {
......@@ -44,6 +45,9 @@ namespace Detail {
std::string className("VectorBase_" + std::to_string(Base::worldDimension()));
py::class_<Base, Geometry> cls(module, className.c_str());
// dimensionality properties
registerDimensionProperties(cls);
cls.def("name", &Base::name, "name of the geometry class");
cls.def("squaredLength", &Base::squaredLength, "squared length of the vector");
cls.def("length", &Base::length, "length of the vector");
......@@ -104,10 +108,8 @@ namespace Detail {
// define retrieval functions for the coordinates
cls.def("x", &Vector::x, "x-coordinate of the vector");
if constexpr (worldDim > 1)
cls.def("y", &Vector::y, "y-coordinate of the vector");
if constexpr (worldDim > 2)
cls.def("z", &Vector::z, "z-coordinate of the vector");
if constexpr (worldDim > 1) cls.def("y", &Vector::y, "y-coordinate of the vector");
if constexpr (worldDim > 2) cls.def("z", &Vector::z, "z-coordinate of the vector");
}
} // end namespace detail
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment