Module Vz.Dom

Domains.

Domains describe sets of continuous or discrete values and how to inject them on the unit interval [0; 1.] and project them back.

Domains are also always equipped with a comparison function, a formatter and a function to select values for tick marks.

type 'a compare = 'a -> 'a -> int

The type for comparisons functions.

type 'a fmt = Stdlib.Format.formatter -> 'a -> unit

The type for formatting functions.

type piecewise_proj =
  1. | Proportional
    (*

    The bounds of the pieces are proportionally projected on the unit space. For example the bounds of the pieces [0.; 8.; 10.] are mapped on [0.; 0.8; 1.].

    *)
  2. | Uniform
    (*

    The bounds of the pieces are uniformly projected on the unit space. For example [0.; 2.; 10.] are mapped on [0.; 0.5; 1.].

    *)

The type for projections on the unit interval for piecewise continuous domains.

type kind =
  1. | Discrete
    (*

    Finite and ordered list of values.

    *)
  2. | Continuous of piecewise_proj
    (*

    Piecewise continuous domain.

    *)

The kind of domain, either discrete or continuous.

module Shape : sig ... end

Domain shaping.

type 'a t

The type for domains of type 'a.

val v : ?clamped:bool -> ?compare:'a compare -> ?proj_extents:(float -> 'a * 'a) -> ?unniced_values:'a list -> ?pp:'a fmt -> kind -> none:'a -> 'a list -> ('a -> float) -> (float -> 'a) -> 'a t
val kind : 'a t -> kind

kind d is the domain kind see kind.

val inj : 'a t -> 'a -> float

inj d v maps value v of the domain in the unit interval [0; 1.]. If clamped d is false the resulting value can lie outisde the unit interval. If v cannot be mapped it maps to Float.nan.

val proj : 'a t -> float -> 'a

inj d t is the inverse of proj, it maps t back to the domain value, if possible. If clamped d is true t is clamped to [0;1.]. If t cannot be mapped back it maps to none d.

val proj_extents : 'a t -> float -> 'a * 'a

inv_map d t is the inverse of map, but maps back to a range of the original domain. This is useful if inv_map is a quantization of the unit interval. If it's not this returns the point range inv_map d t.

val values : 'a t -> 'a list

values d is the list of values defining the domain. The semantics of which depends on kind.

val none : 'a t -> 'a

none d is the value returned by invert map when the value cannot be mapped back.

Continuous

val linear : ?nice:bool -> ?clamp:bool -> float -> float -> float t
val log : ?base:float -> ?nice:bool -> ?clamp:bool -> float -> float -> float t
val pow : ?exp:float -> ?nice:bool -> ?clamp:bool -> float -> float -> float t
val sqrt : ?nice:bool -> ?clamp:bool -> float -> float -> float t

Discrete

val discrete : ?compare:'a compare -> ?pp:'a fmt -> ?none:'a -> 'a list -> 'a t

discrete vs is a discrete domain with values vs. Given n values the ith zero-based position in the order is injected to i/n. The projection maps any value in the interval [i/n; (i+1)/n[ back to i. 1. maps to none which by default is the last n-1th element.