Esempio n. 1
0
        private void SmoothFenceLine(Fence fence, int StartIdx, int Increment, int EndIdx)
        {
            // Smooth each a fence line, removing all points forming the apex of corners
            // smaller than MinimumRoadFenceAngle degrees. Preserve the start and end points.
            double brng;
            double DistA, DistB, DistC;

            // First, remove any vertices that are too close to each other and corners that are too sharp.
            int I = StartIdx;

            do
            {
                GeometryUtils.RectToPolar(fence[I - 1].X, fence[I - 1].Y, fence[I + 1].X, fence[I + 1].Y, out brng, out DistA);
                GeometryUtils.RectToPolar(fence[I].X, fence[I].Y, fence[I - 1].X, fence[I - 1].Y, out brng, out DistB);
                GeometryUtils.RectToPolar(fence[I].X, fence[I].Y, fence[I + 1].X, fence[I + 1].Y, out brng, out DistC);

                if (DistA < Epsilon || DistB < SmallEpsilon || DistC < SmallEpsilon ||
                    // Cosine rule
                    (DistB * DistB + DistC * DistC - DistA * DistA) / (2 * DistB * DistC) > Math.Cos(MinimumRoadFenceAngle * (Math.PI / 180)))
                {
                    fence.Points.RemoveAt(I);
                    if (Increment == 1)
                    {
                        EndIdx--;
                    }
                    if ((Increment == 1 && I > StartIdx) || (Increment == -1 && I > EndIdx))
                    {
                        I--;
                    }
                }
                else
                {
                    I += Increment;
                }
            } while (I != EndIdx);

            // Next: Apply polyline compression to the polyline to remove redundant vertices.
            fence.Compress(0.01); // Todo: DesignFilterBoundaryPolylineCompressionTolerance);
        }