module M2: sig
.. end
type
t = Gg.m2
The type for 2D square matrices.
val dim : int
dim
is the dimension of rows and columns.
type
v = Gg.v2
The type for rows and columns as vectors.
Constructors, accessors and constants
val v : float -> float -> float -> float -> Gg.m2
v e00 e01 e10 e11
is a matrix whose components are
specified in
row-major order
val of_rows : Gg.v2 -> Gg.v2 -> Gg.m2
of_rows r0 r1
is the matrix whose rows are r0
and r1
.
val of_cols : Gg.v2 -> Gg.v2 -> Gg.m2
of_cols c0 c1
is the matrix whose columns are c0
and c1
.
val el : int -> int -> Gg.m2 -> float
val row : int -> Gg.m2 -> Gg.v2
row i a
is the
i
th row of
a
.
Raises Invalid_argument
if
i
is not in [
0;
Gg.M2.dim
[.
val col : int -> Gg.m2 -> Gg.v2
col j a
is the
j
th column of
a
.
Raises Invalid_argument
if
j
is not in [
0;
Gg.M2.dim
[.
val zero : Gg.m2
val id : Gg.m2
id
is the identity matrix, the neutral element for
Gg.M2.mul
.
val of_m3 : Gg.m3 -> Gg.m2
of_m3 m
extracts the 2D linear part (top-left 2x2 matrix) of m
.
val of_m4 : Gg.m4 -> Gg.m2
of_m4 m
extracts the 2D linear part (top-left 2x2 matrix) of m
.
Functions
val neg : Gg.m2 -> Gg.m2
neg a
is the negated matrix -a
.
val add : Gg.m2 -> Gg.m2 -> Gg.m2
add a b
is the matrix addition a + b
.
val sub : Gg.m2 -> Gg.m2 -> Gg.m2
sub a b
is the matrix subtraction a - b
.
val mul : Gg.m2 -> Gg.m2 -> Gg.m2
val emul : Gg.m2 -> Gg.m2 -> Gg.m2
emul a b
is the element wise multiplication of a
and b
.
val ediv : Gg.m2 -> Gg.m2 -> Gg.m2
ediv a b
is the element wise division of a
and b
.
val smul : float -> Gg.m2 -> Gg.m2
smul s a
is a
's elements multiplied by the scalar s
.
val transpose : Gg.m2 -> Gg.m2
val trace : Gg.m2 -> float
val det : Gg.m2 -> float
val inv : Gg.m2 -> Gg.m2
val rot : float -> Gg.m2
rot theta
rotates 2D space around the origin by theta
.
val scale : Gg.v2 -> Gg.m2
scale s
scales 2D space in the x
and y
dimensions
according to s
.
Traversal
val map : (float -> float) -> Gg.m2 -> Gg.m2
map f a
is the element wise application of f
to a
.
val mapi : (int -> int -> float -> float) -> Gg.m2 -> Gg.m2
mapi f a
is like
Gg.M2.map
but the element indices are also given.
val fold : ('a -> float -> 'a) -> 'a -> Gg.m2 -> 'a
fold f acc a
is f (
...(f (f acc a
00) a
10)
...)
.
val foldi : ('a -> int -> int -> float -> 'a) -> 'a -> Gg.m2 -> 'a
foldi f acc a
is
f (
...(f (f acc 0 0 a
00) 1 0 a
10)
...)
.
val iter : (float -> unit) -> Gg.m2 -> unit
iter f a
is f a
00; f a
10;
...
val iteri : (int -> int -> float -> unit) -> Gg.m2 -> unit
iteri f a
is f 0 0 a
00; f 1 0 a
10;
...
Predicates and comparisons
val for_all : (float -> bool) -> Gg.m2 -> bool
for_all p a
is p a
00 && p a
10 &&
...
val exists : (float -> bool) -> Gg.m2 -> bool
exists p a
is p a
00 || p a
10 ||
...
val equal : Gg.m2 -> Gg.m2 -> bool
equal a b
is a = b
.
val equal_f : (float -> float -> bool) -> Gg.m2 -> Gg.m2 -> bool
equal_f eq a b
tests
a
and
b
like
Gg.M2.equal
but
uses
eq
to test floating point values.
val compare : Gg.m2 -> Gg.m2 -> int
compare a b
is Pervasives.compare a b
. That is
lexicographic comparison in column-major order.
val compare_f : (float -> float -> int) -> Gg.m2 -> Gg.m2 -> int
compare_f cmp a b
compares
a
and
b
like
Gg.M2.compare
but uses
cmp
to compare floating point values.
Printers
val to_string : Gg.m2 -> string
to_string a
is a textual representation of a
.
val pp : Format.formatter -> Gg.m2 -> unit
pp ppf a
prints a textual representation of a
on ppf
.
val pp_f : (Format.formatter -> float -> unit) -> Format.formatter -> Gg.m2 -> unit
pp_f pp_e ppf a
prints
a
like
Gg.M2.pp
but uses
pp_e
to print floating point values.
Element accessors
val e00 : Gg.m2 -> float
val e01 : Gg.m2 -> float
val e10 : Gg.m2 -> float
val e11 : Gg.m2 -> float