Beispiel #1
0
        public static Point[] sClipPolygonByRect(Point[] inArray, Rect clipRect)
        {
            if ((inArray == null) || (inArray.Length == 0))
            {
                return(null);
            }
            PolygonClipping clipping = new PolygonClipping();

            return(clipping.ClipPolygonByRect(inArray, clipRect));
        }
Beispiel #2
0
        protected PathFigure RenderNonStacked(Point[] pts, double origin, bool inverted, double optRadius, Rect cr)
        {
            PointCollection points = null;
            int             length = pts.Length;

            if (base.Smoothed && (length > 3))
            {
                points = new SplineNew(pts).CalculateCollection();
                length = pts.Length;
            }
            else if (!double.IsNaN(optRadius))
            {
                points = base.DecimateAsCollection(pts, optRadius);
                length = pts.Length;
            }
            else
            {
                points = new PointCollection();
                for (int i = 0; i < length; i++)
                {
                    points.Add(pts[i]);
                }
            }
            if (inverted)
            {
                points.Add(new Point(origin, pts[length - 1].Y));
                points.Add(new Point(origin, pts[0].Y));
            }
            else
            {
                points.Add(new Point(pts[length - 1].X, origin));
                points.Add(new Point(pts[0].X, origin));
            }
            points.Add(points[0]);
            if (!cr.IsEmptyRect())
            {
                Point[] inArray = new Point[points.Count];
                for (int j = 0; j < points.Count; j++)
                {
                    inArray[j] = points[j];
                }
                inArray = PolygonClipping.sClipPolygonByRect(inArray, cr);
                if (inArray == null)
                {
                    return(null);
                }
                points = Utils.ToCollection(inArray);
            }
            return(RenderSegment(points));
        }
Beispiel #3
0
        protected PathFigure[] RenderSegment(Point[] pts, double optRadius, Rect clip)
        {
            if ((pts == null) || (pts.Length == 0))
            {
                return(null);
            }
            if (Smoothed && (pts.Length > 3))
            {
                pts = new SplineNew(pts).Calculate();
            }
            else if (!double.IsNaN(optRadius))
            {
                pts = Decimate(pts, optRadius);
            }
            if (clip.IsEmptyRect())
            {
                PathFigure figure = new PathFigure();
                figure.StartPoint = pts[0];
                figure.IsClosed   = IsClosed;
                figure.IsFilled   = IsFilled;
                PolyLineSegment segment = new PolyLineSegment();
                segment.Points = pts.ToCollection();
                figure.Segments.Add(segment);
                return(new PathFigure[] { figure });
            }
            if (!IsClosed)
            {
                return(ClippingEngine.CreateClippedLines(pts, clip));
            }
            pts = PolygonClipping.sClipPolygonByRect(pts, clip);
            if ((pts == null) || (pts.Length <= 0))
            {
                return(null);
            }
            PathFigure figure2 = new PathFigure();

            figure2.StartPoint = pts[0];
            figure2.IsClosed   = IsClosed;
            figure2.IsFilled   = IsFilled;
            figure2.Segments   = new PathSegmentCollection();
            if (!IsFilled)
            {
                PathFigure[] figureArray = new PathFigure[pts.Length];
                PathFigure   figure4     = new PathFigure();
                figure4.StartPoint = pts[pts.Length - 1];
                figureArray[0]     = figure4;
                LineSegment segment3 = new LineSegment();
                segment3.Point = pts[0];
                figureArray[0].Segments.Add(segment3);
                for (int i = 1; i < figureArray.Length; i++)
                {
                    PathFigure figure3 = new PathFigure();
                    figure3.StartPoint = pts[i - 1];
                    figureArray[i]     = figure3;
                    LineSegment segment2 = new LineSegment();
                    segment2.Point = pts[i];
                    figureArray[i].Segments.Add(segment2);
                }
                return(figureArray);
            }
            PolyLineSegment segment4 = new PolyLineSegment();

            segment4.Points = pts.ToCollection();
            figure2.Segments.Add(segment4);
            return(new PathFigure[] { figure2 });
        }