Module OgamlMath.IntRect

Operations on integer rectangles

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

type t = {x : int; y : int; width : int; height : int}
Type of immutable rectangles of integers

Record fields

x : int
y : int
width : int
height : int
val create : Vector2i.t -> Vector2i.t -> t
create position size creates a rectangle at position position and of size size
val create_from_points : Vector2i.t -> Vector2i.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 -> Vector2i.t
Returns the position of a rectangle
val abs_position : t -> Vector2i.t
Returns the absolute position of a rectangle, that is the point of minimal coordinates
val corner : t -> Vector2i.t
Returns the top corner (aka position + size) of a rectangle
val abs_corner : t -> Vector2i.t
Returns the absolute corner of a rectangle, that is the point of maximal coordinates
val size : t -> Vector2i.t
Returns the size of a rectangle
val abs_size : t -> Vector2i.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 -> int
Returns the area of a rectangle
val scale : t -> Vector2i.t -> t
Scales a rectangle
val extend : t -> Vector2i.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 -> Vector2i.t -> t
Translates a rectangle
val intersects : t -> t -> bool
intersects t1 t2 returns true iff t1 and t2 overlap
val includes : t -> t -> bool
includes t r returns true iff the rectangle r is included in the rectangle t
val contains : ?strict:bool -> t -> Vector2i.t -> bool
contains t p returns true iff the rectangle t contains p
if strict is set to true then upper bounds are not included (false by default)
val iter : ?strict:bool -> t -> (Vector2i.t -> unit) -> unit
iter t f iterates through all points of the rectangle t
if strict is set to false then upper bounds are included (true by default)
val fold : ?strict:bool -> t -> (Vector2i.t -> 'a -> 'a) -> 'a -> 'a
fold t f u folds through all points of the rectangle t
if strict is set to false then upper bounds are included (true by default)
val print : t -> string
Returns a pretty-printed string (not for serialization)