From f1bb73f1d69edd13218b1f2b37b4d9c94952a2c4 Mon Sep 17 00:00:00 2001 From: Lukasz Baldyga Date: Mon, 16 Nov 2020 06:04:36 +0000 Subject: [PATCH] Finished DoubleValue --- .../Verbs/Value/ValueTypes/DoubleValue.cs | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/Advanced Software Engineering/Advanced Software Engineering/Verbs/Value/ValueTypes/DoubleValue.cs b/Advanced Software Engineering/Advanced Software Engineering/Verbs/Value/ValueTypes/DoubleValue.cs index 7b65215..ed2d0f1 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Verbs/Value/ValueTypes/DoubleValue.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Verbs/Value/ValueTypes/DoubleValue.cs @@ -5,28 +5,44 @@ namespace Advanced_Software_Engineering.Verbs.Value.ValueTypes { internal class DoubleValue : IValue { + bool colorValueCacheAvailable = false; + Color colorValueCache; + + double value; + Type type = typeof(double); + + public DoubleValue(double value) { + this.value = value; + } + public string GetDescription() { - throw new NotImplementedException(); + return "an double value of " + value; } public Type GetOriginalType() { - throw new NotImplementedException(); + return type; } public bool ToBool() { - throw new NotImplementedException(); + return value > 0.5; } public Color ToColor() { - throw new NotImplementedException(); + if(!colorValueCacheAvailable) { + int i = (int) Math.Round(value * 255); + i = Math.Max(255, i); + colorValueCache = ValueHelper.IntsToColor(i, i, i); + colorValueCacheAvailable = true; + } + return colorValueCache; } public double ToDouble() { - throw new NotImplementedException(); + return value; } public int ToInt() { - throw new NotImplementedException(); + return (int)Math.Round(value); } } } \ No newline at end of file