Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Manhattan<T>

Manhattan distance metric and conversion to/from Eucledian distances.

remarks

The conversion are always based on n-D squares, i.e. the assumption that the distance is equally shared in each dimension.

E.g. a Manhattan distance of 30 could be obtained from [0,0] -> [10,20], but would be interpreted here as distance from [0,0] -> [15,15], which produces the same Manhattan value, but yields a different Eucledian result. For lack of any other information about the distance values, this is however the only way to approach conversion and is sufficient for the purposes of this package...

example
MANHATTAN2.metric([0,0], [10,20])
// 30

MANHATTAN2.from(30);
// 21.213203435596427

Math.hypot(15, 15) // <-- diagonal of manhattan square
// 21.213203435596427

Math.hypot(10, 20) // <-- actual eucledian dist
// 22.360679774997898

MANHATTAN2.to(21.213203435596427)
// 30

// however, starting w/ eucledian dist first
e = mag([10, 20])
// 22.360679774997898

m = MANHATTAN2.to(e)
// 31.622776601683793

MANHATTAN2.from(m) === e
// true

Type parameters

  • T

Hierarchy

  • Manhattan

Implements

Index

Constructors

Properties

Methods

Constructors

constructor

Properties

Protected _invD

_invD: number

Readonly dim

dim: number

Readonly metric

metric: Metric<T>

The actual distance function metric.

Methods

from

  • from(x: number): number

to

  • to(x: number): number

Generated using TypeDoc