Skip to content

Commit

Permalink
feat(color): replace proximity functions
Browse files Browse the repository at this point in the history
- add new proximity() HOF to replace proximityHsv/Rgb()
  • Loading branch information
postspectacular committed Feb 9, 2021
1 parent 6d15065 commit 7a0be62
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/color/src/ops/sort.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { Fn, typedArray, typedArrayType } from "@thi.ng/api";
import { quickSort, sortByCachedKey, swap } from "@thi.ng/arrays";
import { compareNumAsc, compareNumDesc } from "@thi.ng/compare";
import type { ReadonlyColor, TypedColor } from "../api";
import { distHsv, distRgb } from "./distance";
import type { ColorDistance, ReadonlyColor, TypedColor } from "../api";
import { distEucledian3 } from "./distance";

export const selectChannel = (id: number) => (col: ReadonlyColor) => col[id];

export const proximityHsv = (target: ReadonlyColor) => (col: ReadonlyColor) =>
distHsv(target, col);

export const proximityRgb = (target: ReadonlyColor) => (col: ReadonlyColor) =>
distRgb(target, col);
/**
* Takes a `target` color and optional `distance` function. Returns a new
* function which can be used as `key` function for {@link sort} to compute the
* distance metric of a color to the given `target`.
*
* @param target
* @param dist
*/
export const proximity = (
target: ReadonlyColor,
dist: ColorDistance = distEucledian3
) => (col: ReadonlyColor) => dist(target, col);

export const sort = (
colors: ReadonlyColor[],
Expand Down

0 comments on commit 7a0be62

Please sign in to comment.