コード例 #1
0
        /// <summary>
        /// Smooths the provided vertexsequence. Will iterate round all the vertices in the contour
        /// and will average out vertex positions based on thepositions of its neighbours. This will
        /// smooth out the edges of the contour and remove sharp angles.
        /// </summary>
        /// <param name="vs">The vertex sequence to smooth</param>
        private void SmoothContour(VertexSequence vs)
        {
            VertexSequence smooth = new VertexSequence();

            for (int i = 0; i < vs.Count; i++)
            {
                float x = 0;
                float y = 0;
                int   w = 0;
                for (int j = -m_smoothWeights.Length / 2; j <= m_smoothWeights.Length / 2; j++)
                {
                    x += vs[i + j].x * m_smoothWeights[j + (m_smoothWeights.Length / 2)];
                    y += vs[i + j].y * m_smoothWeights[j + (m_smoothWeights.Length / 2)];
                    w += m_smoothWeights[j + (m_smoothWeights.Length / 2)];
                }
                x /= w;
                y /= w;
                smooth.Add(new Vector2()
                {
                    x = x, y = y
                });
            }

            vs.CopyFrom(smooth);
        }