예제 #1
0
            private int CreateFlatEnds([NotNull] NeighboredSegmentsSubpart segmentsSubpartx,
                                       double rowDistance,
                                       [NotNull] Dictionary <FeaturePoint, SegmentInfo> flatEnds,
                                       [NotNull] ContinuationFinder continuationFinder,
                                       bool atStart)
            {
                var              errorCount = 0;
                double           sumLength  = 0;
                SegmentProxyInfo first      = null;

                foreach (SegmentProxyInfo info in
                         GetSegmentProxies(segmentsSubpartx, continuationFinder, atStart))
                {
                    first = first ?? info;

                    var segmentPartKey = new SegmentPart(info.SegmentProxy, 0, 1, complete: true);
                    NeighboredSegmentsSubpart segmentsSubpart = info.Subpart;

                    SegmentParts neighboredParts;
                    segmentsSubpart.SegmentNeighbors.TryGetValue(segmentPartKey,
                                                                 out neighboredParts);

                    var featurePointKey =
                        new FeaturePoint(
                            segmentsSubpart.BaseFeature, segmentsSubpart.TableIndex,
                            segmentPartKey.PartIndex, segmentPartKey.SegmentIndex);

                    SegmentInfo segmentInfo;
                    if (!flatEnds.TryGetValue(featurePointKey, out segmentInfo))
                    {
                        // TODO revise: neighboredParts can be null here, but SegmentInfo property is later expected to be NotNull
                        segmentInfo = new SegmentInfo(neighboredParts);
                        flatEnds.Add(featurePointKey, segmentInfo);
                    }

                    if (atStart)
                    {
                        segmentInfo.FlatStart = true;
                    }
                    else
                    {
                        segmentInfo.FlatEnd = true;
                    }

                    if (info != first)
                    {
                        errorCount += VerifyAngle(first, info, rowDistance, segmentsSubpart);
                    }

                    sumLength += info.SegmentProxy.Length;
                    if (sumLength >= rowDistance)
                    {
                        break;
                    }
                }

                return(errorCount);
            }
예제 #2
0
            public void AdaptLineEnds(
                [NotNull] Dictionary <FeaturePoint, List <NeighboredSegmentsSubpart> > splittedParts,
                [NotNull] ContinuationFinder continuationFinder, out int errorCount)
            {
                Dictionary <FeaturePoint, SegmentInfo> flatEnds =
                    GetFlatEnds(splittedParts, continuationFinder, out errorCount);

                RecalcFlatEnds(flatEnds, splittedParts);

                Drop0LengthParts(EnumSegmentParts(splittedParts.Values));
            }
예제 #3
0
            private bool HandleAsFlat(NeighboredSegmentsSubpart segmentPart,
                                      double fullFraction,
                                      ContinuationFinder continuationFinder)
            {
                var p = new FeaturePoint(segmentPart.BaseFeature, segmentPart.TableIndex,
                                         segmentPart.PartIndex, fullFraction);

                List <NeighboredSegmentsSubpart> continuations =
                    continuationFinder.GetContinuations(p, new List <SegmentsSubpart>(), false);

                if (continuations == null)
                {
                    return(AdaptUnconnected);
                }

                var junctionSegments = new List <NeighboredSegmentsSubpart>();

                foreach (NeighboredSegmentsSubpart continuation in continuations)
                {
                    if (p.Feature == continuation.BaseFeature &&
                        p.TableIndex == continuation.TableIndex &&
                        p.Part == continuation.PartIndex &&
                        Math.Abs(p.FullFraction - continuation.FullStartFraction) < 0.01)
                    {
                        junctionSegments.Add(continuation);
                        continue;
                    }

                    if (NotReportedCondition != null &&
                        NotReportedCondition.IsFulfilled(segmentPart.BaseFeature,
                                                         segmentPart.TableIndex,
                                                         continuation.BaseFeature,
                                                         continuation.TableIndex))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(JunctionIsEndExpression))
                    {
                        return(false);
                    }

                    junctionSegments.Add(continuation);
                }

                if (junctionSegments.Count > 0)
                {
                    var rule = new QaConnectionRule(new[] { junctionSegments[0].BaseFeature.Table },
                                                    new List <string> {
                        JunctionIsEndExpression
                    });
                    TableView[] tableFilterHelpers;
                    IList <QaConnectionRuleHelper> helpers = QaConnectionRuleHelper.CreateList(
                        new[] { rule },
                        out
                        tableFilterHelpers);

                    foreach (NeighboredSegmentsSubpart junctionSegment in junctionSegments)
                    {
                        int tableIndex = junctionSegment.TableIndex;

                        TableView baseHelper = tableFilterHelpers[tableIndex];

                        DataRow helperRow = baseHelper.Add(junctionSegment.BaseFeature);
                        Assert.NotNull(helperRow, "no row returned");

                        {
                            helperRow[QaConnections.StartsIn] = segmentPart.FullStartFraction <
                                                                segmentPart.FullEndFraction;
                        }
                    }

                    foreach (QaConnectionRuleHelper ruleHelper in helpers)
                    {
                        // check if all rows comply to the current rule
                        int connectedElementsCount = junctionSegments.Count;
                        var matchingRowsCount      = 0;
                        for (var tableIndex = 0; tableIndex < 1; tableIndex++)
                        {
                            matchingRowsCount += ruleHelper
                                                 .MainRuleFilterHelpers[tableIndex]
                                                 .FilteredRowCount;
                        }

                        Assert.True(matchingRowsCount <= connectedElementsCount,
                                    "Unexpected matching rows count: {0}; total connected rows: {1}",
                                    matchingRowsCount, connectedElementsCount);

                        if (matchingRowsCount == connectedElementsCount &&
                            ruleHelper.VerifyCountRules())
                        {
                            // all rows comply to the current rule,
                            // so one rule if fulfilled and no further checking needed
                            return(true);
                        }
                    }
                }

                return(AdaptUnconnected);
            }
