package gg

  1. Overview
  2. Docs

Module Gg.Box2Source

2D axis-aligned boxes.

Sourcetype t = box2

The type for 2D boxes (rectangles).

Sourceval dim : int

dim is the dimension of the boxes of type box2.

Sourcetype v = v2

The type for 2D vectors.

Sourcetype p = p2

The type for 2D points.

Sourcetype size = size2

The type for 2D sizes.

Sourcetype m = m2

The type for matrices representing linear transformations of 2D space.

Constructors, accessors and constants

Sourceval v : p2 -> size2 -> box2

v o size is a box whose origin is o and size is size.

Sourceval v_mid : p2 -> size2 -> t

v_mid mid size is a box whose mid point is mid and size is size.

Sourceval empty : box2

empty is the empty box.

Sourceval o : box2 -> p2

o b is the origin of b.

Raises Invalid_argument on empty

Sourceval ox : box2 -> float

ox b is V2.x (o b).

Sourceval oy : box2 -> float

oy b is V2.y (o b).

Sourceval size : box2 -> size

size b is the size of b.

Raises Invalid_argument on empty

Sourceval w : box2 -> float

w b is Size2.w (size b).

Sourceval h : box2 -> float

h b is Size2.h (size b).

Sourceval zero : box2

zero is a box whose origin and size is zero.

Sourceval unit : box2

unit is the unit box which extends from zero to one in all dimensions.

Sourceval of_pts : p2 -> p2 -> box2

of_pts p p' is the smallest box whose space contains p and p'.

Sourceval add_pt : box2 -> p2 -> box2

add_pt b p is the smallest box whose space contains b and p.

Functions

Sourceval min : box2 -> p2

min b is the smallest point of b (its origin).

Raises Invalid_argument on empty

Sourceval minx : box2 -> float

minx b is V2.x (min b).

Sourceval miny : box2 -> float

miny b is V2.y (min b).

Sourceval max : box2 -> p2

max b is the greatest point of b (its size added to the origin).

Raises Invalid_argument on empty

Sourceval maxx : box2 -> float

maxx b is V2.x (max b).

Sourceval maxy : box2 -> float

maxy b is V2.y (max b).

Sourceval mid : box2 -> p2

mid b is the mid point between min and max.

Raises Invalid_argument on empty

Sourceval midx : box2 -> float

midx b is V2.x (mid b).

Sourceval midy : box2 -> float

midy b is V2.y (mid b).

Sourceval bl_pt : box2 -> p2

bl b is the bottom-left corner of b.

Raises Invalid_argument on empty

Sourceval bm_pt : box2 -> p2

bm_pt b is the bottom-mid point of b.

Raises Invalid_argument on empty

Sourceval br_pt : box2 -> p2

br_pt b is the bottom-right corner of b.

Raises Invalid_argument on empty

Sourceval ml_pt : box2 -> p2

ml_pt b is the mid-left corner of b.

Raises Invalid_argument on empty

Sourceval mm_pt : box2 -> p2

ml_pt b is {!mid} b.

Raises Invalid_argument on empty

Sourceval mr_pt : box2 -> p2

mr_pt b is the mid-right point of b.

Raises Invalid_argument on empty

Sourceval tl_pt : box2 -> p2

tl_pt b is the top-left corner of b.

Raises Invalid_argument on empty

Sourceval tm_pt : box2 -> p2

tm_pt b is the top-middle corner of b.

Raises Invalid_argument on empty

Sourceval tr_pt : box2 -> p2

tr_pt b is the top-right corner of b.

Raises Invalid_argument on empty

Sourceval area : box2 -> float

area b is the surface area of b.

Sourceval inter : box2 -> box2 -> box2

inter b b' is a box whose space is the intersection of S(b) and S(b').

Sourceval union : box2 -> box2 -> box2

union b b' is the smallest box whose space contains S(b) and S(b').

Sourceval inset : v2 -> box2 -> box2

inset d b is b whose edges are inset in each dimension according to amounts in d. Negative values in d outset. If the size in dimension i becomes negative it is clamped to 0 and the ith coordinate of the mid point of b is used for the ith coordinate of the resulting box's origin. Returns empty on empty.

Sourceval round : box2 -> box2

round b is the smallest box containing b with integer valued corners. Returns empty on empty.

Sourceval move : v2 -> box2 -> box2

move d b is b translated by d. Returns empty on empty.

Sourceval ltr : m2 -> box2 -> box2

ltr m b is the smallest box containing the corners of b transformed by m. Returns empty on empty.

Sourceval tr : m3 -> box2 -> box2

tr m b is the smallest box containing the corners of b transformed by m in homogenous 2D space. Returns empty on empty.

Sourceval map_f : (float -> float) -> box2 -> box2

map_f f b is the box whose origin and size are those of b with their components mapped by f. Returns empty on empty.

Predicates and comparisons

Sourceval is_empty : box2 -> bool

is_empty b is true iff b is empty.

Sourceval is_pt : box2 -> bool

is_pt b is true iff b is not empty and its size is equal to 0 in every dimension.

Sourceval is_seg : box2 -> bool

is_seg b is true iff b is not empty and its size is equal to 0 in exactly one dimension.

Sourceval isects : box2 -> box2 -> bool

isects b b' is not (is_empty (inter b b')).

Sourceval subset : box2 -> box2 -> bool

subset b b' is true iff S(b) is included in S(b').

Sourceval mem : p2 -> box2 -> bool

mem p b is true iff p is in S(b).

Sourceval equal : box2 -> box2 -> bool

equal b b' is b = b'.

Sourceval equal_f : (float -> float -> bool) -> box2 -> box2 -> bool

equal_f eq b b' tests b and b' like equal but uses eq to test floating point values.

Sourceval compare : box2 -> box2 -> int

compare u v is Stdlib.compare u v.

Sourceval compare_f : (float -> float -> int) -> box2 -> box2 -> int

compare_f cmp b b' compares b and b' like compare but uses cmp to compare floating point values.

Formatters

Sourceval pp : Format.formatter -> box2 -> unit

pp ppf b prints a textual representation of b on ppf.

Sourceval pp_f : (Format.formatter -> float -> unit) -> Format.formatter -> box2 -> unit

pp_f pp_fl ppf b prints b like pp but uses pp_fl to print floating point values.