ND Points

Include <mln/core/point.hpp>

../_images/ndpoint.svg

Class hierarchy diagrams for ndpoints. They all implement the __PointInterface but differ in the storage and the compile-time number of dimension:

  • ndpoint provide points type with value semantics (they own the coordinates array). Point uses a dynamic array while point*N*d use a static array storage

  • nbpointref provide points type with reference semantics (they borrow the coordinates array). PointRef and ConstPointRef supports dynamic array bound while pointNd_ref and const_pointNd_ref provide compile-time bound checking.

template<int ndim, class T>
class ndpoint

ndpoint represents a n-dimensional points (coordinates) over a grid. The number of dimensions can be known at compile time or dynamic ndim = -1. It is a container (own the value).

ndpoint() = default

Default constructor.

template<class P>
ndpoint(const P &other)

Converting constructor from any point implementing the __PointInterface. This overload is enabled only if P is compatible with ndpoint i.e. if P::value_type is convertible to T and ndim == (-1 || other.ndim).

ndpoint(int dim)

Construction with the number of dimensions given dynamically. Only available when ndim == -1.

template<int ndim, class T>
class ndpointref

ndpointref represents a n-dimensional points (coordinates) over a grid. The number of dimensions can be known at compile time or dynamic ndim = -1. It has a reference semantic and should be used as a function parameter only.

  1. template<class P>
    ndpointref(P &other)
  2. template<class P>
    ndpointref(const P &other)

    Converting constructor from any point implementing the __PointInterface. This overload is enabled only if P is compatible with ndpointref, i.e. if P::value_type* is convertible to T* and ndim == (-1 || other.ndim).

ndpoint(int dim, T *coordinates)

Constructor from an array in the form of a pair (pointer, size).

Aliases

using Point = ndpoint<-1, int>
using point1d = ndpoint<1, int>
using point2d = ndpoint<2, int>
using point3d = ndpoint<3, int>
using PointRef = ndpointref<-1, int>
using point1d_ref = ndpointref<1, int>
using point2d_ref = ndpointref<2, int>
using point3d_ref = ndpointref<3, int>
using ConstPointRef = ndpointref<-1, const int>
using const_point1d_ref = ndpointref<1, const int>
using const_point2d_ref = ndpointref<2, const int>
using const_point3d_ref = ndpointref<3, const int>

Read-Only Point Interface

template<int ndim, class T>
class __PointInterface
using value_type = T
__PointInterface(std::initializer_list<T> coordinates)

Construction from a list of coordinates

const T *data() const

Return a pointer to the coordinates array.

int dim() const

return the number of dimension

T operator[](int k) const

Return the coordinate in the k-th dimension.

T x()

Get the x-coordinate (available when dim() >= 1)

T y()

Get the y-coordinate (available when dim() >= 2)

T z()

Get the z-coordinate (available when dim() >= 3)

Point Interopability

Any two points p₁ and p₂ of types P₁ and P₂ are said compatible if their value types are compatible and if they have the same number of dimensions (p₁.dim() == p₂.dim()). They thus share a common_reference (std::CommonReference˂P₁,P₂˃).

  • Conversion

    Two compatible points are convertible to each other (std::Convertible).

    Example:

    mln::point2d p1 = {x, y};
    mln::ndpoint<2, long> p2 = p1; // Ok (int to long conversion)
    mln::Point p3 = p1;            // Ok (static to dynamic conversion)
    mln::point2d p4 = p3;          // Ok (dynamic to static conversion with run-time dim assertion)
    
  • Comparison

    Two compatible points are comparable and totally ordered (std::totally_ordered) using the lexicographical ordering.

  • Arithmetics

    Two compatible points are Addable using usual arithmetic rules.

Mutable Point Interface

template<int ndim, class T>
class __MutablePointInterface
using value_type = T
__MutablePointInterface(std::initializer_list<T> coordinates)

Construction from a list of coordinates

T *data()

Return a pointer to the mutable coordinates array.

int dim() const

return the number of dimension

T &operator[](int k)

Return the coordinate in the k-th dimension.

T &x()

Get the x-coordinate (available when dim() >= 1)

T &y()

Get the y-coordinate (available when dim() >= 2)

T &z()

Get the z-coordinate (available when dim() >= 3)