package stk

  1. Overview
  2. Docs

Geometry.

This module is used to represent and compute widget coordinates.

type t = {
  1. x : int;
  2. y : int;
  3. w : int;
    (*

    width

    *)
  4. h : int;
    (*

    height

    *)
}

A geometry is rectangle. x and y are coordinates of top-left corner.

val to_string : t -> string
val pp : Stdlib.Format.formatter -> t -> unit
val create : x:int -> y:int -> w:int -> h:int -> t

Convenient function to create a t.

val seg_inter : int -> int -> int -> int -> (int * int) option

seg_inter x1 w1 x2 w2 returns the intersection segment (left..right) between segments (x1..(x1+w1)) and (x2..(x2+w2)), if any.

val inter : t -> t -> t option

Intersection between two rectangles, if any.

val union : t -> t -> t

Union of two rectangles, i.e. returns the rectangle containing both.

val zero : t

Zero geometry, all fields set to 0.

val is_zero : t -> bool
val inside : x:int -> y:int -> t -> bool

inside ~x ~y g returns true is point (x, y) is inside g.

val translate : ?x:int -> ?y:int -> t -> t

translate ~x ~y g returns a new geometry, adding x (resp. y) to g.x (resp. g.y) if specified.

val enlarge : ?w:int -> ?h:int -> t -> t

enlarge ~w ~h g returns a new geometry whose width (resp. height) is increased by 2 * w (resp. 2 * h). g.x (resp. g.y) is translated by -w (resp. -h) so that the final geometry remains centered with report to the original one.

val to_rect : t -> Tsdl.Sdl.rect

to_rect g creates a Tsdl.Sdl.rect from g.

val of_rect : Tsdl.Sdl.rect -> t

of_rect r creates a geometry t from a Tsdl.Sdl.rect.

val has_intersect : t -> t -> bool

has_intersect g1 g2 returns true if intersection g1 g2 <> None.

val remove_border : t -> int Props.trbl -> t

remove_border g borders returns a new geometry by removing borders from g. It is ensured that the returned geometry has non-negative width and height.

OCaml

Innovation. Community. Security.