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 |
#1200 in Math
98 downloads per month
Used in 5 crates
(2 directly)
96KB
3K
SLoC
figures
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
~135–365KB