package toffee

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Geometry.RectSource

Axis-aligned rectangles representing margins, padding, borders, or insets.

A rectangle is defined by four edges: left, right, top, and bottom. Each edge value can represent coordinates, spacing, or offsets depending on context.

In CSS layout, rectangles primarily represent spacing properties like padding and margin, where each edge specifies the amount of space on that side.

Type

Sourcetype 'a t = {
  1. left : 'a;
  2. right : 'a;
  3. top : 'a;
  4. bottom : 'a;
}

'a t represents a rectangle with four edges.

The type parameter 'a allows rectangles of different value types:

  • float t for concrete measurements
  • Dimension.t t for CSS dimension values
  • Length_percentage.t t for length or percentage values

Constants

Sourceval zero : float t

zero is a rectangle with all edges set to 0.0.

Sourceval all : 'a -> 'a t

all value creates a rectangle with all edges set to value.

Creation

Sourceval make : left:'a -> right:'a -> top:'a -> bottom:'a -> 'a t

make ~left ~right ~top ~bottom creates a rectangle.

Mapping Functions

Sourceval map : ('a -> 'b) -> 'a t -> 'b t

map f rect applies f to each edge of rect.

Sourceval map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t

map2 f r1 r2 applies f to corresponding edges of r1 and r2.

Sourceval zip_size : 'b Size.t -> ('a -> 'b -> 'c) -> 'a t -> 'c t

zip_size size f rect applies f to each edge with its corresponding dimension.

For left and right edges, f receives size.width as the second argument. For top and bottom edges, f receives size.height as the second argument.

Component Extraction

Sourceval horizontal_components : 'a t -> 'a Line.t

horizontal_components rect extracts the left and right edges as a line.

Sourceval vertical_components : 'a t -> 'a Line.t

vertical_components rect extracts the top and bottom edges as a line.

Arithmetic Operations

Sourceval add : float t -> float t -> float t

add a b adds corresponding edges of a and b.

Sourceval (+) : float t -> float t -> float t

a + b is equivalent to add a b.

Axis Sums

Sourceval horizontal_axis_sum : float t -> float

horizontal_axis_sum rect returns rect.left +. rect.right.

This computes total horizontal spacing, not the width of the rectangle.

Sourceval vertical_axis_sum : float t -> float

vertical_axis_sum rect returns rect.top +. rect.bottom.

This computes total vertical spacing, not the height of the rectangle.

Sourceval sum_axes : float t -> float Size.t

sum_axes rect returns both axis sums as a size.

Equivalent to {width = horizontal_axis_sum rect; height = vertical_axis_sum rect}.

Sourceval grid_axis_sum : Absolute_axis.t -> float t -> float

grid_axis_sum axis rect returns the sum along axis.

Returns horizontal_axis_sum rect for Horizontal, vertical_axis_sum rect for Vertical.

Comparison and String Functions

Sourceval compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int

compare cmp a b lexicographically compares a and b using cmp.

Edges are compared in order: left, right, top, bottom.

Sourceval equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool

equal eq a b tests if a and b are equal using eq for each edge.

Sourceval to_string : ('a -> string) -> 'a t -> string

to_string f rect converts rect to a string representation using f for each edge.

Sourceval pp : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit

pp f fmt rect prints rect to fmt using f for each edge.