Example #1
0
		public StrokeSegment[] GetSimplifiedSegments (int startIndex, float error, int maxSegments)
		{
			var bb = BoundingBox;
			var points = Points;

			if (startIndex == 0) {
				startIndex = RemoveInitialFlourish ();
			}

			var totalSegment = new StrokeSegment (this, startIndex, points.Length - 1);

			var segments = new List<StrokeSegment> { totalSegment };

			//
			// Subdivide
			//
			for (;;) {
				//
				// Find the next to split
				//
				int segToSplit = -1;
				int pointToSplit = -1;
				float pointDist = 0;

				for (var i = 0; i < segments.Count; i++) {

					float d;
					var j = segments [i].GetFarthestInteriorPoint (out d);
					if (j >= 0 && (segToSplit == -1 || d > pointDist)) {
						segToSplit = i;
						pointToSplit = j;
						pointDist = d;
					}

				}

				//
				// Split it
				//
				var shouldSplit = segToSplit >= 0 &&
				                  segments.Count < maxSegments &&
				                  pointDist > error;

				if (shouldSplit) {
					var lastIndex = segments [segToSplit].EndIndex;
					segments [segToSplit].EndIndex = pointToSplit;
					segments.Insert (segToSplit + 1, new StrokeSegment (this, pointToSplit, lastIndex));
				}
				else {
					break;
				}
			}

			return segments.ToArray ();
		}
Example #2
0
        public StrokeSegment[] GetSimplifiedSegments(int startIndex, float error, int maxSegments)
        {
            var bb     = BoundingBox;
            var points = Points;

            if (startIndex == 0)
            {
                startIndex = RemoveInitialFlourish();
            }

            var totalSegment = new StrokeSegment(this, startIndex, points.Length - 1);

            var segments = new List <StrokeSegment> {
                totalSegment
            };

            //
            // Subdivide
            //
            for (;;)
            {
                //
                // Find the next to split
                //
                int   segToSplit   = -1;
                int   pointToSplit = -1;
                float pointDist    = 0;

                for (var i = 0; i < segments.Count; i++)
                {
                    float d;
                    var   j = segments [i].GetFarthestInteriorPoint(out d);
                    if (j >= 0 && (segToSplit == -1 || d > pointDist))
                    {
                        segToSplit   = i;
                        pointToSplit = j;
                        pointDist    = d;
                    }
                }

                //
                // Split it
                //
                var shouldSplit = segToSplit >= 0 &&
                                  segments.Count <maxSegments &&
                                                  pointDist> error;

                if (shouldSplit)
                {
                    var lastIndex = segments [segToSplit].EndIndex;
                    segments [segToSplit].EndIndex = pointToSplit;
                    segments.Insert(segToSplit + 1, new StrokeSegment(this, pointToSplit, lastIndex));
                }
                else
                {
                    break;
                }
            }

            return(segments.ToArray());
        }