thesadrogue / TheSadRogue.Primitives

A collection of primitive data structures for working with a 2-dimensional grid.
MIT License
21 stars 6 forks source link

Make Gradient.Lerp and Gradient.ToColorArray More Precise #99

Open Chris3606 opened 1 year ago

Chris3606 commented 1 year ago

The current implementation appears to be more or less correct, but is rather awkwardly imprecise when it comes to lerp'ed values. See this unit test and the associated one for lerp (called LerpBasic); in even this simple test cases, lerp'ed values are off by 5 (eg 5/55 = ~2%) from what they should be.

It is likely some imprecision is unavoidable, particularly with floats; but it seems at least reasonable to expect more precision than this.