using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RealTimeGraphX.DataPoints
{
///
/// Represents a graph value data point.
///
///
public class DoubleDataPoint : GraphDataTypeBase
{
///
/// Initializes a new instance of the class.
///
public DoubleDataPoint() : base()
{
}
///
/// Initializes a new instance of the class.
///
/// The value.
public DoubleDataPoint(double value) : base(value)
{
}
///
/// Performs an implicit conversion from to .
///
/// The value.
///
/// The result of the conversion.
///
public static implicit operator DoubleDataPoint(double value)
{
return new DoubleDataPoint(value);
}
///
/// Implements the operator -.
///
/// a.
/// The b.
///
/// The result of the operator.
///
public static DoubleDataPoint operator -(DoubleDataPoint a, DoubleDataPoint b)
{
return new DoubleDataPoint(a.Value - b.Value);
}
///
/// Implements the operator +.
///
/// a.
/// The b.
///
/// The result of the operator.
///
public static DoubleDataPoint operator +(DoubleDataPoint a, DoubleDataPoint b)
{
return new DoubleDataPoint(a.Value + b.Value);
}
///
/// Sums the value of this instance with another instance value and returns the result.
///
/// The other instance.
///
public override IGraphDataPoint Add(IGraphDataPoint other)
{
return new DoubleDataPoint(this.Value + (other as DoubleDataPoint).Value);
}
///
/// Subtract the value of another instance from this instance and returns the result.
///
/// The other instance.
///
public override IGraphDataPoint Subtract(IGraphDataPoint other)
{
return new DoubleDataPoint(this.Value - (other as DoubleDataPoint).Value);
}
///
/// Multiplies the value of this instance with another instance value and returns the result.
///
/// The other instance.
///
public override IGraphDataPoint Multiply(IGraphDataPoint other)
{
return new DoubleDataPoint(this.Value * (other as DoubleDataPoint).Value);
}
///
/// Divides the value of this instance with another instance value and returns the result.
///
/// The other instance.
///
public override IGraphDataPoint Divide(IGraphDataPoint other)
{
return new DoubleDataPoint(this.Value / (other as DoubleDataPoint).Value);
}
///
/// Returns the percentage value of this instance between the specified minimum and maximum values.
///
/// The minimum.
/// The maximum.
///
public override double ComputeRelativePosition(IGraphDataPoint min, IGraphDataPoint max)
{
DoubleDataPoint dMin = min as DoubleDataPoint;
DoubleDataPoint dMax = max as DoubleDataPoint;
var result = ((Value - dMin) * 100) / (dMax - dMin);
return double.IsNaN(result) ? dMin.Value : result;
}
///
/// Returns the absolute value of the specified percentage value between the specified minimum and maximum values.
///
/// The minimum.
/// The maximum.
/// The percentage.
///
public override IGraphDataPoint ComputeAbsolutePosition(IGraphDataPoint min, IGraphDataPoint max, double percentage)
{
double minimum = (double)min.GetValue();
double maximum = (double)max.GetValue();
return new DoubleDataPoint(minimum + (maximum - minimum) * percentage);
}
///
/// Creates a range of values from the specified minimum and maximum.
///
/// The minimum.
/// The maximum.
/// The count.
///
public override IEnumerable CreateRange(IGraphDataPoint min, IGraphDataPoint max, int count)
{
double minimum = (double)min.GetValue();
double maximum = (double)max.GetValue();
return Enumerable.Range(0, count).
Select(i => minimum + (maximum - minimum) * ((double)i / (count - 1))).
Select(x => new DoubleDataPoint(x));
}
///
/// Returns a formated string of this data point.
///
/// The format.
///
public override string ToString(string format)
{
return Value.ToString(format);
}
}
}