github ↗
docs menu

Module Hugin.Coord

Coordinate systems.

A coordinate system projects the normalised positions of a panel into its box, inverts that projection where it can, and generates the panel's axes. coord gives a figure's panels a coordinate system.

Coordinate systems

#type t

The type for coordinate systems.

#val cartesian : ?aspect:float -> unit -> t

cartesian ~aspect () maps normalised positions affinely onto the box of the panel, x from its left edge to its right and y from its bottom edge to its top, and draws x axes below the panel and y axes to its left. Without aspect, the panel takes the box the layout gives it. With aspect, one unit of y is aspect times as long on the page as one unit of x, a unit being one of the transform of a continuous scale (Continuous scales), such as a power of the base on a log scale, and one step of a band scale (Scale.length); a scale whose domain spans no unit, or more than the floats hold, counts as spanning one. So 1. gives equal data units on both axes, and square cells to two band scales of equal paddings. The aspect sizes the panel's grid track, so the spines of its neighbours stay aligned.

Raises Invalid_argument if aspect is not finite and positive.

#val equal : t -> t -> bool

equal c c' is true iff c and c' are the same coordinate system with equal parameters.

#val pp : Stdlib.Format.formatter -> t -> unit

pp ppf c formats c for debugging.

Projections

#type projection

The type for projections: a coordinate system fitted to a panel's box.

#val point : projection -> float -> float -> P2.t

point p x y is the point of the page, in points, at which p puts the normalised position (x, y). Positions outside the unit square extrapolate.

#val invert : projection -> P2.t -> (float * float) option

invert p pt is Some (x, y), the normalised position that p puts at the point pt of the page, possibly outside the unit square, or None if p puts no position there. Under cartesian it is Some _ for every finite pt if the panel's box has a positive width and height, and None otherwise.