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 Int32DataPoint : GraphDataPoint
{
///
/// Initializes a new instance of the class.
///
public Int32DataPoint() : base()
{
}
///
/// Initializes a new instance of the class.
///
/// The value.
public Int32DataPoint(int value) : base(value)
{
}
///
/// Performs an implicit conversion from to .
///
/// The value.
///
/// The result of the conversion.
///
public static implicit operator Int32DataPoint(int value)
{
return new Int32DataPoint(value);
}
///
/// Implements the operator -.
///
/// a.
/// The b.
///
/// The result of the operator.
///
public static Int32DataPoint operator -(Int32DataPoint a, Int32DataPoint b)
{
return new Int32DataPoint(a.Value - b.Value);
}
///
/// Implements the operator +.
///
/// a.
/// The b.
///
/// The result of the operator.
///
public static Int32DataPoint operator +(Int32DataPoint a, Int32DataPoint b)
{
return new Int32DataPoint(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 Int32DataPoint(this.Value + (other as Int32DataPoint).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 Int32DataPoint(this.Value - (other as Int32DataPoint).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 Int32DataPoint(this.Value * (other as Int32DataPoint).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 Int32DataPoint(this.Value / (other as Int32DataPoint).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)
{
Int32DataPoint dMin = min as Int32DataPoint;
Int32DataPoint dMax = max as Int32DataPoint;
if (dMax - dMin == 0) //Prevent divide by zero
{
return dMin;
}
var result = ((Value - dMin) * 100) / (dMax - dMin);
return 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)
{
int minimum = (int)min.GetValue();
int maximum = (int)max.GetValue();
return new Int32DataPoint((int)(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 = (int)min.GetValue();
double maximum = (int)max.GetValue();
return Enumerable.Range(0, count).
Select(i => minimum + (maximum - minimum) * ((double)i / (count - 1))).
Select(x => new Int32DataPoint((int)x));
}
///
/// Returns a formated string of this data point.
///
/// The format.
///
public override string ToString(string format)
{
return Value.ToString(format);
}
///
/// Parses the specified value and returns a new instance of data point.
///
/// The value.
///
public override IGraphDataPoint Parse(string value)
{
return new Int32DataPoint(int.Parse(value));
}
}
}