示例#1
0
        public void TestBoundingBoxBezierRectangle()
        {
            var curve = new BezierTestData {
                Matrix = new Matrix {
                    OffsetX = 50, OffsetY = offsetY
                }
            }
            .RoundedRectBezier;

            ReportPainter.PushPaint(c => {
                c.SetLineWidth(1);
                var bb = BezierExtensions.BezierBoundingBox(curve);
                c.SetColor(Colors.SpringGreen);
                c.Rectangle(bb);
                c.Stroke();

                c.SetColor(Colors.Blue);
                c.SetLineWidth(2);
                ContextPainterExtensions.DrawBezier(c, curve);
                c.Stroke();
            });

            WritePainter();

            offsetY += 200;
        }
示例#2
0
        public void TestBezierRectJitterAndOffset()
        {
            var jitter = 5d;
            var rect   = new Rectangle(0, 0, 400, 100);

            Action prove = () => {
                var shape = new BezierRectangleShape(rect)
                {
                    Jitter = jitter
                };

                var bb = BezierExtensions.BezierBoundingBox(shape.BezierPoints);

                var offset = bb.Size - rect.Size;

                ReportDetail("{0} {1} W={2:0.####} H={3}", rect, jitter, offset.Width, offset.Height);
            };

            ReportDetail("************* same jitter, rect growing");
            for (int i = 100; i < 10000; i += 100)
            {
                rect = new Rectangle(0, 0, i * 3, i);
                prove();
            }
            ReportDetail("************* same rect, jitter growing");
            rect = new Rectangle(0, 0, 400, 100);
            for (int i = 1; i < rect.Size.Height; i += 5)
            {
                jitter = i;
                prove();
            }
        }
示例#3
0
        private IList <Point> BezierHull0(IList <Point> bezier)
        {
            var cps = BezierExtensions.ControlPoints(bezier);

            var hull = PolyAlgoPrototyper.AndrewsMonotonChainHullSSF(cps, false);

            if (hull[0] != bezier[0])
            {
                var extend = new Point[hull.Length + 2];
                Array.Copy(hull, 0, extend, 1, hull.Length);
                extend[0] = bezier[0];
                extend[extend.Length - 1] = bezier[bezier.Count - 1];
                hull = extend;
            }
            return(hull);
        }
示例#4
0
        private void PaintSegments(IList <Point> curve)
        {
            var segments = BezierExtensions.BezierSegments(curve);
            var cols     = new Color[] {
                Colors.Blue,
                Colors.Red,
                Colors.BlueViolet,
                Colors.OrangeRed,
                Colors.AliceBlue,
                Colors.Orange,
                Colors.Aquamarine,
                Colors.DodgerBlue
            };


            ReportPainter.PushPaint(c => {
                var iCol = 0;
                foreach (var seg in segments)
                {
                    c.SetLineWidth(1);
                    var bb = BezierExtensions.BezierBoundingBox(seg.Start, seg.Cp1, seg.Cp2, seg.End);
                    c.SetColor(Colors.SpringGreen);
                    c.Rectangle(bb);
                    c.Stroke();

                    c.SetColor(cols[iCol++]);
                    c.SetLineWidth(2);
                    ContextPainterExtensions.DrawBezier(c, seg);
                    c.Stroke();

                    var med = BezierExtensions.BezierPoint(seg.Start, seg.Cp1, seg.Cp2, seg.End, .5);
                    c.SetColor(Colors.DarkGray);
                    c.Arc(med.X, med.Y, 5, 0, 360);
                    c.Stroke();
                }
            });

            WritePainter();
        }
示例#5
0
        public void TestBezierHull(IList <Point> bezier)
        {
            base.ReportPainter.PushPaint(c => {
                c.SetColor(Colors.Blue);
                c.SetLineWidth(2);
                ContextPainterExtensions.DrawBezier(c, bezier);
                c.Stroke();
            });

            var cps = BezierExtensions.ControlPoints(bezier);

            base.ReportPainter.PushPaint(c => {
                c.SetColor(Colors.Red);
                c.SetLineWidth(1);
                foreach (var p in cps)
                {
                    c.Arc(p.X, p.Y, 5, 0, 360);
                    c.Stroke();
                }
                ;
            });

            var hull = BezierExtensions.BezierHull(bezier);

            base.ReportPainter.PushPaint(c => {
                c.SetColor(Colors.Green);
                c.SetLineWidth(1);
                foreach (var p in hull)
                {
                    c.Arc(p.X, p.Y, 3, 0, 360);
                    c.Fill();
                }
                ContextPainterExtensions.DrawPoligon(c, hull);
                c.Stroke();
            });
            WritePainter();
        }