#2d #math #graphics

figures

A math library specialized for 2d screen graphics

4 releases

0.1.2 Sep 2, 2021
0.1.1 Aug 29, 2021
0.1.0 Aug 22, 2021
0.0.0-reserve.0 Aug 10, 2021

#142 in Math

Download history 23/week @ 2021-08-08 16/week @ 2021-08-15 114/week @ 2021-08-22 151/week @ 2021-08-29 6/week @ 2021-09-05 3/week @ 2021-09-12 8/week @ 2021-09-19 4/week @ 2021-09-26 22/week @ 2021-10-03 41/week @ 2021-10-10 3/week @ 2021-10-17 4/week @ 2021-10-24 15/week @ 2021-10-31 6/week @ 2021-11-07 6/week @ 2021-11-14 3/week @ 2021-11-21

82 downloads per month
Used in 4 crates (2 directly)

MIT/Apache

96KB
3K SLoC

figures

crate version Live Build Status HTML Coverage Report for main branch Documentation for main branch

A minimalist crate for 2d math focused on what is needed to build user interfaces. Written for Gooey and Kludgine.

figures utilizes the Rust type system to prevent performing math on numbers with different units. The core types in figures all accept arbitrary unit types, allowing you to safely manage numbers in a wide variety of use cases while allowing the Rust compiler to help you prevent easy mistakes.

While the core types support any arbitrary units, figures defines three built in units:

  • Pixels: Represents physical pixels on a display.
  • Points: Represents a DPI-scaled resolution, as configured in the operating system.
  • Scaled: Represents an arbitrarily scaled resolution, enabling applications to add a "user interface scale" option to their applications easily.

To ease converting between these three units, the Displayable trait is implemented by all measurement types in this library.

Inspiration

This library is born of a difference of opinions from the excellent library euclid. Ultimately, I disagree on some fundamental design decisions. One of the most prevalent is that in euclid you are prevented from adding a Point and a Size together. In figures, you are able to interoperate with more types freely.

The second major change from euclid is embracing the Length/[Figure] type throughout the types. APIs will often favor returning a Figure instead of the raw type.

This library is hyper-focused on being a minimalistic math library for Gooey and Kludgine. euclid has more functionality. While we may accept PRs for some additional functionality, if you're looking for a more complete library, euclid should be your choice.

About

This is being developed by and for Khonsu Labs for Cosmic Verge. I hope it will be useful to others as well.

This code is dual-licensed under the MIT License and Apache License 2.0. Fonts in this repository are not included by default, and are solely licensed under the Apache License 2.0.

Dependencies

~125–375KB

x0a