示例#1
0
        public void MiscellaneousLine(int size, short[] points, float exA, float exB, float exC)
        {
            MockPixelGrid pixelGrid = new MockPixelGrid(size, points);
            float         a, b, c;

            LinearRegression.CalculateLineEquation(pixelGrid, 0, 0, pixelGrid.Width, pixelGrid.Height,
                                                   out a, out b, out c);

            MathHelper.NormalizeCoefficientsWithRespectToA(ref a, ref b, ref c);
            TestHelper.AssertABC(a, b, c, exA, exB, exC);
        }
示例#2
0
        public void SquarePixelPatternGivesIndeterminateLine(int size, short[] points)
        {
            MockPixelGrid pixelGrid = new MockPixelGrid(size, points);
            float         a, b, c;

            LinearRegression.CalculateLineEquation(pixelGrid, 0, 0, pixelGrid.Width, pixelGrid.Height,
                                                   out a, out b, out c);
            Assert.IsTrue(float.IsNaN(a), MathHelper.CoeffecientsToString("Expected NaN for a, b and c, but got ", a, b, c));
            Assert.IsTrue(float.IsNaN(b), MathHelper.CoeffecientsToString("Expected NaN for a, b and c, but got ", a, b, c));
            Assert.IsTrue(float.IsNaN(c), MathHelper.CoeffecientsToString("Expected NaN for a, b and c, but got ", a, b, c));
        }
示例#3
0
        public void DiagonalLine(int size, short[] points, float expectedC)
        {
            MockPixelGrid pixelGrid = new MockPixelGrid(size, points);
            float         a, b, c;

            LinearRegression.CalculateLineEquation(pixelGrid, 0, 0, pixelGrid.Width, pixelGrid.Height,
                                                   out a, out b, out c);

            MathHelper.NormalizeCoefficientsWithRespectToA(ref a, ref b, ref c);
            TestHelper.AssertABC(a, b, c, MathHelper.SQRT2DIV2, -MathHelper.SQRT2DIV2, expectedC);
        }
        private void drawLineButton_Click(object sender, EventArgs e)
        {
            float     a, b, c;
            PixelGrid pixelGrid = pixelGridUserControl.PixelCells;
            int       width     = pixelGrid.Width;
            int       height    = pixelGrid.Height;

            LinearRegression.CalculateLineEquation(pixelGrid, 0, 0, width, height,
                                                   out a, out b, out c);

            eqnATextBox.Text = a.ToString("G7");
            eqnBTextBox.Text = b.ToString("G7");
            eqnCTextBox.Text = c.ToString("G7");

            if (!float.IsNaN(a) && !float.IsNaN(b) && !float.IsNaN(c))
            {
                pixelGridUserControl.DrawLine(a, b, c);
            }
            else
            {
                pixelGridUserControl.MakeLineInvalid();
            }
        }