HanSolo / medusa

A JavaFX library for Gauges
Apache License 2.0
687 stars 129 forks source link

Smooth gradient precisely on gradient stop #209

Closed jab27 closed 3 years ago

jab27 commented 3 years ago

The lookup of lower and upper bound precisely at a gradient stop will pick the neighbors on both sides instead of just going with the actual one. This results in interpolated color that could be quite fare off. Example with stops defines for 0.2, 0.4, 0.6, 0.8 and 1.0 The position is 0.4 and the lower and upper bound is set to 0.2 and 0.6 in stead of just picking 0.4 for one or both. I believe the fix would be to include an equal in one or both of the compare's of method getCoulorAt(…) in tools.

public Color getColorAt(final double POSITION_OF_COLOR) { … if (Double.compare(fraction,POSITION) < 0) { lowerBound = stops.get(fraction); } if (Double.compare(fraction, POSITION) > 0) { upperBound = stops.get(fraction); break; } …

image

HanSolo commented 3 years ago

Thx for the heads up, will take a look at asap 👍🏻

HanSolo commented 3 years ago

Should be fixed with latest commit in jdk16 branch, could you give it a try please?

jab27 commented 3 years ago

It's working. Thanks!