Spatial C++ Library
Generic Multi-Dimensional Containers and Spatial Operations
spatial::quadrance< Ct, DistanceType, Diff > Class Template Reference

Defines a metric in the Euclidian space where only the square of the distances are being computed into a scalar value expressed with the DistanceType which is one of C++'s arithmetic types. More...

#include <metric.hpp>

Inherits Diff.

Inherited by spatial::details::Compress< quadrance< Ct, DistanceType, Diff >, typename spatial::container_traits< const Ct >::key_type > [private], and spatial::details::Compress< quadrance< Ct, DistanceType, Diff >, typename spatial::container_traits< Ct >::key_type > [private].

Public Types

typedef details::rebind_builtin_difference< Diff, DistanceType >::type difference_type
 The type used to compute the difference between 2 keys along the same dimension. More...
 
typedef DistanceType distance_type
 

Public Member Functions

 quadrance (const difference_type &diff=Diff())
 The constructor allows you to specify a custom difference type. More...
 
template<typename AnyDistanceType >
 quadrance (const quadrance< Ct, AnyDistanceType, Diff > &other)
 Copy the metric from another metric with any DistanceType. More...
 
distance_type distance_to_key (dimension_type rank, const key_type &origin, const key_type &key) const
 Compute the distance between the point of origin and the key. More...
 
distance_type distance_to_plane (dimension_type, dimension_type dim, const key_type &origin, const key_type &key) const
 The distance between the point of origin and the closest point to the plane orthogonal to the axis of dimension dim and crossing key. More...
 
difference_type difference () const
 Returns the difference functor used in this type. More...
 

Private Types

typedef enable_if< import::is_arithmetic< DistanceType > >::type check_concept_distance_type_is_arithmetic
 
typedef container_traits< Ct >::key_type key_type
 The key_type of the container being used for calculations. More...
 

Detailed Description

template<typename Ct, typename DistanceType, typename Diff>
class spatial::quadrance< Ct, DistanceType, Diff >

Defines a metric in the Euclidian space where only the square of the distances are being computed into a scalar value expressed with the DistanceType which is one of C++'s arithmetic types.

Concept:
This object is a model of Metric

This method of distance calculation is more flexible than spatial::euclidian since it can support all of the C++'s arithmetic types.

When using this metric and reading the distance value, you must remember that you are reading the square of the distance, and not the real distance. Thus, you should use square root to recover the real distance.

This metric has one important drawback: if you are working with large value over the entire range permissible by DistanceType, then chances that the computation overflows is non-negligible. To receive an arithmetic_error exception upon overflow, compile your application with #define SPATIAL_SAFER_ARITHEMTICS.

Definition at line 138 of file metric.hpp.

Member Typedef Documentation

template<typename Ct, typename DistanceType, typename Diff>
typedef enable_if<import::is_arithmetic<DistanceType> >::type spatial::quadrance< Ct, DistanceType, Diff >::check_concept_distance_type_is_arithmetic
private

Definition at line 142 of file metric.hpp.

template<typename Ct, typename DistanceType, typename Diff>
typedef details::rebind_builtin_difference<Diff, DistanceType>::type spatial::quadrance< Ct, DistanceType, Diff >::difference_type

The type used to compute the difference between 2 keys along the same dimension.

Definition at line 150 of file metric.hpp.

template<typename Ct, typename DistanceType, typename Diff>
typedef DistanceType spatial::quadrance< Ct, DistanceType, Diff >::distance_type

Definition at line 159 of file metric.hpp.

template<typename Ct, typename DistanceType, typename Diff>
typedef container_traits<Ct>::key_type spatial::quadrance< Ct, DistanceType, Diff >::key_type
private

The key_type of the container being used for calculations.

Definition at line 156 of file metric.hpp.

Constructor & Destructor Documentation

template<typename Ct, typename DistanceType, typename Diff>
spatial::quadrance< Ct, DistanceType, Diff >::quadrance ( const difference_type diff = Diff())
explicit

The constructor allows you to specify a custom difference type.

Definition at line 162 of file metric.hpp.

template<typename Ct, typename DistanceType, typename Diff>
template<typename AnyDistanceType >
spatial::quadrance< Ct, DistanceType, Diff >::quadrance ( const quadrance< Ct, AnyDistanceType, Diff > &  other)

Copy the metric from another metric with any DistanceType.

Definition at line 166 of file metric.hpp.

Member Function Documentation

template<typename Ct, typename DistanceType, typename Diff>
difference_type spatial::quadrance< Ct, DistanceType, Diff >::difference ( ) const

Returns the difference functor used in this type.

Definition at line 200 of file metric.hpp.

template<typename Ct, typename DistanceType, typename Diff>
distance_type spatial::quadrance< Ct, DistanceType, Diff >::distance_to_key ( dimension_type  rank,
const key_type origin,
const key_type key 
) const

Compute the distance between the point of origin and the key.

Returns
The resulting square distance.

Definition at line 174 of file metric.hpp.

template<typename Ct, typename DistanceType, typename Diff>
distance_type spatial::quadrance< Ct, DistanceType, Diff >::distance_to_plane ( dimension_type  ,
dimension_type  dim,
const key_type origin,
const key_type key 
) const

The distance between the point of origin and the closest point to the plane orthogonal to the axis of dimension dim and crossing key.

Returns
The resulting square distance.

Definition at line 189 of file metric.hpp.


The documentation for this class was generated from the following file: