Exemple #1
0
 /// <summary>
 /// Remove the segs in the section of the line.
 /// </summary>
 /// <param name="line"></param>
 /// <param name="start"></param>
 /// <param name="end"></param>
 private void Remove(TaggedLineString line, int start, int end)
 {
     for (int i = start; i < end; i++)
     {
         TaggedLineSegment seg = line.GetSegment(i);
         _inputIndex.Remove(seg);
     }
 }
Exemple #2
0
        private void SimplifySection(int i, int j, int depth)
        {
            depth += 1;
            int[] sectionIndex = new int[2];
            if ((i + 1) == j)
            {
                LineSegment newSeg = _line.GetSegment(i);
                _line.AddToResult(newSeg);
                // leave this segment in the input index, for efficiency
                return;
            }

            bool isValidToSimplify = true;

            /**
             * Following logic ensures that there is enough points in the output line.
             * If there is already more points than the minimum, there's nothing to check.
             * Otherwise, if in the worst case there wouldn't be enough points,
             * don't flatten this segment (which avoids the worst case scenario)
             */
            if (_line.ResultSize < _line.MinimumSize)
            {
                int worstCaseSize = depth + 1;
                if (worstCaseSize < _line.MinimumSize)
                {
                    isValidToSimplify = false;
                }
            }

            double[] distance        = new double[1];
            int      furthestPtIndex = FindFurthestPoint(_linePts, i, j, distance);

            // flattening must be less than distanceTolerance
            if (distance[0] > _distanceTolerance)
            {
                isValidToSimplify = false;
            }
            // test if flattened section would cause intersection
            LineSegment candidateSeg = new LineSegment();

            candidateSeg.P0 = _linePts[i];
            candidateSeg.P1 = _linePts[j];
            sectionIndex[0] = i;
            sectionIndex[1] = j;
            if (HasBadIntersection(_line, sectionIndex, candidateSeg))
            {
                isValidToSimplify = false;
            }

            if (isValidToSimplify)
            {
                LineSegment newSeg = Flatten(i, j);
                _line.AddToResult(newSeg);
                return;
            }
            SimplifySection(i, furthestPtIndex, depth);
            SimplifySection(furthestPtIndex, j, depth);
        }