From 9987e39919a3a71ff677303d00070c6e7eebb6e0 Mon Sep 17 00:00:00 2001 From: Marc Noon Date: Thu, 8 Apr 2021 05:31:51 -0700 Subject: [PATCH] Cleaning up naming and prepping for refactoring. --- Graphics/GraphForm.Designer.cs | 88 ++++++++++++++++-- Graphics/GraphForm.cs | 158 +++++++++++++++++++-------------- 2 files changed, 173 insertions(+), 73 deletions(-) diff --git a/Graphics/GraphForm.Designer.cs b/Graphics/GraphForm.Designer.cs index 7c79c3d..ca74573 100644 --- a/Graphics/GraphForm.Designer.cs +++ b/Graphics/GraphForm.Designer.cs @@ -45,6 +45,11 @@ private void InitializeComponent() this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.toolStripStatusLabel2 = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.CheckQuad1 = new System.Windows.Forms.CheckBox(); + this.CheckQuad2 = new System.Windows.Forms.CheckBox(); + this.CheckQuad3 = new System.Windows.Forms.CheckBox(); + this.CheckQuad4 = new System.Windows.Forms.CheckBox(); this.panel5.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); @@ -52,6 +57,7 @@ private void InitializeComponent() this.splitContainer1.SuspendLayout(); this.panel1.SuspendLayout(); this.statusStrip1.SuspendLayout(); + this.groupBox1.SuspendLayout(); this.SuspendLayout(); // // panel2 @@ -82,7 +88,8 @@ private void InitializeComponent() this.panel4.Name = "panel4"; this.panel4.Size = new System.Drawing.Size(1374, 943); this.panel4.TabIndex = 2; - this.panel4.Paint += new System.Windows.Forms.PaintEventHandler(this.panel4_Paint); + this.panel4.Paint += new System.Windows.Forms.PaintEventHandler(this.Panel4_Paint); + this.panel4.Resize += new System.EventHandler(this.Panel4_Resize); // // comboBox1 // @@ -96,6 +103,7 @@ private void InitializeComponent() // this.panel5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left))); + this.panel5.Controls.Add(this.groupBox1); this.panel5.Controls.Add(this.comboBox1); this.panel5.Location = new System.Drawing.Point(3, 3); this.panel5.Name = "panel5"; @@ -146,7 +154,7 @@ private void InitializeComponent() this.btnClear.TabIndex = 4; this.btnClear.Text = "Clear"; this.btnClear.UseVisualStyleBackColor = true; - this.btnClear.Click += new System.EventHandler(this.btnClear_Click); + this.btnClear.Click += new System.EventHandler(this.BtnClear_Click); // // btnPause // @@ -156,7 +164,7 @@ private void InitializeComponent() this.btnPause.TabIndex = 3; this.btnPause.Text = "Pause"; this.btnPause.UseVisualStyleBackColor = true; - this.btnPause.Click += new System.EventHandler(this.btnPause_Click); + this.btnPause.Click += new System.EventHandler(this.BtnPause_Click); // // txtZoom // @@ -164,7 +172,7 @@ private void InitializeComponent() this.txtZoom.Name = "txtZoom"; this.txtZoom.Size = new System.Drawing.Size(196, 39); this.txtZoom.TabIndex = 2; - this.txtZoom.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtZoom_KeyPress); + this.txtZoom.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TxtZoom_KeyPress); // // lblZoom // @@ -184,7 +192,7 @@ private void InitializeComponent() this.btnGraph.TabIndex = 0; this.btnGraph.Text = "Graph"; this.btnGraph.UseVisualStyleBackColor = true; - this.btnGraph.Click += new System.EventHandler(this.btnGraph_Click); + this.btnGraph.Click += new System.EventHandler(this.BtnGraph_Click); // // statusStrip1 // @@ -210,6 +218,67 @@ private void InitializeComponent() this.toolStripStatusLabel1.Size = new System.Drawing.Size(172, 32); this.toolStripStatusLabel1.Text = "StatusMessage"; // + // groupBox1 + // + this.groupBox1.Controls.Add(this.CheckQuad4); + this.groupBox1.Controls.Add(this.CheckQuad3); + this.groupBox1.Controls.Add(this.CheckQuad2); + this.groupBox1.Controls.Add(this.CheckQuad1); + this.groupBox1.Location = new System.Drawing.Point(31, 146); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(347, 210); + this.groupBox1.TabIndex = 5; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Quadrants"; + // + // CheckQuad1 + // + this.CheckQuad1.AutoSize = true; + this.CheckQuad1.Checked = true; + this.CheckQuad1.CheckState = System.Windows.Forms.CheckState.Checked; + this.CheckQuad1.Location = new System.Drawing.Point(7, 39); + this.CheckQuad1.Name = "CheckQuad1"; + this.CheckQuad1.Size = new System.Drawing.Size(184, 36); + this.CheckQuad1.TabIndex = 0; + this.CheckQuad1.Text = "1st Quadrant"; + this.CheckQuad1.UseVisualStyleBackColor = true; + // + // CheckQuad2 + // + this.CheckQuad2.AutoSize = true; + this.CheckQuad2.Checked = true; + this.CheckQuad2.CheckState = System.Windows.Forms.CheckState.Checked; + this.CheckQuad2.Location = new System.Drawing.Point(7, 81); + this.CheckQuad2.Name = "CheckQuad2"; + this.CheckQuad2.Size = new System.Drawing.Size(194, 36); + this.CheckQuad2.TabIndex = 1; + this.CheckQuad2.Text = "2nd Quadrant"; + this.CheckQuad2.UseVisualStyleBackColor = true; + // + // CheckQuad3 + // + this.CheckQuad3.AutoSize = true; + this.CheckQuad3.Checked = true; + this.CheckQuad3.CheckState = System.Windows.Forms.CheckState.Checked; + this.CheckQuad3.Location = new System.Drawing.Point(7, 123); + this.CheckQuad3.Name = "CheckQuad3"; + this.CheckQuad3.Size = new System.Drawing.Size(188, 36); + this.CheckQuad3.TabIndex = 2; + this.CheckQuad3.Text = "3rd Quadrant"; + this.CheckQuad3.UseVisualStyleBackColor = true; + // + // CheckQuad4 + // + this.CheckQuad4.AutoSize = true; + this.CheckQuad4.Checked = true; + this.CheckQuad4.CheckState = System.Windows.Forms.CheckState.Checked; + this.CheckQuad4.Location = new System.Drawing.Point(7, 158); + this.CheckQuad4.Name = "CheckQuad4"; + this.CheckQuad4.Size = new System.Drawing.Size(188, 36); + this.CheckQuad4.TabIndex = 3; + this.CheckQuad4.Text = "4th Quadrant"; + this.CheckQuad4.UseVisualStyleBackColor = true; + // // GraphForm // this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F); @@ -233,6 +302,8 @@ private void InitializeComponent() this.panel1.PerformLayout(); this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -254,6 +325,11 @@ private void InitializeComponent() private System.Windows.Forms.Button btnClear; private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel2; - } + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.CheckBox CheckQuad4; + private System.Windows.Forms.CheckBox CheckQuad3; + private System.Windows.Forms.CheckBox CheckQuad2; + private System.Windows.Forms.CheckBox CheckQuad1; + } } diff --git a/Graphics/GraphForm.cs b/Graphics/GraphForm.cs index 07b9890..1954336 100644 --- a/Graphics/GraphForm.cs +++ b/Graphics/GraphForm.cs @@ -33,70 +33,54 @@ private void Form1_Load(object sender, EventArgs e) // private variables ... make this more extensible and functional and testable - private ReadOnlySequence spts = new ReadOnlySequence(); + private List pts = new List(); private static Queue qpts = new System.Collections.Generic.Queue(); - private int maxX = 1; - private int maxY = 0; - private int minX = 0; - private int minY = 0; private bool dequeing_flag = false; private GraphingState currentGraphingState = GraphingState.stopped; private PaintCommand currentPaintCommand = PaintCommand.opaque; Formula f = new Formula(); - + private Rectangle rect = new Rectangle(); // Green paint brush... TODO: build based on user selection - private System.Drawing.SolidBrush myBrush1 = new System.Drawing.SolidBrush(System.Drawing.Color.DeepSkyBlue); - private System.Drawing.SolidBrush myBrush2 = new System.Drawing.SolidBrush(System.Drawing.Color.DeepPink); - private System.Drawing.SolidBrush myBrush4 = new System.Drawing.SolidBrush(System.Drawing.Color.Gold); - private System.Drawing.SolidBrush myBrush3 = new System.Drawing.SolidBrush(System.Drawing.Color.Green); + private readonly System.Drawing.SolidBrush myBrush1 = new System.Drawing.SolidBrush(System.Drawing.Color.DeepSkyBlue); + private readonly System.Drawing.SolidBrush myBrush2 = new System.Drawing.SolidBrush(System.Drawing.Color.DeepPink); + private readonly System.Drawing.SolidBrush myBrush4 = new System.Drawing.SolidBrush(System.Drawing.Color.Gold); + private readonly System.Drawing.SolidBrush myBrush3 = new System.Drawing.SolidBrush(System.Drawing.Color.Green); // flags - private Boolean runIt = false; - private Boolean breakOut = true; // when set to true it should break out of the next iteration and stop the current plot. This is not very functional but works + private bool runIt = false; + private bool breakOut = true; // when set to true it should break out of the next iteration and stop the current plot. This is not very functional but works /// /// panel4_Paint ... change name to GraphicPaint or Layer Paint etc... /// /// /// - private void panel4_Paint(object sender, PaintEventArgs e) + private void Panel4_Paint(object sender, PaintEventArgs e) { - if (this.currentPaintCommand == PaintCommand.opaque) + + if (currentPaintCommand == PaintCommand.opaque) { - if (this.runIt == true) + if (runIt == true) { while (qpts.Count > 0) { var pt = qpts.Dequeue(); - - //e.Graphics.DrawLine(new Pen(myBrush1), pt, new Point(pt.X - 1, pt.Y)); - //e.Graphics.DrawLine(new Pen(myBrush2), pt, new Point(pt.X, pt.Y - 1)); - //e.Graphics.DrawLine(new Pen(myBrush3), pt, new Point(pt.X, pt.Y)); - //e.Graphics.DrawLine(new Pen(myBrush4), pt, new Point(pt.X - 1, pt.Y - 1)); - - //e.Graphics.DrawLine(new Pen(myBrush3), pt.X, pt.Y, pt.X + 1, pt.Y + 1); - e.Graphics.FillRectangle(myBrush3, pt.X, pt.Y, 1, 1); e.Graphics.FillRectangle(myBrush4, pt.X + 1, pt.Y + 1, 1, 1); e.Graphics.FillRectangle(myBrush1, pt.X + 1, pt.Y, 1, 1); e.Graphics.FillRectangle(myBrush2, pt.X, pt.Y + 1, 1, 1); - //e.Graphics.DrawLine(new Pen(myBrush4), - // pt, - // new Point(pt.X + 1, pt.Y + 1) - //); - } - this.dequeing_flag = false; + dequeing_flag = false; } } - else if (this.currentPaintCommand == PaintCommand.clear) + else if (currentPaintCommand == PaintCommand.clear) { - this.panel4.Invalidate(); - this.currentPaintCommand = PaintCommand.opaque; - this.toolStripStatusLabel2.Text = "Opaque"; + panel4.Invalidate(); + currentPaintCommand = PaintCommand.opaque; + toolStripStatusLabel2.Text = "Opaque"; } } @@ -119,9 +103,36 @@ private async Task performFormula() // notice it doesn't care about y, z, or t... just returns a point for x which is fine as its a simple algorithm + // var rigor + var rigor = 0.005; + // Equations - not very extensible... move equations into a text string then figure out a way to generate these equations dynamically during a plot - var cos = Complex.Sqrt(zoom * x * 1.00 * Math.Cos(x * 1.00)); - var sin = Complex.Sqrt(zoom * x * 1.00 * Math.Sin(x * 1.00)); + //var cosInit = Math.Cos(x * rigor); + //var sinInit = Math.Cos(x * rigor); + + //if (cosInit >= 0 && sinInit >= 0) + //{ + // // 1st quad + //} + //else if (cosInit < 0 && sinInit > 0) + //{ + // // 2nd quad + // //return new Point(0, 0); + //} + //else if (cosInit < 0 && sinInit < 0) + //{ + // // 3rd quad + // //return new Point(0, 0); + + //} + //else + //{ + // // 4th quad + // //return new Point(0, 0); + //} + + Complex cos = Complex.Sqrt(520 + zoom * x * rigor * Math.Cos(x * rigor)); + Complex sin = Complex.Sqrt(520 + zoom * x * rigor * Math.Sin(x * rigor)); // convert the plot during each iteration to a single point to be rendered return new Point( @@ -133,28 +144,28 @@ private async Task performFormula() // iterates over some plot or formula ... may need to change this to x, y, z etc... // needs to use smarter iteration and plots by placing in a thread or threads - for (int x = 0; x < 1_500_000_000; x++) + for (var x = 0; x < 1_500_000_000; x++) { - if (this.breakOut == true) + if (breakOut == true) { - this.currentGraphingState = GraphingState.stopped; - this.toolStripStatusLabel1.Text = "Stopped"; + currentGraphingState = GraphingState.stopped; + toolStripStatusLabel1.Text = "Stopped"; break; } // while pause is pressed loop here waiting for it to be unpressed - while (this.runIt == false) + while (runIt == false) { - this.currentGraphingState = GraphingState.paused; - this.toolStripStatusLabel1.Text = "Paused"; + currentGraphingState = GraphingState.paused; + toolStripStatusLabel1.Text = "Paused"; System.Threading.Thread.Sleep(100); } - this.currentGraphingState = GraphingState.graphing; + currentGraphingState = GraphingState.graphing; // the current offset uses the center of screen plus some number - var ox = this.panel4.Width / 2; - var oy = this.panel4.Height /2; + var ox = panel4.Width / 2; + var oy = panel4.Height /2; //// Equations - not very extensible... move equations into a text string then figure out a way to generate these equations dynamically during a plot //var cos = Complex.Sqrt(200 + zoom * x * 0.0001 * Math.Cos(x * 0.0001)); @@ -169,9 +180,16 @@ private async Task performFormula() // add offset pt = new Point(pt.X + ox, pt.Y + oy); + if (!rect.Contains(pt)) + { + continue; + } + // check that the plot has not already been plotted, otherwise skip or continue to next iteration if (plotPoint.X == pt.X && plotPoint.Y == pt.Y) + { continue; + } // save the current point after testing if it was already plotted last // TODO: perhaps store points in a key value pair where the key is a plotted point... if it was already plotted for a given color then move on @@ -191,10 +209,10 @@ private async Task performFormula() // after every single iteration that wasn't already plotted it will cause plot to invalidated and updated if (x%1 == 0) { - this.dequeing_flag = true; + dequeing_flag = true; // move back to the windows form thread to perform windows form operations using the drawing area and the invoke command - this.panel4.Invoke(new Action(() => + panel4.Invoke(new Action(() => { //panel4.Invalidate(new Rectangle(new Point(pt.X - 1, pt.Y - 1), new Size(2, 2))); @@ -220,16 +238,18 @@ private async Task performFormula() /// /// /// - private void btnGraph_Click(object sender, EventArgs e) + private void BtnGraph_Click(object sender, EventArgs e) { - if (this.currentGraphingState == GraphingState.stopped) + rect = panel4.ClientRectangle; + + if (currentGraphingState == GraphingState.stopped) { - this.breakOut = false; + breakOut = false; btnGraph.Text = "Stop Graphing"; } - else if (this.currentGraphingState == GraphingState.graphing) + else if (currentGraphingState == GraphingState.graphing) { - this.breakOut = true; + breakOut = true; btnGraph.Text = "Graphing"; } else @@ -240,7 +260,7 @@ private void btnGraph_Click(object sender, EventArgs e) // TODO: Check to see if it broke out. Create a nother parameter to check... System.Threading.Thread.Sleep(1000); - this.runIt = true; + runIt = true; _ = Task.Run(async () => { await performFormula(); @@ -248,7 +268,7 @@ private void btnGraph_Click(object sender, EventArgs e) } - private void txtZoom_KeyPress(object sender, KeyPressEventArgs e) + private void TxtZoom_KeyPress(object sender, KeyPressEventArgs e) { // used code from: https://stackoverflow.com/questions/19761487/how-to-make-a-textbox-accept-only-numbers-and-just-one-decimal-point-in-windows // this code prevents anything but numbers and decimal and more numbers @@ -261,29 +281,33 @@ private void txtZoom_KeyPress(object sender, KeyPressEventArgs e) } } - private void btnPause_Click(object sender, EventArgs e) + private void BtnPause_Click(object sender, EventArgs e) { - if (this.runIt == true) + if (runIt == true) { - this.runIt = false; - this.btnPause.Text = "Continue"; - this.toolStripStatusLabel1.Text = "Paused"; + runIt = false; + btnPause.Text = "Continue"; + toolStripStatusLabel1.Text = "Paused"; } else { - this.runIt = true; - this.btnPause.Text = "Pause"; - this.toolStripStatusLabel1.Text = "Graphing"; + runIt = true; + btnPause.Text = "Pause"; + toolStripStatusLabel1.Text = "Graphing"; } } - private void btnClear_Click(object sender, EventArgs e) + private void BtnClear_Click(object sender, EventArgs e) { - this.currentPaintCommand = PaintCommand.clear; - this.toolStripStatusLabel2.Text = "Clear"; - this.panel4.Invalidate(); - this.panel4.Update(); + currentPaintCommand = PaintCommand.clear; + toolStripStatusLabel2.Text = "Clear"; + panel4.Invalidate(); + panel4.Update(); } + private void Panel4_Resize(object sender, EventArgs e) + { + rect = panel4.ClientRectangle; + } } }