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

Defines a metric for the a space where distances are the sum of all the elements of the vector. More...

#include <metric.hpp>

Inherits Diff.

Inherited by spatial::details::Compress< manhattan< Ct, DistanceType, Diff >, typename spatial::container_traits< const Ct >::key_type > [private], and spatial::details::Compress< manhattan< 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

 manhattan (const difference_type &diff=Diff())
 A constructor that allows you to specify the Difference type. More...
 
template<typename AnyDistanceType >
 manhattan (const manhattan< 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::manhattan< Ct, DistanceType, Diff >

Defines a metric for the a space where distances are the sum of all the elements of the vector.

Also known as the taxicab metric.

Concept:
This object is a model of Metric.
Template Parameters
CtThe container used with this metric.
DistanceTypeThe type used to compute distance values.
DiffA difference functor that compute the difference between 2 elements of a the Container's key type, along the same dimension.

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

This metric is the fastest of all built-in metric, and generally offers an acceptable approaximation to the euclidian metric. However the distance calculated by this metric cannot be converted into Euclidian distances. If you are looking for a fast metric that is convertible in Euclidian distances, check out quadrance.

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 231 of file metric.hpp.

Member Typedef Documentation

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

Definition at line 235 of file metric.hpp.

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

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

Definition at line 243 of file metric.hpp.

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

Definition at line 252 of file metric.hpp.

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

The key_type of the container being used for calculations.

Definition at line 249 of file metric.hpp.

Constructor & Destructor Documentation

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

A constructor that allows you to specify the Difference type.

Definition at line 255 of file metric.hpp.

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

Copy the metric from another metric with any DistanceType.

Definition at line 259 of file metric.hpp.

Member Function Documentation

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

Returns the difference functor used in this type.

Definition at line 294 of file metric.hpp.

template<typename Ct, typename DistanceType, typename Diff>
distance_type spatial::manhattan< 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 manahattan distance.

Definition at line 267 of file metric.hpp.

template<typename Ct, typename DistanceType, typename Diff>
distance_type spatial::manhattan< 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 manhattan distance.

Definition at line 283 of file metric.hpp.


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