Esempio n. 1
0
        void GetBezierApproximation()
        {
            int outputSegmentCount = 256;
            int s = 0;

            Points = new PointCollection();
            while (true)
            {
                var split = OrderedControlPoints.Where(item => item.LPath == s || item.RPath == s);
                if (split.Count() == 0)
                {
                    break;
                }
                var     controlPoints = split.Select(item => item.Point).ToList();
                Point[] points        = new Point[outputSegmentCount + 1];
                for (int i = 0; i <= outputSegmentCount; i++)
                {
                    double t = (double)i / outputSegmentCount;
                    points[i] = GetBezierPoint(t, controlPoints, 0, controlPoints.Count);
                }
                var polyline = new PolyLineSegment(points, true);
                foreach (var item in polyline.Points)
                {
                    Points.Add(item);
                }
                s++;
            }
        }
Esempio n. 2
0
        void OrderControlPoints()
        {
            if (OrderedControlPoints == null)
            {
                OrderedControlPoints = new List <Tuple>();
            }
            foreach (var item in ControlPoints)
            {
                if (OrderedControlPoints.Find(tuple => tuple.Point.Id == item.Id) != null)
                {
                    continue;
                }
                if (OrderedControlPoints.Count == 0)
                {
                    OrderedControlPoints.Add(new Tuple(0, 0, item));
                }
                else if (item.Point.X > OrderedControlPoints.Last().Point.Point.X)
                {
                    OrderedControlPoints.Add(new Tuple(0, 0, item));
                }
                else
                {
                    for (int i = 0; i < OrderedControlPoints.Count; i++)
                    {
                        if (item.Point.X < OrderedControlPoints[i].Point.Point.X)
                        {
                            OrderedControlPoints.Insert(i, new Tuple(0, 0, item));
                            break;
                        }
                    }
                }
            }
            int t = 0;

            foreach (var item in OrderedControlPoints)
            {
                if (EndPoints.Contains(item.Point))
                {
                    item.LPath = t;
                    t++;
                    item.RPath = t;
                }
                else
                {
                    item.LPath = t;
                    item.RPath = t;
                }
            }
        }