package gg

  1. Overview
  2. Docs

Module type Gg.VSource

Implemented by all vector types.

Sourcetype t

The type for vectors.

Sourceval dim : int

dim is the dimension of vectors of type t.

Sourcetype m

The type for matrices representing linear transformations of dim space.

Constructors, accessors and constants

Sourceval comp : int -> t -> float

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

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

Sourceval zero : t

zero is the neutral element for add.

Sourceval infinity : t

infinity is the vector whose components are infinity.

Sourceval neg_infinity : t

neg_infinity is the vector whose components are neg_infinity.

Sourceval basis : int -> t

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

Functions

Sourceval neg : t -> t

neg v is the inverse vector -v.

Sourceval add : t -> t -> t

add u v is the vector addition u + v.

Sourceval sub : t -> t -> t

sub u v is the vector subtraction u - v.

Sourceval mul : t -> t -> t

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

Sourceval div : t -> t -> t

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

Sourceval smul : float -> t -> t

smul s v is the scalar multiplication sv.

Sourceval half : t -> t

half v is the half vector smul 0.5 v.

Sourceval dot : t -> t -> float

dot u v is the dot product u.v.

Sourceval norm : t -> float

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

Sourceval norm2 : t -> float

norm2 v is the squared norm |v|2 .

Sourceval unit : t -> t

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

Sourceval homogene : t -> t

homogene v is the vector v/(comp (dim - 1) v) if comp (dim - 1) v <> 0 and v otherwise.

Sourceval mix : t -> t -> float -> t

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

Sourceval ltr : m -> t -> t

ltr m v is the linear transform mv.

Overridden Stdlib operators

Sourceval (+) : t -> t -> t

u + v is add u v.

Sourceval (-) : t -> t -> t

u - v is sub u v.

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

t * v is smul t v.

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

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

Traversal

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

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

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

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

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

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

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

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

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

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

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

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

Predicates and comparisons

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

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

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

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

Sourceval equal : t -> t -> bool

equal u v is u = v.

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

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

Sourceval compare : t -> t -> int

compare u v is Stdlib.compare u v.

Sourceval compare_f : (float -> float -> int) -> t -> t -> 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 -> t -> unit

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

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

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