Module OgamlMath.Vector2i

Operations on immutable vectors of 2 integers

This module defines the vector2i type and various operations on it.

exception Vector2i_exception of string
Raised when an error occurs (usually a division by zero)

Vector operations

type t = {x : int; y : int}
Type of immutable vectors of 2 integers

Record fields

x : int
y : int
val make : int -> int -> t
Fast way to create a vector
val zero : t
Zero vector
val unit_x : t
Unit x vector
val unit_y : t
Unit y vector
val add : t -> t -> t
Adds two vectors together
val sub : t -> t -> t
sub u v computes the vector u - v
val prop : int -> t -> t
Multiplies a vector by a scalar
val div : int -> t -> t
Divides a vector by a scalar. Raises Vector2i_exception if the scalar is zero.
val pointwise_product : t -> t -> t
Computes the pointwise product of two vectors.
val pointwise_div : t -> t -> t
Computes the pointwise division of two vectors.
val dot : t -> t -> int
Computes the dot product of two vectors
val det : t -> t -> int
Computes the determinant of two vectors
val angle : t -> t -> float
Computes the angle (in radians) between two vectors
val squared_norm : t -> int
Computes the squared norm of a vector
val norm : t -> float
Computes the norm of a vector
val squared_dist : t -> t -> int
Computes the squared distance between two points
val dist : t -> t -> float
Computes the distance between two points
val clamp : t -> t -> t -> t
clamp v a b returns the vector whose coordinates are the coordinates of v clamped between the coordinates of a and b
val map : t -> (int -> int) -> t
Maps each coordinate of a vector
val map2 : t -> t -> (int -> int -> int) -> t
Maps each pair of coordinates of two vectors
val max : t -> int
Returns the maximal coordinate of a vector
val min : t -> int
Returns the minimal coordinate of a vector
val raster : t -> t -> t list
raster p1 p2 applies the Bresenham's line algorithm between the pointsp1 and p2 and returns the list of points constituting the line
Note : should not be used for precise raytracing as it may miss points
val print : t -> string
Returns a pretty-printed string (not for serialization)