aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/SideChains/RealTimeGraphEx/Models/RealTimeGraphExPolygon.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/SideChains/RealTimeGraphEx/Models/RealTimeGraphExPolygon.cs')
-rw-r--r--Software/Visual_Studio/SideChains/RealTimeGraphEx/Models/RealTimeGraphExPolygon.cs383
1 files changed, 383 insertions, 0 deletions
diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphEx/Models/RealTimeGraphExPolygon.cs b/Software/Visual_Studio/SideChains/RealTimeGraphEx/Models/RealTimeGraphExPolygon.cs
new file mode 100644
index 000000000..815647222
--- /dev/null
+++ b/Software/Visual_Studio/SideChains/RealTimeGraphEx/Models/RealTimeGraphExPolygon.cs
@@ -0,0 +1,383 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace RealTimeGraphEx.Models
+{
+ public class RealTimeGraphExPolygon
+ {
+ public List<RealTimeGraphExPoint> Points { get; set; }
+ public List<double> ActualValues { get; set; }
+
+ public int TotalPoints
+ {
+ get { return Points.Count; }
+ }
+
+ public RealTimeGraphExPolygon()
+ {
+ Points = new List<RealTimeGraphExPoint>();
+ ActualValues = new List<double>();
+ }
+
+ public RealTimeGraphExPoint Add(double xValue, double yValue, double actualValue)
+ {
+ var p = new RealTimeGraphExPoint() { XValue = xValue, YValue = yValue };
+ Points.Add(p);
+ ActualValues.Add(actualValue);
+ return p;
+ }
+
+ public RealTimeGraphExPoint Replace(double xValue, double yValue, double actualValue, int index)
+ {
+ var p = new RealTimeGraphExPoint() { XValue = xValue, YValue = yValue };
+ if (index < Points.Count)
+ {
+ Points.RemoveAt(index);
+ Points.Insert(index, p);
+ ActualValues.RemoveAt(index);
+ ActualValues.Insert(index, actualValue);
+ }
+ return p;
+ }
+
+ public void RemoveFromStart(int count)
+ {
+ if (count < 1) return;
+
+ lock (Points)
+ {
+ if (Points.Count < count) return;
+
+ Points.RemoveRange(0, count);
+ ActualValues.RemoveRange(0, count);
+
+ double offSet = Points[0].XValue;
+
+ for (int i = 0; i < Points.Count; i++)
+ {
+ Points[i].XValue = Points[i].XValue - offSet;
+ }
+ }
+ }
+
+ public void ClearPoints()
+ {
+ Points.Clear();
+ }
+
+ public void ClearActualPoints()
+ {
+ ActualValues.Clear();
+ }
+
+ public int[] ToPolygonPoints()
+ {
+ lock (Points)
+ {
+ List<int> points = new List<int>();
+
+ for (int i = 0; i < Points.Count; i++)
+ {
+ points.Add((int)Points[i].XValue);
+ points.Add((int)Points[i].YValue);
+ }
+
+ return points.ToArray();
+ }
+ }
+
+ public int[] ToPolygonPoints(double scaleFactor, Func<double, double> scaleY)
+ {
+ double xValue = 0;
+
+ lock (Points)
+ {
+ List<int> points = new List<int>();
+
+ for (int i = 0; i < Points.Count; i++)
+ {
+ points.Add((int)xValue);
+ points.Add((int)scaleY(Points[i].YValue));
+ xValue += scaleFactor;
+ }
+
+ return points.ToArray();
+ }
+ }
+
+ public int[] ToPolygonPoints(double offsetX, double offsetY, double scaleFactor, Func<double, double> scaleY)
+ {
+ double xValue = 0;
+
+ lock (Points)
+ {
+ List<int> points = new List<int>();
+
+ for (int i = 0; i < Points.Count; i++)
+ {
+ points.Add((int)(xValue + offsetX));
+ points.Add((int)(scaleY(Points[i].YValue) + offsetY));
+ xValue += scaleFactor;
+ }
+
+ return points.ToArray();
+ }
+ }
+
+ public int[] ToPolygonPointsFill(double offsetX, double offsetY, double width, double height, double scaleFactor, Func<double, double> scaleY)
+ {
+ double xValue = 0;
+
+ lock (Points)
+ {
+ List<int> points = new List<int>();
+
+ for (int i = 0; i < Points.Count; i++)
+ {
+ points.Add((int)(xValue + offsetX));
+ points.Add((int)(scaleY(Points[i].YValue) + offsetY));
+
+ xValue += scaleFactor;
+ }
+
+ points.Add((int)((xValue - scaleFactor) + offsetX));
+ points.Add((int)height);
+ points.Add(0);
+ points.Add((int)height);
+ points.Add(0);
+ points.Add(points[1]);
+
+ return points.ToArray();
+ }
+ }
+
+ public int[] ToPolygonPointsReflection(double offsetX, double offsetY, double height, double scaleFactor, Func<double, double> scaleY)
+ {
+ double xValue = 0;
+
+ lock (Points)
+ {
+ List<int> points = new List<int>();
+
+ for (int i = 0; i < Points.Count; i++)
+ {
+ points.Add((int)(xValue + offsetX));
+ points.Add((int)((height - scaleY(Points[i].YValue)) + offsetY));
+
+ xValue += scaleFactor;
+ }
+
+ return points.ToArray();
+ }
+ }
+
+ public int[] ToPolygonPointsWaveFill(double offsetX, double offsetY, double width, double height, double scaleFactor, Func<double, double> scaleY)
+ {
+ double xValue = 0;
+
+ lock (Points)
+ {
+ List<int> points = new List<int>();
+
+ for (int i = 0; i < Points.Count; i++)
+ {
+ points.Add((int)(xValue + offsetX));
+ points.Add((int)((scaleY(Points[i].YValue)) + offsetY));
+
+ xValue += scaleFactor;
+ }
+
+ points.Add((int)width);
+ points.Add((int)(height / 2));
+
+ points.Add((int)width);
+ points.Add((int)((height - scaleY(Points[Points.Count - 1].YValue)) + offsetY));
+
+ xValue -= scaleFactor;
+
+ for (int i = Points.Count - 1; i >= 0; i--)
+ {
+ points.Add((int)(xValue + offsetX));
+ points.Add((int)((height - scaleY(Points[i].YValue)) + offsetY));
+
+ xValue -= scaleFactor;
+ }
+
+ points.Add(0);
+ points.Add(points[points.Count - 2]);
+ points.Add(points[0]);
+ points.Add((int)(height / 2));
+ points.Add(0);
+ points.Add((int)(height / 2));
+ points.Add(0);
+ points.Add(points[1]);
+
+ return points.ToArray();
+ }
+ }
+
+ public int[] ToPolygonPointsReflection(double height)
+ {
+ lock (Points)
+ {
+ List<int> points = new List<int>();
+
+ for (int i = 0; i < Points.Count; i++)
+ {
+ points.Add((int)Points[i].XValue);
+ points.Add((int)(height - Points[i].YValue));
+ }
+
+ return points.ToArray();
+ }
+ }
+
+ public int[] ToPolygonPointsReflection(double height, double scaleFactor, Func<double, double> scaleY)
+ {
+ double xValue = 0;
+
+ lock (Points)
+ {
+ List<int> points = new List<int>();
+
+ for (int i = 0; i < Points.Count; i++)
+ {
+ points.Add((int)xValue);
+ points.Add((int)(height - scaleY(Points[i].YValue)));
+
+ xValue += scaleFactor;
+ }
+
+ return points.ToArray();
+ }
+ }
+
+ public int[] ToPolygonPointsFill(double width, double height)
+ {
+ lock (Points)
+ {
+ List<int> points = new List<int>();
+
+ for (int i = 0; i < Points.Count; i++)
+ {
+ points.Add((int)Points[i].XValue);
+ points.Add((int)Points[i].YValue);
+ }
+
+ points.Add((int)width);
+ points.Add((int)height);
+ points.Add(0);
+ points.Add((int)height);
+ points.Add(0);
+ points.Add(points[1]);
+
+ return points.ToArray();
+ }
+ }
+
+ public int[] ToPolygonPointsFill(double width, double height, double scaleFactor, Func<double, double> scaleY)
+ {
+ double xValue = 0;
+
+ lock (Points)
+ {
+ List<int> points = new List<int>();
+
+ for (int i = 0; i < Points.Count; i++)
+ {
+ points.Add((int)xValue);
+ points.Add((int)scaleY(Points[i].YValue));
+
+ xValue += scaleFactor;
+ }
+
+ points.Add((int)(xValue - scaleFactor));
+ points.Add((int)height);
+ points.Add(0);
+ points.Add((int)height);
+ points.Add(0);
+ points.Add(points[1]);
+
+ return points.ToArray();
+ }
+ }
+
+ public int[] ToPolygonPointsWaveFill(double width, double height)
+ {
+ lock (Points)
+ {
+ List<int> points = new List<int>();
+
+ for (int i = 0; i < Points.Count; i++)
+ {
+ points.Add((int)Points[i].XValue);
+ points.Add((int)Points[i].YValue);
+ }
+
+ for (int i = Points.Count - 1; i >= 0; i--)
+ {
+ points.Add((int)Points[i].XValue);
+ points.Add((int)(height - Points[i].YValue));
+ }
+
+ points.Add(points[0]);
+ points.Add((int)(height / 2));
+ points.Add(0);
+ points.Add((int)(height / 2));
+ points.Add(0);
+ points.Add(points[1]);
+
+ return points.ToArray();
+ }
+ }
+
+ public int[] ToPolygonPointsWaveFill(double width, double height, double scaleFactor, Func<double, double> scaleY)
+ {
+ double xValue = 0;
+
+ lock (Points)
+ {
+ List<int> points = new List<int>();
+
+ for (int i = 0; i < Points.Count; i++)
+ {
+ points.Add((int)xValue);
+ points.Add((int)(scaleY(Points[i].YValue)));
+
+ xValue += scaleFactor;
+ }
+
+ points.Add((int)width);
+ points.Add((int)(height / 2));
+
+ points.Add((int)width);
+ points.Add((int)(height - scaleY(Points[Points.Count - 1].YValue)));
+
+ xValue -= scaleFactor;
+
+ for (int i = Points.Count - 1; i >= 0; i--)
+ {
+ points.Add((int)xValue);
+ points.Add((int)(height - scaleY(Points[i].YValue)));
+
+ xValue -= scaleFactor;
+ }
+
+ points.Add(0);
+ points.Add(points[points.Count - 2]);
+ points.Add(points[0]);
+ points.Add((int)(height / 2));
+ points.Add(0);
+ points.Add((int)(height / 2));
+ points.Add(0);
+ points.Add(points[1]);
+
+ return points.ToArray();
+ }
+ }
+ }
+}