modellking / DMX-UI

1 stars 0 forks source link

Color.Pp LerpLooping ignores farFlag if Both Colors Hues are below or above 180 #44

Closed modellking closed 5 years ago

modellking commented 5 years ago

Describe the bug Color.Pp LerpLooping ignores farFlag if Both Colors Hues are below or above 180

To Reproduce Steps to reproduce the behavior:

  1. Test Code in AppTests

Expected behavior enabling FarFlag always proposes a different huesequence then disabling it

Screenshots none

Plattform: All

Additional context Add any other context about the problem here.

modellking commented 5 years ago

Test and Dev Code Module

using System;

public struct HsvColor { public double H; public double S; public double V;}
public class Program
{
    public static HsvColor LerpLooping(HsvColor a, HsvColor b, float f, bool hueFarFlag = false)
        {
            var ah = a.H;
            var bh = b.H;

            if (Math.Abs(ah - bh) > 180.0 ^ hueFarFlag)
            {
                if (ah < bh)
                    ah += 360;
                else
                    bh += 360;
            }

            return new HsvColor
            {
                H = (f * bh + (1 - f) * ah) % 360,
                S = f * b.S + (1 - f) * a.S,
                V = f * b.V + (1 - f) * a.V
            };
        }
    public static void Main() {
        var a = new HsvColor();
        a.H = 0.0;
        a.S = 0.0;
        a.V = 0.0;

        var b = new HsvColor();
        b.H = 110.0;
        b.S = 0.0;
        b.V = 0.0;

        for (float i = 0f; i < 1.01f; i+=0.1f) {
            Console.Write("{0:F}", LerpLooping(a,b,i,false).H);
            Console.Write("\t");
            Console.WriteLine("{0:F}", LerpLooping(a,b,i,true).H);
        }
    }
}

Solved with next commit