6 releases (3 breaking)

0.3.1 Apr 11, 2023
0.3.0 Apr 9, 2023
0.2.0 Mar 6, 2023
0.1.0 Mar 6, 2023
0.0.2 Jun 27, 2022

#371 in GUI

Download history 2/week @ 2023-12-25 7/week @ 2024-02-12 27/week @ 2024-02-19 23/week @ 2024-02-26 14/week @ 2024-03-04 15/week @ 2024-03-11 16/week @ 2024-03-18 8/week @ 2024-03-25 110/week @ 2024-04-01

152 downloads per month
Used in 5 crates (2 directly)

MIT/Apache

64KB
1.5K SLoC

cuadra

Crate API Lines Of Code

Layouts.

See the documentation for more information.

Status

This is currently in an experimental stage of development.

Contributing

Contributions are welcomed to help refine and improve this library over time. If you notice a bug, have an idea for a new feature, or simply want to suggest improvements to the existing codebase, please get in touch.


lib.rs:

Layout

Several primitives are defined for Position, Size and their combination as a Zone.

Types have 8, 16, 32 and 64 bit sizes implementations, and they are limited to values of just half the range of an equivalent bit-size signed integer, leaving 1/4th of the range for positive values.

Positions can have negative values, while Sizes can only be positive.

For example, a Position8 can hold values between -64,-64 and 63,63, while a Size16 can have values of between 1,1 and 16_383,16_383.

The non-negative range from 0 to the clamped maximum is always 1/4th of the primitive's maximum. This allows to have a safety margin around which allows to move the biggest size to the furthest position, and still be able to represent all its points with the same inner bit-size.

The following diagram shows the example range of values of a Position8, around the inner centered square, with the outer safety margin around it, and the maximum positive clamped size filled with +.

      -128,127       0,127     127,127
          .-----|-----|-----|-----·
          |                       |
          |  -64,63       63,63   |
          |     .-----------.     --
          |     |     |+++++|     |
          |     |     |+++++|     |
  -128,0 --     |----0,0----|     -- 127,0
          |     |     |     |     |
          |     |     |     |     |
          |     .-----------.     --
          |  -64,-64      63,-64  |
          |                       |
          .-----|-----|-----|-----.
      -128,-128      0,-128    127,-128

Dependencies