package gg

  1. Overview
  2. Docs
type t = v4

The type for 4D vectors.

val dim : int

dim is the dimension of vectors of type v4.

type m = m4

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

Constructors, accessors and constants

val v : float -> float -> float -> float -> v4

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

val comp : int -> v4 -> float

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

val x : v4 -> float

x v is the x component of v.

val y : v4 -> float

y v is the y component of v.

val z : v4 -> float

z v is the z component of v.

val w : v4 -> float

z v is the z component of v.

val ox : v4

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

val oy : v4

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

val oz : v4

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

val ow : v4

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

val zero : v4

zero is the neutral element for add.

val infinity : v4

infinity is the vector whose components are infinity.

val neg_infinity : v4

neg_infinity is the vector whose components are neg_infinity.

val basis : int -> v4

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

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

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

val to_tuple : v4 -> float * float * float * float

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

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

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

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

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

Functions

val neg : v4 -> v4

neg v is the inverse vector -v.

val add : v4 -> v4 -> v4

add u v is the vector addition u + v.

val sub : v4 -> v4 -> v4

sub u v is the vector subtraction u - v.

val mul : v4 -> v4 -> v4

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

val div : v4 -> v4 -> v4

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

val smul : float -> v4 -> v4

smul s v is the scalar multiplication sv.

val half : v4 -> v4

half v is the half vector smul 0.5 v.

val dot : v4 -> v4 -> float

dot u v is the dot product u.v.

val norm : v4 -> float

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

val norm2 : v4 -> float

norm2 v is the squared norm |v|2 .

val unit : v4 -> v4

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

val homogene : v4 -> v4

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

val mix : v4 -> v4 -> float -> v4

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

val ltr : m4 -> v4 -> v4

ltr m v is the linear transform mv.

Overridden Pervasives operators

val (+) : v4 -> v4 -> v4

u + v is add u v.

val (-) : v4 -> v4 -> v4

u - v is sub u v.

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

t * v is smul t v.

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

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

Traversal

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

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

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

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

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

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

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

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

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

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

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

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

Predicates and comparisons

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

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

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

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

val equal : v4 -> v4 -> bool

equal u v is u = v.

val 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.

val compare : v4 -> v4 -> int

compare u v is Pervasives.compare u v.

val 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.

Printers

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

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

val 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.

OCaml

Innovation. Community. Security.