From e48f9ba06680e9447eb82e44d38eacc664850ac5 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 12:58:03 -0700 Subject: Allow zooming on graph --- grapher/Form1.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 495640e..3e627fe 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -44,6 +44,23 @@ namespace grapher } this.AccelerationChart.ChartAreas[0].AxisX.RoundAxisValues(); + + this.AccelerationChart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; + this.AccelerationChart.ChartAreas[0].AxisY.ScaleView.Zoomable = true; + + this.AccelerationChart.ChartAreas[0].AxisY.ScaleView.MinSize = 0.01; + this.AccelerationChart.ChartAreas[0].AxisY.ScaleView.SmallScrollSize = 0.001; + + this.AccelerationChart.ChartAreas[0].CursorY.Interval = 0.001; + + this.AccelerationChart.ChartAreas[0].CursorX.AutoScroll = true; + this.AccelerationChart.ChartAreas[0].CursorY.AutoScroll = true; + + this.AccelerationChart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; + this.AccelerationChart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; + + this.AccelerationChart.ChartAreas[0].CursorX.IsUserEnabled = true; + this.AccelerationChart.ChartAreas[0].CursorY.IsUserEnabled = true; } public static double Magnitude(int x, int y) -- cgit v1.2.3 From 46027296f75691cf150aa279a374da3adabf8c44 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 14:21:33 -0700 Subject: Added skeleton for input fields --- grapher/Form1.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 3e627fe..6e81984 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -77,5 +77,30 @@ namespace grapher { } + + private void listBox1_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + private void label1_Click(object sender, EventArgs e) + { + + } + + private void textBox3_TextChanged(object sender, EventArgs e) + { + + } + + private void label6_Click(object sender, EventArgs e) + { + + } } } -- cgit v1.2.3 From 7d0f8a2028ef8977c68c92c9c0bba4272cc10773 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 17:31:08 -0700 Subject: Rename elements and add write button --- grapher/Form1.cs | 100 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 41 deletions(-) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 6e81984..3312269 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -12,37 +12,14 @@ namespace grapher { public partial class RawAcceleration : Form { + #region Constructor + public RawAcceleration() { InitializeComponent(); - var managedAccel = new ManagedAccel(5, 0, 0.3, 1.25, 15); - var orderedPoints = new SortedDictionary(); - - for (int i = 0; i < 100; i++) - { - for (int j = 0; j <= i; j++) - { - var output = managedAccel.Accelerate(i, j, 1); - - var inMagnitude = Magnitude(i,j); - var outMagnitude = Magnitude(output.Item1, output.Item2); - var ratio = inMagnitude > 0 ? outMagnitude / inMagnitude : 0; - - if (!orderedPoints.ContainsKey(inMagnitude)) - { - orderedPoints.Add(inMagnitude, ratio); - } - } - } - - var series = this.AccelerationChart.Series.FirstOrDefault(); - series.Points.Clear(); - - foreach (var point in orderedPoints) - { - series.Points.AddXY(point.Key, point.Value); - } - + ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); + UpdateGraph(); + this.AccelerationChart.ChartAreas[0].AxisX.RoundAxisValues(); this.AccelerationChart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; @@ -62,6 +39,33 @@ namespace grapher this.AccelerationChart.ChartAreas[0].CursorX.IsUserEnabled = true; this.AccelerationChart.ChartAreas[0].CursorY.IsUserEnabled = true; } + #endregion Constructor + + #region Properties + + public ManagedAccel ManagedAcceleration { get; set; } + + private int AccelerationType { get; set; } + + private Tuple Sensitivity { get; set; } + + private double Rotation { get; set; } + + private Tuple Weight { get; set; } + + private double Cap { get; set; } + + private double Offset { get; set; } + + private double Acceleration { get; set; } + + private double LimitOrExponent { get; set; } + + private double Midpoint { get; set; } + + #endregion Properties + + #region Methods public static double Magnitude(int x, int y) { @@ -78,29 +82,43 @@ namespace grapher } - private void listBox1_SelectedIndexChanged(object sender, EventArgs e) + private void UpdateGraph() { + var orderedPoints = new SortedDictionary(); - } + for (int i = 0; i < 100; i++) + { + for (int j = 0; j <= i; j++) + { + var output = ManagedAcceleration.Accelerate(i, j, 1); - private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) - { + var inMagnitude = Magnitude(i,j); + var outMagnitude = Magnitude(output.Item1, output.Item2); + var ratio = inMagnitude > 0 ? outMagnitude / inMagnitude : 0; - } + if (!orderedPoints.ContainsKey(inMagnitude)) + { + orderedPoints.Add(inMagnitude, ratio); + } + } + } - private void label1_Click(object sender, EventArgs e) - { + var series = this.AccelerationChart.Series.FirstOrDefault(); + series.Points.Clear(); + foreach (var point in orderedPoints) + { + series.Points.AddXY(point.Key, point.Value); + } } - private void textBox3_TextChanged(object sender, EventArgs e) - { - - } + #endregion Methods - private void label6_Click(object sender, EventArgs e) + private void writeButton_Click(object sender, EventArgs e) { - + ManagedAcceleration.UpdateAccel(5, 0, 1.3, 9, 15); + ManagedAcceleration.WriteToDriver(); + UpdateGraph(); } } } -- cgit v1.2.3 From 93d4d0fe6a356953b5dd78f60393f2a70a73afb3 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 18:14:27 -0700 Subject: Take new data for most fields by pressing enter --- grapher/Form1.cs | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 2 deletions(-) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 3312269..431dd53 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -38,6 +38,10 @@ namespace grapher this.AccelerationChart.ChartAreas[0].CursorX.IsUserEnabled = true; this.AccelerationChart.ChartAreas[0].CursorY.IsUserEnabled = true; + + Acceleration = 0; + LimitOrExponent = 1.01; + Midpoint = 0; } #endregion Constructor @@ -47,7 +51,7 @@ namespace grapher private int AccelerationType { get; set; } - private Tuple Sensitivity { get; set; } + private double Sensitivity { get; set; } private double Rotation { get; set; } @@ -116,9 +120,88 @@ namespace grapher private void writeButton_Click(object sender, EventArgs e) { - ManagedAcceleration.UpdateAccel(5, 0, 1.3, 9, 15); + ManagedAcceleration.UpdateAccel(5, 0, Acceleration, LimitOrExponent, Midpoint); ManagedAcceleration.WriteToDriver(); UpdateGraph(); } + + private void sensitivityBox_KeyDown(object sender, KeyEventArgs e) + { + if (TryHandleWithEnter(e, sender, out double data)) + { + Sensitivity = data; + } + } + + private bool TryHandleWithEnter(KeyEventArgs e, object sender, out double data) + { + bool validEntry = false; + data = 0.0; + + if (e.KeyCode == Keys.Enter) + { + try + { + data = Convert.ToDouble(((TextBox)sender).Text); + validEntry = true; + } + catch + { + } + + e.Handled = true; + e.SuppressKeyPress = true; + } + + return validEntry; + } + + private void accelerationBox_KeyDown(object sender, KeyEventArgs e) + { + if (TryHandleWithEnter(e, sender, out double data)) + { + Acceleration = data; + } + } + + private void rotationBox_KeyDown(object sender, KeyEventArgs e) + { + if (TryHandleWithEnter(e, sender, out double data)) + { + Rotation = data; + } + } + + private void capBox_KeyDown(object sender, KeyEventArgs e) + { + if (TryHandleWithEnter(e, sender, out double data)) + { + Cap = data; + } + } + + private void offsetBox_KeyDown(object sender, KeyEventArgs e) + { + if (TryHandleWithEnter(e, sender, out double data)) + { + Offset = data; + } + } + + private void limitBox_KeyDown(object sender, KeyEventArgs e) + { + if (TryHandleWithEnter(e, sender, out double data)) + { + LimitOrExponent = data; + } + } + + private void midpointBox_KeyDown(object sender, KeyEventArgs e) + { + if (TryHandleWithEnter(e, sender, out double data)) + { + Midpoint = data; + } + } } } -- cgit v1.2.3 From 953fd6e30faae4f8eecfe2fde2b47cf42da51ca8 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 18:50:43 -0700 Subject: Take all variables through GUI --- grapher/Form1.cs | 96 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 70 insertions(+), 26 deletions(-) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 431dd53..d1244f3 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -17,7 +17,18 @@ namespace grapher public RawAcceleration() { InitializeComponent(); + ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); + AccelerationType = 5; + Sensitivity = new VectorXY(1); + Rotation = 0; + Weight = new VectorXY(1); + Cap = new VectorXY(0); + Offset = 0; + Acceleration = 0; + LimitOrExponent = 1.01; + Midpoint = 0; + UpdateGraph(); this.AccelerationChart.ChartAreas[0].AxisX.RoundAxisValues(); @@ -38,11 +49,8 @@ namespace grapher this.AccelerationChart.ChartAreas[0].CursorX.IsUserEnabled = true; this.AccelerationChart.ChartAreas[0].CursorY.IsUserEnabled = true; - - Acceleration = 0; - LimitOrExponent = 1.01; - Midpoint = 0; } + #endregion Constructor #region Properties @@ -51,13 +59,13 @@ namespace grapher private int AccelerationType { get; set; } - private double Sensitivity { get; set; } + private VectorXY Sensitivity { get; set; } private double Rotation { get; set; } - private Tuple Weight { get; set; } + private VectorXY Weight { get; set; } - private double Cap { get; set; } + private VectorXY Cap { get; set; } private double Offset { get; set; } @@ -98,7 +106,7 @@ namespace grapher var inMagnitude = Magnitude(i,j); var outMagnitude = Magnitude(output.Item1, output.Item2); - var ratio = inMagnitude > 0 ? outMagnitude / inMagnitude : 0; + var ratio = inMagnitude > 0 ? outMagnitude / inMagnitude : Sensitivity.X; if (!orderedPoints.ContainsKey(inMagnitude)) { @@ -116,23 +124,6 @@ namespace grapher } } - #endregion Methods - - private void writeButton_Click(object sender, EventArgs e) - { - ManagedAcceleration.UpdateAccel(5, 0, Acceleration, LimitOrExponent, Midpoint); - ManagedAcceleration.WriteToDriver(); - UpdateGraph(); - } - - private void sensitivityBox_KeyDown(object sender, KeyEventArgs e) - { - if (TryHandleWithEnter(e, sender, out double data)) - { - Sensitivity = data; - } - } - private bool TryHandleWithEnter(KeyEventArgs e, object sender, out double data) { bool validEntry = false; @@ -156,6 +147,32 @@ namespace grapher return validEntry; } + private void writeButton_Click(object sender, EventArgs e) + { + ManagedAcceleration.UpdateAccel( + AccelerationType, + Sensitivity.X, + Sensitivity.Y, + Weight.X, + Weight.Y, + Cap.X, + Cap.Y, + Offset, + Acceleration, + LimitOrExponent, + Midpoint); + ManagedAcceleration.WriteToDriver(); + UpdateGraph(); + } + + private void sensitivityBox_KeyDown(object sender, KeyEventArgs e) + { + if (TryHandleWithEnter(e, sender, out double data)) + { + Sensitivity.SetBoth(data); + } + } + private void accelerationBox_KeyDown(object sender, KeyEventArgs e) { if (TryHandleWithEnter(e, sender, out double data)) @@ -176,7 +193,7 @@ namespace grapher { if (TryHandleWithEnter(e, sender, out double data)) { - Cap = data; + Cap.SetBoth(data); } } @@ -203,5 +220,32 @@ namespace grapher Midpoint = data; } } + + #endregion Methods + + public class VectorXY + { + public VectorXY(double x) + { + X = x; + Y = x; + } + + public VectorXY(double x, double y) + { + X = x; + Y = y; + } + + public double X { get; set; } + + public double Y { get; set; } + + public void SetBoth(double value) + { + X = value; + Y = value; + } + } } } -- cgit v1.2.3 From 621ab8d23d10c892a18c39234b24266fd90b90fa Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 19:35:57 -0700 Subject: Separate classes into files, add Field class for text box state --- grapher/Form1.cs | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index d1244f3..fbf5dfb 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -25,7 +25,7 @@ namespace grapher Weight = new VectorXY(1); Cap = new VectorXY(0); Offset = 0; - Acceleration = 0; + Acceleration = new Field("0.0", this.accelerationBox, 0); LimitOrExponent = 1.01; Midpoint = 0; @@ -69,7 +69,7 @@ namespace grapher private double Offset { get; set; } - private double Acceleration { get; set; } + private Field Acceleration { get; set; } private double LimitOrExponent { get; set; } @@ -158,7 +158,7 @@ namespace grapher Cap.X, Cap.Y, Offset, - Acceleration, + Acceleration.Data, LimitOrExponent, Midpoint); ManagedAcceleration.WriteToDriver(); @@ -173,14 +173,6 @@ namespace grapher } } - private void accelerationBox_KeyDown(object sender, KeyEventArgs e) - { - if (TryHandleWithEnter(e, sender, out double data)) - { - Acceleration = data; - } - } - private void rotationBox_KeyDown(object sender, KeyEventArgs e) { if (TryHandleWithEnter(e, sender, out double data)) @@ -222,30 +214,5 @@ namespace grapher } #endregion Methods - - public class VectorXY - { - public VectorXY(double x) - { - X = x; - Y = x; - } - - public VectorXY(double x, double y) - { - X = x; - Y = y; - } - - public double X { get; set; } - - public double Y { get; set; } - - public void SetBoth(double value) - { - X = value; - Y = value; - } - } } } -- cgit v1.2.3 From 769deb7d9f8fca973432e74d2a6fac8697091fc2 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 20:10:18 -0700 Subject: All single-value boxes use fields --- grapher/Form1.cs | 56 ++++++++++++-------------------------------------------- 1 file changed, 12 insertions(+), 44 deletions(-) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index fbf5dfb..ef0dd3a 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -21,13 +21,13 @@ namespace grapher ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); AccelerationType = 5; Sensitivity = new VectorXY(1); - Rotation = 0; + Rotation = new Field("0.0", rotationBox, this, 0); Weight = new VectorXY(1); Cap = new VectorXY(0); - Offset = 0; - Acceleration = new Field("0.0", this.accelerationBox, 0); - LimitOrExponent = 1.01; - Midpoint = 0; + Offset = new Field("0.0", offsetBox, this, 0); + Acceleration = new Field("0.0", accelerationBox, this, 0); + LimitOrExponent = new Field("2.0", limitBox, this, 2); + Midpoint = new Field("0.0", midpointBox, this, 0); UpdateGraph(); @@ -61,19 +61,19 @@ namespace grapher private VectorXY Sensitivity { get; set; } - private double Rotation { get; set; } + private Field Rotation { get; set; } private VectorXY Weight { get; set; } private VectorXY Cap { get; set; } - private double Offset { get; set; } + private Field Offset { get; set; } private Field Acceleration { get; set; } - private double LimitOrExponent { get; set; } + private Field LimitOrExponent { get; set; } - private double Midpoint { get; set; } + private Field Midpoint { get; set; } #endregion Properties @@ -157,10 +157,10 @@ namespace grapher Weight.Y, Cap.X, Cap.Y, - Offset, + Offset.Data, Acceleration.Data, - LimitOrExponent, - Midpoint); + LimitOrExponent.Data, + Midpoint.Data); ManagedAcceleration.WriteToDriver(); UpdateGraph(); } @@ -173,14 +173,6 @@ namespace grapher } } - private void rotationBox_KeyDown(object sender, KeyEventArgs e) - { - if (TryHandleWithEnter(e, sender, out double data)) - { - Rotation = data; - } - } - private void capBox_KeyDown(object sender, KeyEventArgs e) { if (TryHandleWithEnter(e, sender, out double data)) @@ -189,30 +181,6 @@ namespace grapher } } - private void offsetBox_KeyDown(object sender, KeyEventArgs e) - { - if (TryHandleWithEnter(e, sender, out double data)) - { - Offset = data; - } - } - - private void limitBox_KeyDown(object sender, KeyEventArgs e) - { - if (TryHandleWithEnter(e, sender, out double data)) - { - LimitOrExponent = data; - } - } - - private void midpointBox_KeyDown(object sender, KeyEventArgs e) - { - if (TryHandleWithEnter(e, sender, out double data)) - { - Midpoint = data; - } - } - #endregion Methods } } -- cgit v1.2.3 From 36abeecf953e0efcd1ec9dcafa4bd1c554e362f5 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 21:03:02 -0700 Subject: Add FieldXY --- grapher/Form1.cs | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index ef0dd3a..2bc4da7 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -20,14 +20,14 @@ namespace grapher ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); AccelerationType = 5; - Sensitivity = new VectorXY(1); - Rotation = new Field("0.0", rotationBox, this, 0); - Weight = new VectorXY(1); - Cap = new VectorXY(0); - Offset = new Field("0.0", offsetBox, this, 0); - Acceleration = new Field("0.0", accelerationBox, this, 0); - LimitOrExponent = new Field("2.0", limitBox, this, 2); - Midpoint = new Field("0.0", midpointBox, this, 0); + Sensitivity = new FieldXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1); + Rotation = new Field(rotationBox, this, 0); + Weight = new FieldXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1); + Cap = new FieldXY(capBoxX, capBoxY, capXYLock, this, 0); + Offset = new Field(offsetBox, this, 0); + Acceleration = new Field(accelerationBox, this, 0); + LimitOrExponent = new Field(limitBox, this, 2); + Midpoint = new Field(midpointBox, this, 0); UpdateGraph(); @@ -59,13 +59,13 @@ namespace grapher private int AccelerationType { get; set; } - private VectorXY Sensitivity { get; set; } + private FieldXY Sensitivity { get; set; } private Field Rotation { get; set; } - private VectorXY Weight { get; set; } + private FieldXY Weight { get; set; } - private VectorXY Cap { get; set; } + private FieldXY Cap { get; set; } private Field Offset { get; set; } @@ -165,22 +165,6 @@ namespace grapher UpdateGraph(); } - private void sensitivityBox_KeyDown(object sender, KeyEventArgs e) - { - if (TryHandleWithEnter(e, sender, out double data)) - { - Sensitivity.SetBoth(data); - } - } - - private void capBox_KeyDown(object sender, KeyEventArgs e) - { - if (TryHandleWithEnter(e, sender, out double data)) - { - Cap.SetBoth(data); - } - } - #endregion Methods } } -- cgit v1.2.3 From d7e1121eb62b9842f9d19bddaf3e633d3dbe0924 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 29 Jul 2020 21:26:13 -0700 Subject: Adde accel type switch --- grapher/Form1.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 2bc4da7..8dd4b8b 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -166,5 +166,33 @@ namespace grapher } #endregion Methods + + private void accelTypeDrop_SelectedIndexChanged(object sender, EventArgs e) + { + switch(this.accelTypeDrop.SelectedItem.ToString()) + { + case ("Linear"): + AccelerationType = 1; + break; + case ("Classic"): + AccelerationType = 2; + break; + case ("Natural"): + AccelerationType = 3; + break; + case ("Logarithmic"): + AccelerationType = 4; + break; + case ("Sigmoid"): + AccelerationType = 5; + break; + case ("Power"): + AccelerationType = 6; + break; + default: + AccelerationType = 0; + break; + } + } } } -- cgit v1.2.3 From 20ea6f85cb0af56c13dabbfc3f65383af8793c7c Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 30 Jul 2020 00:32:48 -0700 Subject: Fix small bugs, add AccelOptions class --- grapher/Form1.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 8dd4b8b..e35f097 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -19,7 +19,7 @@ namespace grapher InitializeComponent(); ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); - AccelerationType = 5; + AccelerationType = 0; Sensitivity = new FieldXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1); Rotation = new Field(rotationBox, this, 0); Weight = new FieldXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1); @@ -151,6 +151,7 @@ namespace grapher { ManagedAcceleration.UpdateAccel( AccelerationType, + Rotation.Data, Sensitivity.X, Sensitivity.Y, Weight.X, -- cgit v1.2.3 From 3cbec32cfa91bad661bc126b517faf78458a27a6 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 30 Jul 2020 01:13:24 -0700 Subject: Fully use acceloptions --- grapher/Form1.cs | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index e35f097..ecb6ead 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -19,7 +19,11 @@ namespace grapher InitializeComponent(); ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); - AccelerationType = 0; + AccelerationOptions = new AccelOptions( + accelTypeDrop, + new Option(accelerationBox, constantOneLabel), + new Option(limitBox, constantTwoLabel), + new Option(midpointBox, constantThreeLabel)); Sensitivity = new FieldXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1); Rotation = new Field(rotationBox, this, 0); Weight = new FieldXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1); @@ -57,7 +61,7 @@ namespace grapher public ManagedAccel ManagedAcceleration { get; set; } - private int AccelerationType { get; set; } + private AccelOptions AccelerationOptions { get; set; } private FieldXY Sensitivity { get; set; } @@ -150,7 +154,7 @@ namespace grapher private void writeButton_Click(object sender, EventArgs e) { ManagedAcceleration.UpdateAccel( - AccelerationType, + AccelerationOptions.AccelerationIndex, Rotation.Data, Sensitivity.X, Sensitivity.Y, @@ -168,32 +172,9 @@ namespace grapher #endregion Methods - private void accelTypeDrop_SelectedIndexChanged(object sender, EventArgs e) + private void label3_Click(object sender, EventArgs e) { - switch(this.accelTypeDrop.SelectedItem.ToString()) - { - case ("Linear"): - AccelerationType = 1; - break; - case ("Classic"): - AccelerationType = 2; - break; - case ("Natural"): - AccelerationType = 3; - break; - case ("Logarithmic"): - AccelerationType = 4; - break; - case ("Sigmoid"): - AccelerationType = 5; - break; - case ("Power"): - AccelerationType = 6; - break; - default: - AccelerationType = 0; - break; - } + } } } -- cgit v1.2.3 From f315e8160e984df93be6667929db34749aa25cfa Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 30 Jul 2020 02:00:20 -0700 Subject: Use class heirarchy for layout types --- grapher/Form1.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index ecb6ead..93e0768 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -21,9 +21,12 @@ namespace grapher ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); AccelerationOptions = new AccelOptions( accelTypeDrop, - new Option(accelerationBox, constantOneLabel), - new Option(limitBox, constantTwoLabel), - new Option(midpointBox, constantThreeLabel)); + new Option[] + { + new Option(accelerationBox, constantOneLabel), + new Option(limitBox, constantTwoLabel), + new Option(midpointBox, constantThreeLabel) + }); Sensitivity = new FieldXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1); Rotation = new Field(rotationBox, this, 0); Weight = new FieldXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1); -- cgit v1.2.3 From 49bd00c71b223d12f1d85d5c1bae635d450403fd Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 30 Jul 2020 20:15:12 -0700 Subject: Use options instead of fields --- grapher/Form1.cs | 94 ++++++++++++++++++++++++-------------------------------- 1 file changed, 40 insertions(+), 54 deletions(-) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index 93e0768..b1ab2fa 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -19,22 +19,31 @@ namespace grapher InitializeComponent(); ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); + Sensitivity = new OptionXY(new FieldXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1), sensitivityLabel); + Rotation = new Option(new Field(rotationBox, this, 0), rotationLabel); + Weight = new OptionXY(new FieldXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1), weightLabel); + Cap = new OptionXY(new FieldXY(capBoxX, capBoxY, capXYLock, this, 0), capLabel); + Offset = new Option(new Field(offsetBox, this, 0), offsetLabel); + + Sensitivity.SetName("Sensitivity"); + Rotation.SetName("Rotation"); + Weight.SetName("Weight"); + Cap.SetName("Cap"); + Offset.SetName("Offset"); + + // The name and layout of these options is handled by AccelerationOptions object. + Acceleration = new Option(new Field(accelerationBox, this, 0), constantOneLabel); + LimitOrExponent = new Option(new Field(limitBox, this, 2), constantTwoLabel); + Midpoint = new Option(new Field(midpointBox, this, 0), constantThreeLabel); + AccelerationOptions = new AccelOptions( accelTypeDrop, new Option[] { - new Option(accelerationBox, constantOneLabel), - new Option(limitBox, constantTwoLabel), - new Option(midpointBox, constantThreeLabel) + Acceleration, + LimitOrExponent, + Midpoint, }); - Sensitivity = new FieldXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1); - Rotation = new Field(rotationBox, this, 0); - Weight = new FieldXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1); - Cap = new FieldXY(capBoxX, capBoxY, capXYLock, this, 0); - Offset = new Field(offsetBox, this, 0); - Acceleration = new Field(accelerationBox, this, 0); - LimitOrExponent = new Field(limitBox, this, 2); - Midpoint = new Field(midpointBox, this, 0); UpdateGraph(); @@ -66,21 +75,21 @@ namespace grapher private AccelOptions AccelerationOptions { get; set; } - private FieldXY Sensitivity { get; set; } + private OptionXY Sensitivity { get; set; } - private Field Rotation { get; set; } + private Option Rotation { get; set; } - private FieldXY Weight { get; set; } + private OptionXY Weight { get; set; } - private FieldXY Cap { get; set; } + private OptionXY Cap { get; set; } - private Field Offset { get; set; } + private Option Offset { get; set; } - private Field Acceleration { get; set; } + private Option Acceleration { get; set; } - private Field LimitOrExponent { get; set; } + private Option LimitOrExponent { get; set; } - private Field Midpoint { get; set; } + private Option Midpoint { get; set; } #endregion Properties @@ -113,7 +122,7 @@ namespace grapher var inMagnitude = Magnitude(i,j); var outMagnitude = Magnitude(output.Item1, output.Item2); - var ratio = inMagnitude > 0 ? outMagnitude / inMagnitude : Sensitivity.X; + var ratio = inMagnitude > 0 ? outMagnitude / inMagnitude : Sensitivity.Fields.X; if (!orderedPoints.ContainsKey(inMagnitude)) { @@ -131,44 +140,21 @@ namespace grapher } } - private bool TryHandleWithEnter(KeyEventArgs e, object sender, out double data) - { - bool validEntry = false; - data = 0.0; - - if (e.KeyCode == Keys.Enter) - { - try - { - data = Convert.ToDouble(((TextBox)sender).Text); - validEntry = true; - } - catch - { - } - - e.Handled = true; - e.SuppressKeyPress = true; - } - - return validEntry; - } - private void writeButton_Click(object sender, EventArgs e) { ManagedAcceleration.UpdateAccel( AccelerationOptions.AccelerationIndex, - Rotation.Data, - Sensitivity.X, - Sensitivity.Y, - Weight.X, - Weight.Y, - Cap.X, - Cap.Y, - Offset.Data, - Acceleration.Data, - LimitOrExponent.Data, - Midpoint.Data); + Rotation.Field.Data, + Sensitivity.Fields.X, + Sensitivity.Fields.Y, + Weight.Fields.X, + Weight.Fields.Y, + Cap.Fields.X, + Cap.Fields.Y, + Offset.Field.Data, + Acceleration.Field.Data, + LimitOrExponent.Field.Data, + Midpoint.Field.Data); ManagedAcceleration.WriteToDriver(); UpdateGraph(); } -- cgit v1.2.3 From 498e5c1a2fabed3ba5f1c00768d7050c5738e76e Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Fri, 31 Jul 2020 10:46:23 -0700 Subject: Small refactoring, use new struct to store magnitudes --- grapher/Form1.cs | 64 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 22 deletions(-) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index b1ab2fa..c6ac407 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.ComponentModel; using System.Data; using System.Drawing; @@ -12,24 +13,27 @@ namespace grapher { public partial class RawAcceleration : Form { + public struct MagnitudeData + { + public double magnitude; + public int x; + public int y; + } + #region Constructor + public static ReadOnlyCollection Magnitudes = GetMagnitudes(); + public RawAcceleration() { InitializeComponent(); ManagedAcceleration = new ManagedAccel(5, 0, 0.3, 1.25, 15); - Sensitivity = new OptionXY(new FieldXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1), sensitivityLabel); - Rotation = new Option(new Field(rotationBox, this, 0), rotationLabel); - Weight = new OptionXY(new FieldXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1), weightLabel); - Cap = new OptionXY(new FieldXY(capBoxX, capBoxY, capXYLock, this, 0), capLabel); - Offset = new Option(new Field(offsetBox, this, 0), offsetLabel); - - Sensitivity.SetName("Sensitivity"); - Rotation.SetName("Rotation"); - Weight.SetName("Weight"); - Cap.SetName("Cap"); - Offset.SetName("Offset"); + Sensitivity = new OptionXY(sensitivityBoxX, sensitivityBoxY, sensXYLock, this, 1, sensitivityLabel, "Sensitivity"); + Rotation = new Option(rotationBox, this, 0, rotationLabel, "Rotation"); + Weight = new OptionXY(weightBoxFirst, weightBoxSecond, weightXYLock, this, 1, weightLabel, "Weight"); + Cap = new OptionXY(capBoxX, capBoxY, capXYLock, this, 0, capLabel, "Cap"); + Offset = new Option(offsetBox, this, 0, offsetLabel, "Offset"); // The name and layout of these options is handled by AccelerationOptions object. Acceleration = new Option(new Field(accelerationBox, this, 0), constantOneLabel); @@ -95,6 +99,26 @@ namespace grapher #region Methods + public static ReadOnlyCollection GetMagnitudes() + { + var magnitudes = new List(); + for (int i = 0; i < 100; i++) + { + for (int j = 0; j <= i; j++) + { + MagnitudeData magnitudeData; + magnitudeData.magnitude = Magnitude(i, j); + magnitudeData.x = i; + magnitudeData.y = j; + magnitudes.Add(magnitudeData); + } + } + + magnitudes.Sort((m1, m2) => m1.magnitude.CompareTo(m2.magnitude)); + + return magnitudes.AsReadOnly(); + } + public static double Magnitude(int x, int y) { return Math.Sqrt(x * x + y * y); @@ -114,20 +138,16 @@ namespace grapher { var orderedPoints = new SortedDictionary(); - for (int i = 0; i < 100; i++) + foreach (var magnitudeData in Magnitudes) { - for (int j = 0; j <= i; j++) - { - var output = ManagedAcceleration.Accelerate(i, j, 1); + var output = ManagedAcceleration.Accelerate(magnitudeData.x, magnitudeData.y, 1); - var inMagnitude = Magnitude(i,j); - var outMagnitude = Magnitude(output.Item1, output.Item2); - var ratio = inMagnitude > 0 ? outMagnitude / inMagnitude : Sensitivity.Fields.X; + var outMagnitude = Magnitude(output.Item1, output.Item2); + var ratio = magnitudeData.magnitude > 0 ? outMagnitude / magnitudeData.magnitude : Sensitivity.Fields.X; - if (!orderedPoints.ContainsKey(inMagnitude)) - { - orderedPoints.Add(inMagnitude, ratio); - } + if (!orderedPoints.ContainsKey(magnitudeData.magnitude)) + { + orderedPoints.Add(magnitudeData.magnitude, ratio); } } -- cgit v1.2.3 From 827f860b80b5195315ac5b2b8dffb32cf532e0d1 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Fri, 31 Jul 2020 10:56:26 -0700 Subject: Add class for storing settings from file --- grapher/Form1.cs | 5 ----- 1 file changed, 5 deletions(-) (limited to 'grapher/Form1.cs') diff --git a/grapher/Form1.cs b/grapher/Form1.cs index c6ac407..e0953eb 100644 --- a/grapher/Form1.cs +++ b/grapher/Form1.cs @@ -180,10 +180,5 @@ namespace grapher } #endregion Methods - - private void label3_Click(object sender, EventArgs e) - { - - } } } -- cgit v1.2.3