Spatial C++ Library
Generic Multi-Dimensional Containers and Spatial Operations
spatial::math Namespace Reference

Functions

template<typename Key , typename Difference , typename Unit >
enable_if< import::is_arithmetic< Unit >, Unit >::type square_euclid_distance_to_plane (dimension_type dim, const Key &origin, const Key &key, Difference diff)
 Compute the distance between the origin and the closest point to the plane orthogonal to the axis of dimension dim and passing by key. More...
 
template<typename Key , typename Difference , typename Unit >
enable_if< import::is_arithmetic< Unit >, Unit >::type square_euclid_distance_to_key (dimension_type rank, const Key &origin, const Key &key, Difference diff)
 Compute the square value of the distance between origin and key. More...
 
template<typename Key , typename Difference , typename Unit >
enable_if< import::is_floating_point< Unit >, Unit >::type euclid_distance_to_plane (dimension_type dim, const Key &origin, const Key &key, Difference diff)
 Compute the distance between the origin and the closest point to the plane orthogonal to the axis of dimension dim and passing by key. More...
 
template<typename Key , typename Difference , typename Unit >
enable_if< import::is_floating_point< Unit >, Unit >::type euclid_distance_to_key (dimension_type rank, const Key &origin, const Key &key, Difference diff)
 Computes the euclidian distance between 2 points. More...
 
template<typename Key , typename Difference , typename Unit >
enable_if< import::is_arithmetic< Unit >, Unit >::type manhattan_distance_to_plane (dimension_type dim, const Key &origin, const Key &key, Difference diff)
 Compute the distance between the origin and the closest point to the plane orthogonal to the axis of dimension dim and passing by key. More...
 
template<typename Key , typename Difference , typename Unit >
enable_if< import::is_arithmetic< Unit >, Unit >::type manhattan_distance_to_key (dimension_type rank, const Key &origin, const Key &key, Difference diff)
 Compute the manhattan distance between origin and key. More...
 

Function Documentation

template<typename Key , typename Difference , typename Unit >
enable_if<import::is_floating_point<Unit>, Unit>::type spatial::math::euclid_distance_to_key ( dimension_type  rank,
const Key &  origin,
const Key &  key,
Difference  diff 
)

Computes the euclidian distance between 2 points.

When compiled without SPATIAL_SAFER_ARITHMETICS, it uses the naive approach, which may overflow or underflow, but is much faster.

When compiled without SPATIAL_SAFER_ARITHMETICS the calculation uses the hypot() algorithm in order to compute the distance: minimize possibilities of overflow or underflow at the expense of speed.

The principle of hypot() is to find the maximum value among all the component of the distance and then divide all other components with this one.

The algorithm comes from this equality: sqrt( x^2 + y^2 + z^2 + ... ) = abs(x) * sqrt( 1 + (y/x)^2 + (z/x)^2 + ...)

Where the second form (on the right of the equation) is less likely to overflow or underflow than the first form during computation.

Definition at line 263 of file spatial_math.hpp.

template<typename Key , typename Difference , typename Unit >
enable_if<import::is_floating_point<Unit>, Unit>::type spatial::math::euclid_distance_to_plane ( dimension_type  dim,
const Key &  origin,
const Key &  key,
Difference  diff 
)

Compute the distance between the origin and the closest point to the plane orthogonal to the axis of dimension dim and passing by key.

Definition at line 235 of file spatial_math.hpp.

template<typename Key , typename Difference , typename Unit >
enable_if<import::is_arithmetic<Unit>, Unit>::type spatial::math::manhattan_distance_to_key ( dimension_type  rank,
const Key &  origin,
const Key &  key,
Difference  diff 
)

Compute the manhattan distance between origin and key.

Definition at line 320 of file spatial_math.hpp.

template<typename Key , typename Difference , typename Unit >
enable_if<import::is_arithmetic<Unit>, Unit>::type spatial::math::manhattan_distance_to_plane ( dimension_type  dim,
const Key &  origin,
const Key &  key,
Difference  diff 
)

Compute the distance between the origin and the closest point to the plane orthogonal to the axis of dimension dim and passing by key.

Definition at line 305 of file spatial_math.hpp.

template<typename Key , typename Difference , typename Unit >
enable_if<import::is_arithmetic<Unit>, Unit>::type spatial::math::square_euclid_distance_to_key ( dimension_type  rank,
const Key &  origin,
const Key &  key,
Difference  diff 
)

Compute the square value of the distance between origin and key.

Definition at line 210 of file spatial_math.hpp.

template<typename Key , typename Difference , typename Unit >
enable_if<import::is_arithmetic<Unit>, Unit>::type spatial::math::square_euclid_distance_to_plane ( dimension_type  dim,
const Key &  origin,
const Key &  key,
Difference  diff 
)

Compute the distance between the origin and the closest point to the plane orthogonal to the axis of dimension dim and passing by key.

Definition at line 193 of file spatial_math.hpp.