示例#1
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);
        }
示例#2
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);
        }