Module OgamlMath.Vector2f

Operations on immutable vectors of 2 floats

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

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

Vector operations

type t = {x : float; y : float}
Type of immutable vectors of 2 floats

Record fields

x : float
y : float
val make : float -> float -> 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 : float -> t -> t
Multiplies a vector by a scalar
val div : float -> t -> t
Divides a vector by a scalar. Raises Vector2f_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 to_int : t -> Vector2i.t
Truncates the floating-point coordinates of a vector
See : OgamlMath.Vector2i
val from_int : Vector2i.t -> t
Returns a float vector from an int vector
See : OgamlMath.Vector2i
val dot : t -> t -> float
Computes the dot product of two vectors
val det : t -> t -> float
Computes the determinant of two vectors
val angle : t -> t -> float
Computes the angle (in radians) between two vectors
val squared_norm : t -> float
Computes the squared norm of a vector
val norm : t -> float
Computes the norm of a vector
val squared_dist : t -> t -> float
Computes the squared distance between two points
val dist : t -> t -> float
Computes the distance between two points
val normalize : t -> t
Normalizes a vector. Raises Vector2f_exception if the vector is zero.
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 -> (float -> float) -> t
Maps each coordinate of a vector
val map2 : t -> t -> (float -> float -> float) -> t
Maps each pair of coordinates of two vectors
val max : t -> float
Returns the maximal coordinate of a vector
val min : t -> float
Returns the minimal coordinate of a vector
val print : t -> string
Returns a pretty-printed string (not for serialization)
val direction : t -> t -> t
direction u v returns the normalized direction vector from u to v . Raises Vector2f_exception if u = v .
val endpoint : t -> t -> float -> t
endpoint a v t returns the point a + tv
val raytrace_points : t -> t -> (float * t * t) list
raytrace_points p1 p2 returns the list of integer-valued points (squares) on the line from p1 to p2
Each point is a triplet of the form (t, p, f) such that :
t is the time at the intersection between the line and the point
p stores the (integer) coordinates of the point
f is a unit vector indicating which face of the square has been intersected
val raytrace : t -> t -> float -> (float * t * t) list
raytrace p v t applies raytrace_points between the points p and p + tv . The intersection times are comprised between 0 and t