ND Points
Include <mln/core/point.hpp>
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 withndpoint
i.e. ifP::value_type
is convertible toT
andndim == (-1 || other.ndim)
.
-
ndpoint(int dim)
Construction with the number of dimensions given dynamically. Only available when
ndim == -1
.
-
ndpoint() = default
-
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.-
template<class P>
ndpointref(const P &other) Converting constructor from any point implementing the
__PointInterface
. This overload is enabled only if P is compatible withndpointref
, i.e. ifP::value_type*
is convertible toT*
andndim == (-1 || other.ndim)
.
-
template<class P>
Aliases
-
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
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.