diff options
| author | Jacob Palecki <[email protected]> | 2020-07-31 10:46:23 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-07-31 10:46:23 -0700 |
| commit | 498e5c1a2fabed3ba5f1c00768d7050c5738e76e (patch) | |
| tree | b1a2aedce76abedf7585689cbf636f8e92d0583d /grapher | |
| parent | Use options instead of fields (diff) | |
| download | rawaccel-498e5c1a2fabed3ba5f1c00768d7050c5738e76e.tar.xz rawaccel-498e5c1a2fabed3ba5f1c00768d7050c5738e76e.zip | |
Small refactoring, use new struct to store magnitudes
Diffstat (limited to 'grapher')
| -rw-r--r-- | grapher/AccelerationSettings.cs | 13 | ||||
| -rw-r--r-- | grapher/Field.cs | 2 | ||||
| -rw-r--r-- | grapher/Form1.Designer.cs | 28 | ||||
| -rw-r--r-- | grapher/Form1.cs | 64 | ||||
| -rw-r--r-- | grapher/Option.cs | 11 | ||||
| -rw-r--r-- | grapher/OptionXY.cs | 33 | ||||
| -rw-r--r-- | grapher/grapher.csproj | 1 |
7 files changed, 114 insertions, 38 deletions
diff --git a/grapher/AccelerationSettings.cs b/grapher/AccelerationSettings.cs new file mode 100644 index 0000000..83d48db --- /dev/null +++ b/grapher/AccelerationSettings.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher +{ + public class AccelerationSettings + { + public sensitivity + } +} diff --git a/grapher/Field.cs b/grapher/Field.cs index 7ce4c6e..5ef057d 100644 --- a/grapher/Field.cs +++ b/grapher/Field.cs @@ -46,7 +46,7 @@ namespace grapher public TextBox Box { get; } - Form ContainingForm { get; } + private Form ContainingForm { get; } public double Data { get; private set; } diff --git a/grapher/Form1.Designer.cs b/grapher/Form1.Designer.cs index decdeeb..4e89ca8 100644 --- a/grapher/Form1.Designer.cs +++ b/grapher/Form1.Designer.cs @@ -30,9 +30,9 @@ namespace grapher /// </summary> private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.AccelerationChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.accelTypeDrop = new System.Windows.Forms.ComboBox(); this.sensitivityBoxX = new System.Windows.Forms.TextBox(); @@ -64,19 +64,19 @@ namespace grapher // // AccelerationChart // - chartArea1.AxisX.Title = "Speed (counts/ms)"; - chartArea1.AxisY.Title = "Sensitivity (magnitude ratio)"; - chartArea1.Name = "ChartArea1"; - this.AccelerationChart.ChartAreas.Add(chartArea1); - legend1.Name = "Legend1"; - this.AccelerationChart.Legends.Add(legend1); + chartArea2.AxisX.Title = "Speed (counts/ms)"; + chartArea2.AxisY.Title = "Sensitivity (magnitude ratio)"; + chartArea2.Name = "ChartArea1"; + this.AccelerationChart.ChartAreas.Add(chartArea2); + legend2.Name = "Legend1"; + this.AccelerationChart.Legends.Add(legend2); this.AccelerationChart.Location = new System.Drawing.Point(242, 1); this.AccelerationChart.Name = "AccelerationChart"; - series1.ChartArea = "ChartArea1"; - series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series1.Legend = "Legend1"; - series1.Name = "Accelerated Sensitivity"; - this.AccelerationChart.Series.Add(series1); + series2.ChartArea = "ChartArea1"; + series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series2.Legend = "Legend1"; + series2.Name = "Accelerated Sensitivity"; + this.AccelerationChart.Series.Add(series2); this.AccelerationChart.Size = new System.Drawing.Size(721, 312); this.AccelerationChart.TabIndex = 0; this.AccelerationChart.Text = "chart1"; 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<MagnitudeData> 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<MagnitudeData> GetMagnitudes() + { + var magnitudes = new List<MagnitudeData>(); + 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<double, double>(); - 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); } } diff --git a/grapher/Option.cs b/grapher/Option.cs index a2a4f89..8e3ecdf 100644 --- a/grapher/Option.cs +++ b/grapher/Option.cs @@ -15,6 +15,17 @@ namespace grapher Label = label; } + public Option(TextBox box, Form containingForm, double defaultData, Label label) + : this(new Field(box, containingForm, defaultData), label) + { + } + + public Option(TextBox box, Form containingForm, double defaultData, Label label, string startingName) + : this(box, containingForm, defaultData, label) + { + SetName(startingName); + } + public Field Field { get; } public Label Label { get; } diff --git a/grapher/OptionXY.cs b/grapher/OptionXY.cs index c65d1cf..de7fad9 100644 --- a/grapher/OptionXY.cs +++ b/grapher/OptionXY.cs @@ -8,12 +8,43 @@ using System.Windows.Forms; namespace grapher { public class OptionXY - { public OptionXY(FieldXY fields, Label label) + { + public OptionXY(FieldXY fields, Label label) { Fields = fields; Label = label; } + public OptionXY( + TextBox xBox, + TextBox yBox, + CheckBox lockCheckBox, + Form containingForm, + double defaultData, + Label label) + : this(new FieldXY(xBox, yBox, lockCheckBox, containingForm, defaultData), label) + { + } + + public OptionXY( + TextBox xBox, + TextBox yBox, + CheckBox lockCheckBox, + Form containingForm, + double defaultData, + Label label, + string startingName): + this( + xBox, + yBox, + lockCheckBox, + containingForm, + defaultData, + label) + { + SetName(startingName); + } + public FieldXY Fields { get; } public Label Label { get; } diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj index 04d2eaa..207de79 100644 --- a/grapher/grapher.csproj +++ b/grapher/grapher.csproj @@ -47,6 +47,7 @@ <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> + <Compile Include="AccelerationSettings.cs" /> <Compile Include="AccelOptions.cs" /> <Compile Include="Field.cs" /> <Compile Include="FieldXY.cs" /> |