예제 #4
0
            private IEnumerable <SegmentProxyInfo> GetSegmentProxies(
                [NotNull] NeighboredSegmentsSubpart segmentsSubpart,
                [NotNull] ContinuationFinder continuationFinder,
                bool atStart)
            {
                FeaturePoint continuationKey;

                if (atStart)
                {
                    for (int iSegment = segmentsSubpart.FullMinFraction;
                         iSegment < segmentsSubpart.FullMaxFraction;
                         iSegment++)
                    {
                        yield return(GetSegmentproxyInfo(segmentsSubpart, iSegment));
                    }

                    continuationKey = new FeaturePoint(segmentsSubpart.BaseFeature,
                                                       segmentsSubpart.TableIndex,
                                                       segmentsSubpart.PartIndex,
                                                       segmentsSubpart.FullMaxFraction);
                }
                else
                {
                    for (int iSegment = segmentsSubpart.FullMaxFraction - 1;
                         iSegment >= segmentsSubpart.FullMinFraction;
                         iSegment--)
                    {
                        yield return(GetSegmentproxyInfo(segmentsSubpart, iSegment));
                    }

                    continuationKey = new FeaturePoint(segmentsSubpart.BaseFeature,
                                                       segmentsSubpart.TableIndex,
                                                       segmentsSubpart.PartIndex,
                                                       segmentsSubpart.FullMinFraction);
                }

                List <NeighboredSegmentsSubpart> continuations =
                    continuationFinder.GetContinuations(continuationKey,
                                                        new List <SegmentsSubpart>(), false);

                if (continuations == null)
                {
                    yield break;
                }

                foreach (NeighboredSegmentsSubpart continuation in continuations)
                {
                    if (continuation.BaseFeature.OID != segmentsSubpart.BaseFeature.OID ||
                        continuation.TableIndex != segmentsSubpart.TableIndex ||
                        continuation.PartIndex != segmentsSubpart.PartIndex)
                    {
                        continue;
                    }

                    if (atStart &&
                        continuation.FullMinFraction != segmentsSubpart.FullMaxFraction)
                    {
                        continue;
                    }

                    if (!atStart &&
                        continuation.FullMaxFraction != segmentsSubpart.FullMinFraction)
                    {
                        continue;
                    }

                    foreach (
                        SegmentProxyInfo segmentProxy in
                        GetSegmentProxies(continuation, continuationFinder, atStart))
                    {
                        yield return(segmentProxy);
                    }
                }
            }
예제 #5
0
            private Dictionary <FeaturePoint, SegmentInfo> GetFlatEnds(
                [NotNull] Dictionary <FeaturePoint, List <NeighboredSegmentsSubpart> > splittedParts,
                [NotNull] ContinuationFinder continuationFinder, out int errorCount)
            {
                errorCount = 0;
                var flatEnds =
                    new Dictionary <FeaturePoint, SegmentInfo>(new FeaturePointComparer());

                foreach (
                    KeyValuePair <FeaturePoint, List <NeighboredSegmentsSubpart> > splitted in
                    splittedParts)
                {
                    foreach (NeighboredSegmentsSubpart segmentsSubpart in splitted.Value)
                    {
                        foreach (
                            KeyValuePair <SegmentPart, SegmentParts> neighboredSegmentPart in
                            segmentsSubpart.SegmentNeighbors)
                        {
                            SegmentPart key = neighboredSegmentPart.Key;
                            if (key.SegmentIndex > 0 &&
                                key.SegmentIndex < segmentsSubpart.FullMaxFraction - 1)
                            {
                                continue;
                            }

                            var flatStart = false;
                            var flatEnd   = false;
                            foreach (SegmentPart segmentPart in neighboredSegmentPart.Value)
                            {
                                if (!flatStart && segmentPart.FullMin <= 0)
                                {
                                    flatStart = HandleAsFlat(segmentsSubpart, segmentPart.FullMin,
                                                             continuationFinder);
                                }

                                if (!flatEnd && segmentPart.FullMax >=
                                    segmentsSubpart.FullMaxFraction)
                                {
                                    flatEnd = HandleAsFlat(segmentsSubpart, segmentPart.FullMax,
                                                           continuationFinder);
                                }
                            }

                            if (flatStart || flatEnd)
                            {
                                IFeatureRowsDistance rowsDistance =
                                    NearDistanceProvider.GetRowsDistance(splitted.Key.Feature,
                                                                         splitted.Key.TableIndex);
                                double rowDistance = rowsDistance.GetRowDistance();

                                if (flatStart)
                                {
                                    errorCount += CreateFlatEnds(
                                        segmentsSubpart, rowDistance, flatEnds, continuationFinder,
                                        atStart: true);
                                }

                                if (flatEnd)
                                {
                                    errorCount += CreateFlatEnds(
                                        segmentsSubpart, rowDistance, flatEnds, continuationFinder,
                                        atStart: false);
                                }

                                if (flatStart && flatEnd)
                                {
                                    double sumLength = 0;
                                    double limit     = 2 * rowDistance;
                                    foreach (SegmentProxy segmentProxy in segmentsSubpart
                                             .GetSegments())
                                    {
                                        sumLength += segmentProxy.Length;
                                        if (sumLength > limit)
                                        {
                                            break;
                                        }
                                    }

                                    if (sumLength < limit && ReportShortSubpartError != null)
                                    {
                                        errorCount += ReportShortSubpartError(
                                            new ShortSubpartError(
                                                segmentsSubpart, sumLength, limit));
                                    }
                                }
                            }
                        }
                    }
                }

                return(flatEnds);
            }