Exemplo n.º 1
0
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            var endMovePoint = new Point(e.X, e.Y);

            if (_obiectInMove != null && _startMovePoint != null && _startMovePoint != new Point(-1, -1))
            {
                var xDelta = endMovePoint.X - _startMovePoint.X;
                var yDelta = endMovePoint.Y - _startMovePoint.Y;

                var obiect = _objects.First(o => o.Id == _obiectInMove.Id);

                var puncte = new List <Point>();

                obiect.Varfuri.ForEach(p =>
                {
                    puncte.Add(new Point(p.X + xDelta, p.Y + yDelta));
                });

                var puncteInitiale = new List <Point>();

                obiect.ObiectInitial.Varfuri.ForEach(p =>
                {
                    puncteInitiale.Add(new Point(p.X + xDelta, p.Y + yDelta));
                });

                obiect.Varfuri = puncte;
                obiect.ObiectInitial.Varfuri = puncteInitiale;

                GenerareExpandare(null, null);
                _obiectInMove = null;
            }

            _startMovePoint = new Point(-1, -1);
        }
Exemplo n.º 2
0
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            var punct = new System.Drawing.Point(((MouseEventArgs)e).X, ((MouseEventArgs)e).Y);

            if (!_inProgres)
            {
                if (_obiectInMove == null)
                {
                    _obiectInProgres      = new Obiect();
                    _linieInProgres       = new Linie();
                    _linieInProgres.Start = punct;

                    _initialPoint = punct;

                    if (checkBox1.Checked)
                    {
                        _drawUtils.DeseneazaVarf(punct, (int)numericUpDown1.Value);
                    }

                    _inProgres = true;
                    _obiectInProgres.Varfuri.Add(punct);
                }
            }
            else
            {
                if (!_isNearInitialPoint)
                {
                    _obiectInProgres.Varfuri.Add(punct);
                    _linieInProgres.End = punct;
                    _obiectInProgres.LiniiPerimetru.Add(new Linie(_linieInProgres));

                    _drawUtils.DeseneazaLinie(_linieInProgres);
                    if (checkBox1.Checked)
                    {
                        _drawUtils.DeseneazaVarf(punct, (int)numericUpDown1.Value);
                    }

                    _linieInProgres       = new Linie();
                    _linieInProgres.Start = punct;
                }
                else
                {
                    _linieInProgres.End = new System.Drawing.Point(_initialPoint.X, _initialPoint.Y);
                    _obiectInProgres.LiniiPerimetru.Add(new Linie(_linieInProgres));

                    //_obiectInProgres.CalculeazaPuncteInterioare(new Point(0, 0), new Point(pictureBox1.Width, pictureBox1.Height));
                    //_objects.Add(_obiectInProgres);

                    _drawUtils.DeseneazaLinie(_linieInProgres);
                    _drawUtils.ColoreazaInteriorObiect(_obiectInProgres, Color.Red, Brushes.Red);

                    _objects.Add(_obiectInProgres);
                    _obiectInProgres.ObiectInitial = new Obiect(_obiectInProgres);
                    _linieInProgres     = null;
                    _obiectInProgres    = null;
                    _inProgres          = false;
                    _isNearInitialPoint = false;
                }
            }
        }
Exemplo n.º 3
0
 private void button1_Click(object sender, EventArgs e)
 {
     _obiectInMove    = null;
     _obiectInProgres = null;
     _objects         = new List <Obiect>();
     _drawUtils.StergeObiecte();
     _inProgres      = false;
     _isMovingObject = false;
 }
Exemplo n.º 4
0
        public void Prime_Test_Throws_WronFormatException(dynamic x)
        {
            // Arrange
            string expected = "Invalid parameter";

            // Act
            Exception e = Assert.Throws <ArgumentException>(() => Obiect.Prime(x));

            // Assert
            Assert.Contains(expected, e.Message);
        }
Exemplo n.º 5
0
        public void Prime_MultipleTests_ExpectedTrue(int x)
        {
            // Arrange
            bool expected = true;

            // Act
            bool actual = Obiect.Prime(x);

            // Assert
            Assert.Equal(expected, actual);
        }
Exemplo n.º 6
0
        public void Prime_Test_FalseEpected()
        {
            // Arrange
            bool expected = true;

            // Act
            bool actual = Obiect.Prime(4);

            // Assert
            Assert.NotEqual(expected, actual);
        }
Exemplo n.º 7
0
        public void Prime_Test()
        {
            // Arrange
            bool expected = true;

            // Act
            bool actual = Obiect.Prime(3);

            // Assert
            Assert.Equal(expected, actual);
        }
Exemplo n.º 8
0
        private void pictureBox1_DoubleClick(object sender, EventArgs e)
        {
            if (_obiectInMove != null)
            {
                if (MessageBox.Show("Sunteți sigur că doriți ștergerea acestui obiect?", "Atenție", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    _objects.Remove(_obiectInMove);
                    _obiectInMove = null;

                    GenerareExpandare(null, null);
                }
            }
        }
Exemplo n.º 9
0
        public void ColoreazaInteriorObiect(Obiect obiect, Color color, Brush brush)
        {
            var myPath = new GraphicsPath(FillMode.Winding);

            Point[] points = new Point[obiect.Varfuri.Count];
            var     i      = 0;

            obiect.Varfuri.ForEach(p => points[i++] = p);
            myPath.AddPolygon(points);

            var myPen = new Pen(color, 2);

            //obiect.Puncte.ForEach(p => DeseneazaPunct(p, pen));

            _graphics.DrawPath(myPen, myPath);
            _graphics.FillPath(brush, myPath);
        }
Exemplo n.º 10
0
        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (_inProgres && _initialPoint != null)
            {
                if (e.X < _initialPoint.X + 8 && e.X > _initialPoint.X - 8 &&
                    e.Y < _initialPoint.Y + 8 && e.Y > _initialPoint.Y - 8)
                {
                    _isNearInitialPoint = true;
                    Cursor.Current      = Cursors.Hand;
                }
                else
                {
                    _isNearInitialPoint = false;
                    Cursor.Current      = Cursors.Default;
                }
            }
            else if (!_inProgres)
            {
                var point    = new Point(e.X, e.Y);
                var isObject = false;
                foreach (var obiect in _objects)
                {
                    if (obiect.ContinePunct(point))
                    {
                        _obiectInMove = obiect;
                        isObject      = true;
                        break;
                    }
                }

                if (isObject)
                {
                    Cursor.Current = Cursors.UpArrow;
                }
                else
                {
                    if (!_isMovingObject)
                    {
                        _obiectInMove  = null;
                        Cursor.Current = Cursors.Default;
                    }
                }
            }
        }
