Crate figures

Source
Expand description

§Figures

figures is considered alpha and unsupported crate version Documentation for main branch

A primarily integer-based 2d graphics math library.

§Inspiration

Sharp graphics are achieved by ensuring that drawing is aligned to pixel boundaries. If a 1px-square dot is drawn at 0.99 pixels offset, the dot may look fuzzy because its color will be shared across multiple pixels. While this can give the illusion of subpixel imaging, it can also be undesired on high-dpi displays.

This library embraces integer types for its data representation to allow for predictable math to be performed without loss of precision. It supports subdividing physical pixels into 4 subpixels, allowing for subpixel layout while providing consistent results.

§Pixels (Px) and Device-Independent Pixels (Lp)

In this crate, a pixel (Px) is a single colorable location on a screen. A display’s resolution, such as 1920x1080, is its measurement in pixels. A pixel can vary in size greatly – a modern smartphone’s display is often over 300 pixels per inch while a 23-inch 1080p monitor contains roughly 96 pixels-per-inch (ppi).

As an alternative to pixels, this crate also provides its own measurement unit: device-independent pixels (Lp). This type offers many constructors using real-world measurements that developers and designers are familiar with, and handles converting to the display’s scale for the developer.

§Project Status

This project is early in development as part of Kludgine and Gooey. It is considered alpha and unsupported at this time, and the primary focus for @ecton is to use this for his own projects. Feature requests and bug fixes will be prioritized based on @ecton’s own needs.

If you would like to contribute, bug fixes are always appreciated. Before working on a new feature, please open an issue proposing the feature and problem it aims to solve. Doing so will help prevent friction in merging pull requests, as it ensures changes fit the vision the maintainers have for Gooey.

Modules§

units
The measurement units supported by figures.

Macros§

fraction
Returns a new fraction.

Structs§

Angle
An measurement of distance between two rays sharing a common endpoint, in degrees.
Fraction
A fraction type for predictable integer-based math.
Point
A coordinate in a 2d space.
Rect
A 2d area expressed as an origin (Point) and a Size.
Size
A width and a height measurement.

Enums§

FloatOrInt
A type representing either an i32 or an f32.

Traits§

Abs
A type that can have its absolute difference from zero calculated.
FloatConversion
Converts a type to its floating point representation.
FromComponents
Converts from a 2d vector in tuple form
IntoComponents
Converts to a 2d vector in tuple form
IntoSigned
Converts a value into its signed representation, clamping negative numbers to i32::MAX.
IntoUnsigned
Converts a value into its signed representation, clamping negative numbers to 0.
Lp2D
Constructors for types that are composed of two Lp components.
PixelScaling
A type that has a scaling factor when converting to pixels.
Pow
Raises a value to an exponent.
Px2D
Constructors for types that are composed of two Px components.
Ranged
A type that has a minimum and a maximum.
Roots
Functionality for getting the root of a number.
Round
Functionality for rounding values to whole numbers.
ScreenScale
Converts this type into its measurement in Px and Lp.
ScreenUnit
A type that can be used as a Unit in figures that knows how to convert to Lp or Px.
StdNumOps
Common number operations available on number types in Rust that aren’t available as traits.
UPx2D
Constructors for types that are composed of two UPx components.
Unit
A type that can be used as a Unit in figures.
UnscaledUnit
Information about scaling for a numerical unit type.
Zero
A type that can represent a zero-value.