@thi.ng/vectors
Version:
Optimized 2d/3d/4d and arbitrary length vector operations, support for memory mapping/layouts
32 lines • 1.02 kB
TypeScript
import type { DistanceFn, ReadonlyVec } from "./api.js";
/**
* Higher order distance function. Takes an existing {@link DistanceFn} `fn` and
* a vector of `weights` to control impact of each dimension. Returns new
* {@link DistanceFn}, which when called, first applies `weights` to both inputs
* and then uses `fn` to compute distance between the weighted results.
*
* @example
* ```ts tangle:../export/weighted-distance.ts
* import { dist3, weightedDistance, ONE3, ZERO3 } from "@thi.ng/vectors";
*
* // custom distance function, ignoring Y-component
* const distXZ = weightedDistance(dist3, [1, 0, 1]);
*
* // distance in XZ plane only
* console.log(
* distXZ(ONE3, ZERO3)
* );
* // 1.4142135623730951
*
* // compare with full Eucledian distance
* console.log(
* dist3(ONE3, ZERO3)
* );
* // 1.7320508075688772
* ```
*
* @param fn -
* @param weights -
*/
export declare const weightedDistance: (fn: DistanceFn, weights: ReadonlyVec) => DistanceFn;
//# sourceMappingURL=dist-weighted.d.ts.map