View Source Tint.Distance behaviour (Tint v1.3.0)

A module providing functions for color distance calculations and a behavior to implement custom distance algorithms.

Summary

Types

A distance calculation module that implements this very behavior or a function that allows calculating the distance between two colors.

A function that allows calculating the distance between two colors.

Callbacks

Calculate the distance of two colors using the given options.

Functions

Calculate the distance of two colors using the given distance algorithm.

Gets the nearest color from the specified palette using the given distance algorithm.

Gets the nearest n colors from the specified palette using the given distance algorithm.

Types

@type distance_algorithm() :: module() | {module(), Keyword.t()} | distance_fun()

A distance calculation module that implements this very behavior or a function that allows calculating the distance between two colors.

@type distance_fun() :: (Tint.color(), Tint.color() -> number())

A function that allows calculating the distance between two colors.

Callbacks

Link to this callback

distance(color, other_color, opts)

View Source
@callback distance(
  color :: Tint.color(),
  other_color :: Tint.color(),
  opts :: Keyword.t()
) :: number()

Calculate the distance of two colors using the given options.

Functions

Link to this function

distance(color, other_color, distance_algorithm)

View Source
@spec distance(Tint.color(), Tint.color(), distance_algorithm()) :: float()

Calculate the distance of two colors using the given distance algorithm.

Link to this function

nearest_color(color, palette, distance_algorithm)

View Source
@spec nearest_color(Tint.color(), [Tint.color()], distance_algorithm()) ::
  nil | Tint.color()

Gets the nearest color from the specified palette using the given distance algorithm.

Link to this function

nearest_colors(color, palette, n, distance_algorithm)

View Source
@spec nearest_colors(
  Tint.color(),
  [Tint.color()],
  non_neg_integer(),
  distance_algorithm()
) :: [Tint.color()]

Gets the nearest n colors from the specified palette using the given distance algorithm.