Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
205: Generalizing gradients and add constant gradients r=Ogeon a=NicolasKlenert This pull request contains two commits: ### 1. Generalization of `Gradient` This allows creation of gradients from arrays. The inner collection type only has to be `ArrayLike`. For backward compatibility the default is still vector. This allows constant gradients and should also allow gradients to be supported for the next `#[no-std]` build. Other options to enable `#[no-std]` for gradients were briefly disscused in #156. ### 2. Adding some constant gradients This commit adds constant gradients. To be precise, it adds all 4 new matplotlib color gradients, which are perfectly perceptually-uniform, both in regular form and also when converted to black-and-white and therefore one of the most useful gradients. These are build the same way the named colors are built. A new feature-flag `named_gradients` is added to toggle said constants. This closes #62. ### Alterantives - The generalization of gradients can be achieved in a multiple of ways. Using a trait is just one of them and may be the wrong way to go. - However I think because this pull request doesn't have any breaking changes and gradients should be supporting arrays in future versions of the crate, it doesn't seem like this update of `Gradient` will cause more breaking API changes in the future than otherwise. Also constant gradients may be the only interaction with gradients a user needs, such that introducing them could reduce the number of users which actually relies on the generation of `Gradient` itself. - At the moment the 4 constant gradients are using linear interpolation but in nature these gradients are Spline-Interpolations of exaclty two points (and 2 controlpoints). If `Gradient` will support Spline-Inerpolation in the future and the exact controlpoints of these gradients can be found (I only found the colormaps), the gradients could be implemented more memory efficient. ### Remark These commits depend on const generics, which is a feature in beta but is planned to be stable on 2021-03-25 onwords (see [#79135](rust-lang/rust#79135)). Co-authored-by: Nicolas Klenert <klenert.nicolas@gmail.com> Co-authored-by: NicolasKlenert <Nicolas_Klenert@web.de> Co-authored-by: NicolasKlenert <klenert.nicolas@gmail.com>
- Loading branch information