package gg

  1. Overview
  2. Docs

Module Gg.V4Source

4D vectors.

Sourcetype t = v4

The type for 4D vectors.

Sourceval dim : int

dim is the dimension of vectors of type v4.

Sourcetype m = m4

The type for matrices representing linear transformations of 4D space.

Constructors, accessors and constants

Sourceval v : float -> float -> float -> float -> v4

v x y z w is the vector (x y z w).

Sourceval comp : int -> v4 -> float

comp i v is vi, the ith component of v.

Raises Invalid_argument if i is not in [0;dim[.

Sourceval x : v4 -> float

x v is the x component of v.

Sourceval y : v4 -> float

y v is the y component of v.

Sourceval z : v4 -> float

z v is the z component of v.

Sourceval w : v4 -> float

z v is the z component of v.

Sourceval ox : v4

ox is the unit vector (1. 0. 0. 0.).

Sourceval oy : v4

oy is the unit vector (0. 1. 0. 0.).

Sourceval oz : v4

oz is the unit vector (0. 0. 1. 0.).

Sourceval ow : v4

ow is the unit vector (0. 0. 0. 1.).

Sourceval zero : v4

zero is the neutral element for add.

Sourceval infinity : v4

infinity is the vector whose components are infinity.

Sourceval neg_infinity : v4

neg_infinity is the vector whose components are neg_infinity.

Sourceval basis : int -> v4

basis i is the ith vector of an orthonormal basis of the vector space t with inner product dot.

Raises Invalid_argument if i is not in [0;dim[.

Sourceval of_tuple : (float * float * float * float) -> v4

of_tuple (x, y, z, w) is v x y z w.

Sourceval to_tuple : v4 -> float * float * float * float

to_tuple v is (x v, y v, z v, w v).

Sourceval of_v2 : v2 -> z:float -> w:float -> v4

of_v2 u z w is v (V2.x u) (V2.y u) z w.

Sourceval of_v3 : v3 -> w:float -> v4

of_v3 u w is v (V3.x u) (V3.y u) (V3.z u) w.

Functions

Sourceval neg : v4 -> v4

neg v is the inverse vector -v.

Sourceval add : v4 -> v4 -> v4

add u v is the vector addition u + v.

Sourceval sub : v4 -> v4 -> v4

sub u v is the vector subtraction u - v.

Sourceval mul : v4 -> v4 -> v4

mul u v is the component wise multiplication u * v.

Sourceval div : v4 -> v4 -> v4

div u v is the component wise division u / v.

Sourceval smul : float -> v4 -> v4

smul s v is the scalar multiplication sv.

Sourceval half : v4 -> v4

half v is the half vector smul 0.5 v.

Sourceval dot : v4 -> v4 -> float

dot u v is the dot product u.v.

Sourceval norm : v4 -> float

norm v is the norm |v| = sqrt v.v.

Sourceval norm2 : v4 -> float

norm2 v is the squared norm |v|2 .

Sourceval unit : v4 -> v4

unit v is the unit vector v/|v|.

Sourceval homogene : v4 -> v4

homogene v is the vector v/vw if vw <> 0 and v otherwise.

Sourceval mix : v4 -> v4 -> float -> v4

mix u v t is the linear interpolation u + t(v - u).

Sourceval ltr : m4 -> v4 -> v4

ltr m v is the linear transform mv.

Overridden Stdlib operators

Sourceval (+) : v4 -> v4 -> v4

u + v is add u v.

Sourceval (-) : v4 -> v4 -> v4

u - v is sub u v.

Sourceval (*) : float -> v4 -> v4

t * v is smul t v.

Sourceval (/) : v4 -> float -> v4

v / t is smul (1. /. t) v.

Traversal

Sourceval map : (float -> float) -> v4 -> v4

map f v is the component wise application of f to v.

Sourceval mapi : (int -> float -> float) -> v4 -> v4

mapi f v is like map but the component index is also given.

Sourceval fold : ('a -> float -> 'a) -> 'a -> v4 -> 'a

fold f acc v is f (...(f (f acc v0) v1)...).

Sourceval foldi : ('a -> int -> float -> 'a) -> 'a -> v4 -> 'a

foldi f acc v is f (...(f (f acc 0 v0) 1 v1)...).

Sourceval iter : (float -> unit) -> v4 -> unit

iter f v is f v0; f v1; ...

Sourceval iteri : (int -> float -> unit) -> v4 -> unit

iteri f v is f 0 v0; f 1 v1; ...

Predicates and comparisons

Sourceval for_all : (float -> bool) -> v4 -> bool

for_all p v is p v0 && p v1 && ...

Sourceval exists : (float -> bool) -> v4 -> bool

exists p v is p v0 || p v1 || ...

Sourceval equal : v4 -> v4 -> bool

equal u v is u = v.

Sourceval equal_f : (float -> float -> bool) -> v4 -> v4 -> bool

equal_f eq u v tests u and v like equal but uses eq to test floating point values.

Sourceval compare : v4 -> v4 -> int

compare u v is Stdlib.compare u v.

Sourceval compare_f : (float -> float -> int) -> v4 -> v4 -> int

compare_f cmp u v compares u and v like compare but uses cmp to compare floating point values.

Formatters

Sourceval pp : Format.formatter -> v4 -> unit

pp ppf v prints a textual representation of v on ppf.

Sourceval pp_f : (Format.formatter -> float -> unit) -> Format.formatter -> v4 -> unit

pp_f pp_comp ppf v prints v like pp but uses pp_comp to print floating point values.