Module OgamlMath.FloatRect

Operations on float rectangles

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

type t = {x : float; y : float; width : float; height : float}
Type of immutable rectangles of floats

Record fields

x : float
y : float
width : float
height : float
val create : Vector2f.t -> Vector2f.t -> t
create position size creates a rectangle at position position and of size size
val create_from_points : Vector2f.t -> Vector2f.t -> t
create_from_points p1 p2 creates a rectangle going from p1 to p2
val zero : t
Zero rectangle
val one : t
Unit rectangle
val position : t -> Vector2f.t
Returns the position of a rectangle
val abs_position : t -> Vector2f.t
Returns the absolute position of a rectangle, that is the point of minimal coordinates
val corner : t -> Vector2f.t
Returns the top corner (aka position + size) of a rectangle
val abs_corner : t -> Vector2f.t
Returns the absolute corner of a rectangle, that is the point of maximal coordinates
val size : t -> Vector2f.t
Returns the size of a rectangle
val abs_size : t -> Vector2f.t
Returns the absolute size of a rectangle
val center : t -> Vector2f.t
Returns the center of a rectangle
val normalize : t -> t
normalize rect returns a rectangle equivalent to rect but with positive size
val area : t -> float
Returns the area of a rectangle
val scale : t -> Vector2f.t -> t
Scales a rectangle
val extend : t -> Vector2f.t -> t
Adds a vector to the height and width of a rectangle. Be careful since if the rectangle is not normalized, adding a positive vector may reduce the effective size of the rectangle.
val translate : t -> Vector2f.t -> t
Translates a rectangle
val from_int : IntRect.t -> t
Converts an integer rectangle to a float rectangle
val to_int : t -> IntRect.t
Truncates the floating-point coordinates of a rectangle
See : OgamlMath.IntRect
val intersects : t -> t -> bool
intersects t1 t2 returns true iff t1 and t2 overlap
val contains : t -> Vector2f.t -> bool
contains t p returns true iff the rectangle t contains p
val includes : t -> t -> bool
includes t r returns true iff the rectangle r is included in the rectangle t
val print : t -> string
Returns a pretty-printed string (not for serialization)