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

Merge branch 'feature/cleanup-common' into 'master'

Feature/cleanup common

See merge request tools/frackit!207
parents 6e894a3f 4472e953
Pipeline #2849 passed with stages
in 9 minutes and 51 seconds
......@@ -19,10 +19,8 @@
/*!
* \file
* \ingroup Common
* \brief Base class for stl conformant forward iterators.
* The implementations are strongly inspired by Dune, see
* https://gitlab.dune-project.org/core/dune-common/-/blob/master/dune/common/iteratorfacades.hh
*
* \brief Iterator facade that allows iterating over a subset of a container with
* random access, where the subset is given by means of indices.
*/
#ifndef FRACKIT_COMMON_ITERATORFACADES_HH
#define FRACKIT_COMMON_ITERATORFACADES_HH
......@@ -35,27 +33,10 @@ namespace Frackit {
/*!
* \ingroup Common
* \brief Base class for stl conformant forward iterators.
* \brief Base class for forward iterator facades.
* The implementation is strongly inspired by the one in Dune, see
* https://gitlab.dune-project.org/core/dune-common/-/blob/master/dune/common/iteratorfacades.hh
*
* Implementations must define following functions:
*
* \code
*
* // Access the value referred to.
* reference dereference() const;
*
* // Compare for equality with iterator j
* bool equals(j);
*
* // position the iterator at the next element.
* void increment()
*
* \endcode
*
* See the above link to dune-common for more information.
*
* \tparam IT Iterator implementation
* \tparam VT The value type
* \tparam RT The reference type
......@@ -86,19 +67,19 @@ public:
pointer operator->() const
{ return &(static_cast<const Implementation *>(this)->dereference()); }
//! Preincrement operator
//! pre-increment operator
Implementation& operator++()
{
static_cast<Implementation *>(this)->increment();
return *static_cast<Implementation *>(this);
static_cast<Implementation *>(this)->increment();
return *static_cast<Implementation *>(this);
}
//! Postincrement operator
//! post-increment operator
Implementation operator++(int)
{
Implementation tmp(static_cast<Implementation const&>(*this));
this->operator++();
return tmp;
Implementation tmp(static_cast<Implementation const&>(*this));
this->operator++();
return tmp;
}
//! equality operator
......@@ -106,6 +87,7 @@ public:
friend inline bool operator==(const Implementation& it, const OtherIt& otherIt)
{ return it.equals(otherIt); }
//! equality operator
template<class OtherIt, std::enable_if_t<isInteroperable<OtherIt>
&& !std::is_same_v<OtherIt, Implementation>, int> = 0>
friend inline bool operator==(const OtherIt& otherIt, const Implementation& it)
......@@ -116,6 +98,7 @@ public:
friend inline bool operator!=(const Implementation& it, const OtherIt& otherIt)
{ return !it.equals(otherIt); }
//! inequality operator
template<class OtherIt, std::enable_if_t<isInteroperable<OtherIt>
&& !std::is_same_v<OtherIt, Implementation>, int> = 0>
friend inline bool operator!=(const OtherIt& otherIt, const Implementation& it)
......
......@@ -19,9 +19,9 @@
/*!
* \file
* \ingroup Common
* \brief Simple range between begin and end iterators
* that can be used to support range-based for loops.
* The implementation is strongly inspired by the one provided in Dune, see
* \brief Class that represents a range between begin and end iterators.
* Can be used to support range-based for loops.
* The implementation is inspired by the one provided in Dune, see
* https://gitlab.dune-project.org/core/dune-common/-/blob/master/dune/common/iteratorrange.hh
*/
#ifndef FRACKIT_COMMON_ITERATORRANGE_HH
......@@ -31,37 +31,24 @@ namespace Frackit {
/*!
* \ingroup Common
* \brief Simple range between begin and end iterators
* that can be used to support range-based for loops.
* The implementation is strongly inspired by the one provided in Dune, see
* \brief Class that represents a range between begin and end iterators.
* Can be used to support range-based for loops.
* The implementation is inspired by the one provided in Dune, see
* https://gitlab.dune-project.org/core/dune-common/-/blob/master/dune/common/iteratorrange.hh
*
* \tparam Iterator The type of iterator
*/
template<typename Iterator>
class IteratorRange
{
public:
///@{
//! The iterators belonging to this range.
using iterator = Iterator;
using const_iterator = Iterator;
///@}
//! Constructs an iterator range on [begin, end).
IteratorRange(const Iterator& begin, const Iterator& end)
: begin_(begin)
, end_(end)
{}
//! Default constructor
IteratorRange() = default;
IteratorRange(const Iterator& begin, const Iterator& end)
: begin_(begin) , end_(end) {}
//! Returns an iterator pointing to the begin of the range.
Iterator begin() const { return begin_; }
//! Returns an iterator pointing past the end of the range.
Iterator end() const { return end_; }
private:
......
......@@ -141,6 +141,7 @@ ctype toRadians(const ctype degrees)
* \param angle The rotation angle
* \note The rotation matrix is taken from:
* https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle
* \todo TODO: This should probably be moved to geometry
*/
template<class ctype>
void rotate(Vector<ctype, 3>& v,
......@@ -176,6 +177,7 @@ void rotate(Vector<ctype, 3>& v,
* vector several times, as the rotation matrix is only constructed once!
* \note The rotation matrix is taken from:
* https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle
* \todo TODO: This should probably be moved to geometry
*/
template<class ctype>
void rotate(std::vector<Vector<ctype, 3>>& vectors,
......
install(FILES
id.hh
math.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/frackit/python/common)
......@@ -26,6 +26,7 @@ point.hh
polygon.hh
quadrilateral.hh
registerdimensionproperties.hh
rotate.hh
segment.hh
sphere.hh
triangle.hh
......
......@@ -16,11 +16,10 @@
* 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_COMMON_MATH_HH
#define FRACKIT_PYTHON_COMMON_MATH_HH
#ifndef FRACKIT_PYTHON_GEOMETRY_ROTATE_HH
#define FRACKIT_PYTHON_GEOMETRY_ROTATE_HH
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <frackit/geometry/vector.hh>
#include <frackit/geometry/direction.hh>
......@@ -31,11 +30,8 @@ namespace Frackit::Python {
namespace py = pybind11;
template<class ctype>
void registerMath(py::module& module)
void registerRotate(py::module& module)
{
module.def("toDegrees", &Frackit::toDegrees<ctype>, "Converts radians into degrees");
module.def("toRadians", &Frackit::toRadians<ctype>, "Converts degrees into radians");
// Register rotation overload for single vector
using namespace py::literals;
using Vector_3 = Vector<ctype, 3>;
......
......@@ -18,10 +18,8 @@
*****************************************************************************/
#include <pybind11/pybind11.h>
#include <frackit/python/common/id.hh>
#include <frackit/python/common/math.hh>
PYBIND11_MODULE(_common, module)
{
Frackit::Python::registerId(module);
Frackit::Python::registerMath<double>(module);
}
......@@ -47,6 +47,7 @@
#include <frackit/python/geometry/magnitude.hh>
#include <frackit/python/geometry/intersect.hh>
#include <frackit/python/geometry/getboundingbox.hh>
#include <frackit/python/geometry/rotate.hh>
PYBIND11_MODULE(_geometry, module)
{
......@@ -96,4 +97,7 @@ PYBIND11_MODULE(_geometry, module)
// bounding box computation
Frackit::Python::registerGetBoundingBox<double>(module);
// rotation algorithms
Frackit::Python::registerRotate<double>(module);
}
......@@ -193,7 +193,7 @@ class DiskSampler:
e2 = Direction_3(axes[1])
e3 = Direction_3(Vector_3(0.0, 0.0, 1.0))
from frackit.common import rotate
from frackit.geometry import rotate
rotate(axes[1], e1, alpha) # rotate minor axis around x
rotate(axes[0], e2, beta) # rotate both axes around y
rotate(axes[1], e2, beta) # rotate both axes around y
......@@ -338,7 +338,7 @@ class PolygonSampler:
edgeVectors.sort(key=lambda v: getAngle(v))
# rotate by strike and dip angle
from frackit.common import rotate
from frackit.geometry import rotate
from frackit.geometry import Direction
dipAngle = self.dipAngleSampler()
strikeAngle = self.strikeAngleSampler()
......@@ -435,7 +435,7 @@ class QuadrilateralSampler:
axes = [Vector_3(1.0, 0.0, 0.0), Vector_3(0.0, 1.0, 0.0)]
from frackit.geometry import Direction_3
from frackit.common import rotate
from frackit.geometry import rotate
rotate(axes[0], Direction_3(Vector_3(0.0, 0.0, 1.0)), strike);
rotate(axes[1], Direction_3(Vector_3(0.0, 0.0, 1.0)), strike);
rotate(axes[0], Direction_3(axes[1]), dip);
......
Markdown is supported
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