Exemplo n.º 11
0
        public void ExpandareUniforma(Obiect obiect, decimal size, int colturi, bool corectareConcavitate)
        {
            if (corectareConcavitate)
            {
                obiect.Uniformizare();
            }
            else
            {
                obiect.UndoUniformizare();
            }

            var joinType = JoinType.Miter;

            switch (colturi)
            {
            case 1: joinType = JoinType.Miter;
                break;

            case 2: joinType = JoinType.Round;
                break;

            case 3: joinType = JoinType.Square;
                break;
            }

            var myObject = ClipperOffset.OffsetPaths(new List <List <Point> >()
            {
                obiect.Varfuri
            }, (double)size, joinType, EndType.Polygon).First();

            var expandedPath = new GraphicsPath(FillMode.Winding);
            var actualPath   = new GraphicsPath(FillMode.Winding);
            var originalPath = new GraphicsPath(FillMode.Winding);

            Point[] originalPoints = new Point[obiect.ObiectInitial.Varfuri.Count];
            Point[] actualPoints   = new Point[obiect.Varfuri.Count];
            Point[] expandedPoints = new Point[myObject.Count];

            var originalCount = 0;

            obiect.ObiectInitial.Varfuri.ForEach(p => originalPoints[originalCount++] = p);
            originalPath.AddPolygon(originalPoints);

            var actualCount = 0;

            obiect.Varfuri.ForEach(p => actualPoints[actualCount++] = p);
            actualPath.AddPolygon(actualPoints);

            var expandedCount = 0;

            myObject.ForEach(p => expandedPoints[expandedCount++] = p);
            expandedPath.AddPolygon(expandedPoints);

            if (joinType == JoinType.Miter)
            {
                var myPen = new Pen(Color.Green, (int)size * 2);
                _graphics.DrawPolygon(myPen, actualPoints);
            }
            else
            {
                _graphics.FillPath(Brushes.Green, expandedPath);
            }

            _graphics.FillPath(Brushes.Yellow, actualPath);
            _graphics.FillPath(Brushes.Red, originalPath);
        }
Exemplo n.º 12
0
        public void ExpandareNeuniforma(Obiect obiect, decimal sizeSus, decimal sizeDreapta, decimal sizeStanga, decimal sizeJos, int colturi, bool corectareConcavitate)
        {
            var size = ((int)sizeDreapta + (int)sizeStanga) / 2;

            if (corectareConcavitate)
            {
                obiect.Uniformizare();
            }
            else
            {
                obiect.UndoUniformizare();
            }

            var joinType = JoinType.Miter;

            switch (colturi)
            {
            case 1:
                joinType = JoinType.Miter;
                break;

            case 2:
                joinType = JoinType.Round;
                break;

            case 3:
                joinType = JoinType.Square;
                break;
            }

            var myObject = ClipperOffset.OffsetPaths(new List <List <Point> >()
            {
                obiect.Varfuri
            }, (double)size, joinType, EndType.Polygon).First();

            var xMove = (sizeDreapta + sizeStanga) / 2 - sizeDreapta;
            var yMove = (sizeSus + sizeJos) / 2 - sizeSus;

            var expandedPath = new GraphicsPath(FillMode.Winding);
            var actualPath   = new GraphicsPath(FillMode.Winding);
            var originalPath = new GraphicsPath(FillMode.Winding);

            Point[] expandedPoints = new Point[myObject.Count];
            Point[] actualPoints   = new Point[obiect.Varfuri.Count];
            Point[] originalPoints = new Point[obiect.ObiectInitial.Varfuri.Count];

            var actualCount = 0;

            obiect.Varfuri.ForEach(p =>
            {
                actualPoints[actualCount++] = p;
            });
            actualPath.AddPolygon(actualPoints);

            var originalCount = 0;

            obiect.ObiectInitial.Varfuri.ForEach(p => originalPoints[originalCount++] = p);
            originalPath.AddPolygon(originalPoints);

            var expandedCount = 0;

            //var myPen = new Pen(Color.Green, size);

            if (joinType == JoinType.Miter)
            {
                obiect.Varfuri.ForEach(p => expandedPoints[expandedCount++] = new Point(p.X - (int)xMove, p.Y + (int)yMove));

                var myPen = new Pen(Color.Green, (int)size * 2);
                _graphics.DrawPolygon(myPen, expandedPoints);
            }
            else
            {
                myObject.ForEach(p => expandedPoints[expandedCount++] = new Point(p.X - (int)xMove, p.Y + (int)yMove));
                expandedPath.AddPolygon(expandedPoints);

                _graphics.FillPath(Brushes.Green, expandedPath);
            }

            //_graphics.DrawPath(myPen, expandedPath);
            _graphics.FillPath(Brushes.Yellow, actualPath);
            _graphics.FillPath(Brushes.Red, originalPath);
        }