Module Vz.Nice

Nicing numbers.

XXX Maybe move that to Gg.Float

Nice numbers for nice labels and ticks.

Nice steps

val step : int -> float -> float -> float

step n v0 v1 is a nice step size for sampling the directed interval [v0;v1] approximatively n times. The step size is in the set { q⋅10z | q ∈ {1,2,5} and z ∈ Z } or 0 if v0 = v1. Raises Invalid_argument if n <= 0.

Quantized nicing

Given a positive step size step the following functions nice numbers so that they belong to the set Q(step) = { z⋅step | z ∈ Z }.

val step_floor : step:float -> float -> float

step_floor step v is the greatest v' such that v' <= v and v' ∈ Q(step). Raises Invalid_argument if step <= 0..

val step_ceil : step:float -> float -> float

step_ceil step v is the smallest v' such that v <= v' and v' ∈ Q(step). Raises Invalid_argument if step <= 0..

val step_round : step:float -> float -> float

step_round step v is either step_floor v or ceil_floor v whichever is the nearest. Ties are rounded towards away from zero. Raises Invalid_argument if step <= 0..

val step_fold : step:float -> ('a -> int -> float -> 'a) -> 'a -> float -> float -> 'a

step_fold step f acc v0 v1 folds f over set of numbers Q(step) ∩ [v0;v1]. Folding is performed in order and in the direction from v0 to v1. The integer given to f is the fractional precision of the numbers mandated by step. Raises Invalid_argument if step <= 0..

val step_outset : step:float -> float -> float -> float * float

step_outset step v0 v1 expands the directed interval [v0;v1] to (v0',v1') ∈ Q(step)2 where v0' (resp. v1') is the nearest number to v0 (resp. v1). Raises Invalid_argument if step <= 0..

val step_inset : step:float -> float -> float -> float * float

step_inset step v0 v1 shrinks the directed interval [v0;v1] to (v0',v1') ∈ Q(step)2 where v0' (resp. v1') is the nearest number to v0 (resp. v1). Raises Invalid_argument if step <= 0..