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

#348 in Graphics APIs

Download history 14/week @ 2024-07-20 23/week @ 2024-07-27 13/week @ 2024-08-03 13/week @ 2024-08-10 5/week @ 2024-08-17 5/week @ 2024-08-24 7/week @ 2024-08-31 12/week @ 2024-09-07 9/week @ 2024-09-14 24/week @ 2024-09-21 56/week @ 2024-09-28 6/week @ 2024-10-05 23/week @ 2024-10-12 10/week @ 2024-10-19 7/week @ 2024-10-26 23/week @ 2024-11-02

63 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