package toffee
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/toffee.geometry/Geometry/Size/index.html
Module Geometry.SizeSource
2-dimensional size representation.
A generic container representing width and height extents. The type is polymorphic over the contained value type, enabling concrete sizes (float t), optional sizes (float option t), and dimension-typed sizes.
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
Arithmetic Operations
sub a b subtracts corresponding dimensions of b from a.
mul_scalar size scalar multiplies both width and height by scalar.
div_scalar size scalar divides both width and height by scalar.
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.
Float-Specific Operations
max a b computes the component-wise maximum of a and b.
min a b computes the component-wise minimum of a and b.
has_non_zero_area size returns true if both width and height are strictly greater than 0.0.
equal a b tests structural equality of a and b using float equality.
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.
equal_option eq a b tests equality of optional sizes using eq for the contained values.
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
Concrete + Option → Option Operations
min_with_option concrete optional computes the minimum of a concrete size with an optional size.
For each dimension, returns Some (min concrete opt) when optional is Some opt, otherwise Some concrete.
max_with_option concrete optional computes the maximum of a concrete size with an optional size.
For each dimension, returns Some (max concrete opt) when optional is Some opt, otherwise Some concrete.
add_with_option concrete optional adds a concrete size to an optional size.
For each dimension, returns Some (concrete + opt) when optional is Some opt, otherwise Some concrete.
sub_with_option concrete optional subtracts an optional size from a concrete size.
For each dimension, returns Some (concrete - opt) when optional is Some opt, otherwise Some concrete.
Concrete Operations with Optional Parameters
clamp min max size clamps size between optional bounds, returning a concrete size.
For each dimension:
- When both bounds are
Some, returnsmin max_val (max min_val size) - When only max is
Some, returnsmin max_val size - When only min is
Some, returnsmax min_val size - When both are
None, returnssizeunchanged
min_or_self optional size computes the minimum with an optional size, falling back to size.
For each dimension, returns min size val_ when optional is Some val_, otherwise size.
max_or_self optional size computes the maximum with an optional size, falling back to size.
For each dimension, returns max size val_ when optional is Some val_, otherwise size.
add_or_zero optional size adds an optional size to a concrete size, treating None as zero.
For each dimension, returns size + val_ when optional is Some val_, otherwise size.
sub_or_zero optional size subtracts an optional size from a concrete size, treating None as zero.
For each dimension, returns size - val_ when optional is Some val_, otherwise size.
max_concrete a b computes the component-wise maximum using Float.max.
Option + Concrete → Option Operations
maybe_add concrete opt_size adds a concrete size to an optional size.
For each dimension, maps Some v to Some (v + concrete), and None to None.
maybe_sub concrete opt_size subtracts a concrete size from an optional size.
For each dimension, maps Some v to Some (v - concrete), and None to None.
maybe_min concrete opt_size computes the minimum of an optional size with a concrete size.
For each dimension, maps Some v to Some (min v concrete), and None to None.