Template Class Point

Inheritance Relationships

Base Type

Class Documentation

template<class T = coordinate, size_t Dimensions = 0>
class Point : public NetworKit::PointImpl::Storage<coordinate, 0>

An abstraction to store k-dimensional geometric points. All arithmic operations are implemented element-wise; i.e., x * y does return a point (x[0]*y[0], x[1]*y[1], …) rather than the inner product (use Point::dot for this purpose).

The point supports both compile-time selection of dimensions (Dimensions > 0) and runtime selection (Dimensions = 0). If at all possible prefer setting the number of Dimensions at compile-time for performance reasons.

Public Functions

Point() = default
Point(const Point&) = default
Point &operator=(const Point&) = default
Point(Point&&) noexcept = default
Point &operator=(Point&&) noexcept = default
template<size_t otherDim>
inline Point &operator=(const Point<T, otherDim> &other)

Type conversion between points of different size.

template<size_t otherDim>
inline explicit Point(const Point<T, otherDim> &other)
inline count getDimensions() const noexcept

Returns number of coordinates stored within point.

inline T distance(const Point &p) const

Returns euclidian distance between this point and the one provided.

inline T squaredDistance(const Point &p) const noexcept

Return euclidian distance squared between this point and the one provided. Faster than distance()

inline T length() const

Returns 2-norm of point, i.e. sqrt{ sum_i point[i]*point[i] }.

inline T squaredLength() const noexcept

Returns 2-norm of point squard, i.e. sum_i point[i]*point[i]. It’s faster to compute than length().

inline Point &operator+=(const Point &other) noexcept

Elementwise addition, in-place.

inline Point &operator-=(const Point &other) noexcept

Elementwise subtraction, in-place.

inline Point &operator*=(const Point &other) noexcept

Elementwise multiplicate, in-place.

inline Point &operator/=(const Point &other) noexcept

Elementwise division, in-place.

inline Point &operator+=(T scalar) noexcept

Add constant to each coordinate, in-place.

inline Point &operator-=(T scalar) noexcept

Subtract constant from each coordinate, in-place.

inline Point &operator*=(T scalar) noexcept

Multiply each coordinate with constant, in-place.

inline Point &scale(T factor) noexcept

Alias to (*this) *= factor;.

inline Point &operator/=(T scalar) noexcept

Divide each coordinate with constant, in-place.

inline Point operator+(const Point &other) const

Elementwise addition.

inline Point operator-(const Point &other) const

Elementwise subtraction.

inline Point operator*(const Point &other) const

Elementwise multiplication.

inline Point operator/(const Point &other) const

Elementwise division.

inline Point operator+(T scalar) const

Elementwise addition.

inline Point operator-(T scalar) const

Elementwise subtraction.

inline Point operator*(T scalar) const

Elementwise multiplication.

inline Point operator/(T scalar) const

Elementwise division.

inline T dot(const Point &other) const noexcept

Computes the dot product (aka inner product)

inline bool operator==(const Point &other) const noexcept

Returns true, if all coordinates match.

inline bool operator!=(const Point &other) const noexcept

Returns false, if all coordinates match.

inline Point min(const Point &other) const

Compute element-wise min and returns new Point.

inline Point max(const Point &other) const

Compute element-wise min and returns new Point.

template<typename Func>
inline Func apply(Func fu)

Applies a function(index, data[i]) to each element of the point, and stores the value.

inline T &operator[](index i) noexcept

Access i-th coordintate without boundary check.

inline T &at(index i)

Access i-th coordintate with boundary check.

inline T operator[](index i) const noexcept

Access i-th coordintate without boundary check.

inline T at(index i) const

Access i-th coordintate with boundary check.

template<typename It>
inline void copyFrom(It begin)

Read coordinates from iterator.

inline std::string toString()

Default point to string conversion.

inline std::string toCsvString()

Point to comma separated string.

inline std::string toSsvString()

Point to space separated string.

inline std::string genericToString(const std::string &start, const std::string &sep, const std::string &end)

Public Static Functions

static inline std::vector<Point<coordinate, 2>> pointVectorToPoint2D(const std::vector<Point> &input)
static inline std::vector<Point<T>> point2DVectorToPoint(const std::vector<Point<coordinate, 2>> &input)

Protected Functions

inline void assertMatchingDimensions(const Point &o) const