Exemplo n.º 1
0
        private void GetValue(IEnumerable <LineSegment2D> lines, PointF endPoint, LineSegment2D[] previousLines, LineSegment2D?targetLine, ref LineSegment2D?nextLine)
        {
            const double minDistanceThreshold = 20;
            double       minDistanceToEnd     = double.MaxValue;

            nextLine = null;
            //targetPoint = null;
            foreach (var line in lines)
            {
                if (previousLines.Contains(line))
                {
                    continue;
                }

                if (line.P1 == targetLine.Value.P1 && line.P2 == targetLine.Value.P2)
                {
                    continue;
                }

                double dist1 = MathExtension.FindDistanceBetweenSegments(targetLine.Value.P1, targetLine.Value.P2, line.P1, line.P2);

                double minDistToEnd     = MathExtension.FindDistanceToSegment(endPoint, line.P1, line.P2);                         //.FindDistanceBetweenSegments(line.P1, line.P2, endLine.P1, endLine.P2);
                double currentDistToEnd = MathExtension.FindDistanceToSegment(endPoint, targetLine.Value.P1, targetLine.Value.P2); //.FindDistanceBetweenSegments(targetLine.Value.P1, targetLine.Value.P2, endLine.P1, endLine.P2);

                if (dist1 < minDistanceThreshold && minDistToEnd < currentDistToEnd && minDistToEnd < minDistanceToEnd)
                {
                    minDistanceToEnd = minDistToEnd;
                    nextLine         = line;
                }
            }
        }