コード例 #1
0
        /// <summary>
        /// Finds all intersections between the specified line segments, using a brute force
        /// algorithm and given the specified epsilon for coordinate comparisons.</summary>
        /// <param name="lines">
        /// An <see cref="Array"/> containing the <see cref="LineD"/> instances to intersect.
        /// </param>
        /// <param name="epsilon">
        /// The maximum absolute difference at which two coordinates should be considered equal.
        /// </param>
        /// <returns>
        /// A lexicographically sorted <see cref="Array"/> containing a <see cref="MultiLinePoint"/>
        /// for every point of intersection between the <paramref name="lines"/>.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="lines"/> is a null reference.</exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="epsilon"/> is equal to or less than zero.</exception>
        /// <remarks>
        /// <b>FindSimple</b> is identical with the basic <see cref="FindSimple(LineD[])"/> overload
        /// but uses the specified <paramref name="epsilon"/> to determine intersections between the
        /// specified <paramref name="lines"/> and to combine nearby intersections.</remarks>

        public static MultiLinePoint[] FindSimple(LineD[] lines, double epsilon)
        {
            if (lines == null)
            {
                ThrowHelper.ThrowArgumentNullException("lines");
            }
            if (epsilon <= 0.0)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException(
                    "epsilon", epsilon, Strings.ArgumentNotPositive);
            }

            var crossings = new BraidedTree <PointD, EventPoint>(
                (a, b) => PointDComparerY.CompareEpsilon(a, b, epsilon));

            for (int i = 0; i < lines.Length - 1; i++)
            {
                for (int j = i + 1; j < lines.Length; j++)
                {
                    var crossing = lines[i].Intersect(lines[j], epsilon);

                    if (crossing.Exists)
                    {
                        PointD p = crossing.Shared.Value;
                        BraidedTreeNode <PointD, EventPoint> node;
                        crossings.TryAddNode(p, new EventPoint(p), out node);
                        node._value.TryAddLines(i, crossing.First, j, crossing.Second);
                    }
                }
            }

            return(EventPoint.Convert(crossings.Values));
        }