Module Gg.M2
type t
= m2
The type for 2D square matrices.
type v
= v2
The type for rows and columns as vectors.
Constructors, accessors and constants
val v : float -> float -> float -> float -> m2
v e00 e01 e10 e11
is a matrix whose components are specified in row-major order
val el : int -> int -> m2 -> float
el i j a
is the elementa
ij
. See also the direct element accessors.- raises Invalid_argument
if
i
orj
is not in [0;
dim
[.
Functions
val mul : m2 -> m2 -> m2
mul a b
is the matrix multiplicationa * b
.
val trace : m2 -> float
trace a
is the matrix tracetrace(a)
.
val det : m2 -> float
det a
is the determinant|a|
.
val inv : m2 -> m2
inv a
is the inverse matrixa
-1.
2D space transformations
val rot2 : float -> m2
rot2 theta
rotates 2D space around the origin bytheta
radians.
Traversal
val mapi : (int -> int -> float -> float) -> m2 -> m2
mapi f a
is likemap
but the element indices are also given.
val fold : ('a -> float -> 'a) -> 'a -> m2 -> 'a
fold f acc a
isf (
...(f (f acc a
00) a
10)
...)
.
val foldi : ('a -> int -> int -> float -> 'a) -> 'a -> m2 -> 'a
foldi f acc a
isf (
...(f (f acc 0 0 a
00) 1 0 a
10)
...)
.
val iter : (float -> unit) -> m2 -> unit
iter f a
isf a
00; f a
10;
...
val iteri : (int -> int -> float -> unit) -> m2 -> unit
iteri f a
isf 0 0 a
00; f 1 0 a
10;
...
Predicates and comparisons
val for_all : (float -> bool) -> m2 -> bool
for_all p a
isp a
00&& p a
10&&
...
val exists : (float -> bool) -> m2 -> bool
exists p a
isp a
00|| p a
10||
...
val equal_f : (float -> float -> bool) -> m2 -> m2 -> bool
equal_f eq a b
testsa
andb
likeequal
but useseq
to test floating point values.
Printers
val pp : Stdlib.Format.formatter -> m2 -> unit
pp ppf a
prints a textual representation ofa
onppf
.
val pp_f : (Stdlib.Format.formatter -> float -> unit) -> Stdlib.Format.formatter -> m2 -> unit
pp_f pp_e ppf a
printsa
likepp
but usespp_e
to print floating point values.