public double GetRemappedAt(double value, sRange targetRn) { if (value >= targetRn.max) { return(targetRn.max); } if (value <= targetRn.min) { return(targetRn.min); } return(targetRn.min + ((value - this.min) * (targetRn.length) / (this.length))); }
public static sColorGradient GetCyanRedGradient(sRange dataRange, sRange threshold = null) { sColorGradient cg = new sColorGradient(); if (dataRange.length < 0.0) { cg.colors.Add(new sColor(0.0, 0.0, 0.5)); cg.colors.Add(new sColor(0.0, 0.0, 0.5)); cg.colors.Add(new sColor(0.0, 0.0, 0.5)); } else { cg.colors.Add(new sColor(180.0, 0.4, 1.0)); cg.colors.Add(new sColor(0.0, 0.0, 0.5)); cg.colors.Add(new sColor(0.0, 0.6, 1.0)); } if (threshold == null) { cg.parameters.Add(0.0); cg.parameters.Add(0.5); cg.parameters.Add(1.0); } else { double midHi_param = dataRange.GetNormalizedAt(threshold.max); if (midHi_param < 0.505) { midHi_param = 0.505; } double mid3 = 0.5; double midLow_param = (1.0 - midHi_param); cg.parameters.Add(midLow_param); cg.parameters.Add(mid3); cg.parameters.Add(midHi_param); } return(cg); }
public static sColorGradient GetRainbowLikeGradient(sRange dataRange, sRange threshold = null) { sColorGradient cg = new sColorGradient(); if (dataRange.length < 0.0) { cg.colors.Add(new sColor(220.0, 0.55, 1.0)); cg.colors.Add(new sColor(220.0, 0.55, 1.0)); cg.colors.Add(new sColor(220.0, 0.55, 1.0)); cg.colors.Add(new sColor(220.0, 0.55, 1.0)); } else { cg.colors.Add(new sColor(220.0, 0.55, 1.0)); cg.colors.Add(new sColor(185.0, 0.55, 1.0)); cg.colors.Add(new sColor(150.0, 0.55, 1.0)); cg.colors.Add(new sColor(0.0, 0.75, 1.0)); } if (threshold == null) { cg.parameters.Add(0.0); cg.parameters.Add(0.25); cg.parameters.Add(0.75); cg.parameters.Add(1.0); } else { double midHi_param = dataRange.GetNormalizedAt(threshold.max); double midLow_param = (midHi_param / 3.0); double midMid_param = ((2 * midHi_param) / 3.0); cg.parameters.Add(0.0); cg.parameters.Add(midLow_param); cg.parameters.Add(midMid_param); cg.parameters.Add(midHi_param); } return(cg); }
public static double GetEnsureValue(double valThis, sRange range = null) { if (range != null) { if (valThis <= range.min) { return(range.min); } else if (valThis >= range.max) { return(range.max); } else { return(valThis); } } else { return(valThis); } }
public double GetOriginBasedNormalizedAt(double value) { if (this.min < 0.0 && this.max < 0.0) { sRange newRn = new sRange(this.min, Math.Abs(this.min)); return(newRn.GetNormalizedAt(value)); } else if (this.min < 0.0 && this.max > 0.0) { double absMax = Math.Max(Math.Abs(this.min), Math.Abs(this.max)); sRange newRn = new sRange(-absMax, absMax); return(newRn.GetNormalizedAt(value)); } else if (this.min > 0.0 && this.max > 0.0) { sRange newRn = new sRange(-1 * Math.Abs(this.max), this.max); return(newRn.GetNormalizedAt(value)); } else { return(this.GetNormalizedAt(value)); } }
public sRange DuplicatesRange() { sRange nr = new sRange(this.min, this.max); return(nr); }