package toffee
Build not yet checkedInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=a92cbbcbe016fb19fb0a749222da0e459a9567aef3f4c7340d9bd6b71c53ed6f
sha512=6a7ab054605538bb31a2b73a1a6d093981a2704c9f0af5852221c05735290d74aca7c7282298c4d0f91e86a800e2ccd94b4918af883cd963449c758eb6b272b3
doc/toffee.geometry/Toffee_geometry/Size/index.html
Module Toffee_geometry.SizeSource
2-dimensional size representation.
A generic container representing width and height extents. The type is polymorphic over the contained value type, enabling optional sizes (float option t) and dimension-typed sizes. Concrete sizes of floats are Sizef.t, which store their floats flat.
All operations preserve type safety and handle axis-specific transformations through abstract and absolute axis types.
'a t represents a 2-dimensional size with width and height of type 'a.
Constants
Creation
Mapping Functions
map f size applies f to both width and height, transforming 'a t into 'b t.
map_width f size applies f to the width while preserving the height.
map_height f size applies f to the height while preserving the width.
zip_map other f size applies f pairwise to corresponding dimensions of size and other.
Axis Accessors
get axis size retrieves the dimension corresponding to axis.
Returns width for Abstract_axis.Inline and height for Abstract_axis.Block.
set axis value size returns a new size with the dimension corresponding to axis set to value.
Sets width for Abstract_axis.Inline and height for Abstract_axis.Block.
get_absolute axis size retrieves the dimension corresponding to axis.
Returns width for Absolute_axis.Horizontal and height for Absolute_axis.Vertical.
Option-Specific Operations
unwrap_or alt size unwraps each dimension of size, using the corresponding dimension from alt when None.
choose_first size alt selects dimensions from size when Some, falling back to alt when None.
both_axis_defined size returns true if both width and height are Some.
apply_aspect_ratio aspect_ratio size applies aspect_ratio to compute the missing dimension.
If aspect_ratio is Some ratio:
- When width is
Somebut height isNone, computes height aswidth / ratio - When height is
Somebut width isNone, computes width asheight * ratio - Otherwise returns
sizeunchanged
If aspect_ratio is None, returns size unchanged.
Comparison and Formatting
compare cmp a b performs lexicographic comparison using cmp, comparing width first, then height.
equal_with eq a b tests equality using eq for both width and height.
to_string f size converts size to a string representation using f for each dimension.
pp f fmt size formats size using fmt and f for each dimension.
Option Operations
These operations implement Taffy's MaybeMath patterns for working with optional values. They follow specific semantics where None represents the absence of a constraint.
Option → Option Operations
min_option a b computes the component-wise minimum of optional sizes.
For each dimension:
Some l, Some rproducesSome (min l r)Some _, Noneproduces the left valueNone, _producesNone
max_option a b computes the component-wise maximum of optional sizes.
For each dimension:
Some l, Some rproducesSome (max l r)Some _, Noneproduces the left valueNone, _producesNone
add_option a b adds optional sizes component-wise.
For each dimension:
Some l, Some rproducesSome (l + r)Some _, Noneproduces the left valueNone, Some _producesNone
sub_option a b subtracts optional sizes component-wise.
For each dimension:
Some l, Some rproducesSome (l - r)Some _, Noneproduces the left valueNone, _producesNone
clamp_option min max size clamps each dimension of size between optional bounds.
For each dimension, returns:
Some (clamp base min_val max_val)when all three areSomeSome (clamp base _ max_val)when only max isSomeSome (clamp base min_val _)when only min isSome- The original value when both bounds are
None NonewhensizeisNone