package toffee
Module Toffee_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
'a t represents a rectangle with four edges.
The type parameter 'a allows rectangles of different value types:
float option tfor optional measurementsDimension.t tfor CSS dimension valuesLength_percentage.t tfor length or percentage values
Concrete rectangles of floats are Rectf.t, which store their floats flat.
Constants
Creation
make ~left ~right ~top ~bottom creates a rectangle.
Mapping Functions
map2 f r1 r2 applies f to corresponding edges of r1 and r2.
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
horizontal_components rect extracts the left and right edges as a line.
vertical_components rect extracts the top and bottom edges as a line.
Comparison and String Functions
compare cmp a b lexicographically compares a and b using cmp.
Edges are compared in order: left, right, top, bottom.
equal eq a b tests if a and b are equal using eq for each edge.
to_string f rect converts rect to a string representation using f for each edge.
pp f fmt rect prints rect to fmt using f for each edge.