Exemplo n.º 1
0
        private IEnumerable <CurveCrossingInfo> FilterCrossInfos(IEnumerable <CurveCrossingInfo> crossInfos, out IEnumerable <CurveCrossingInfo> duplicateEntities)
        {
            duplicateEntities = new List <CurveCrossingInfo>();
            var result = new List <CurveCrossingInfo>();

            foreach (var curveCrossingInfo in crossInfos)
            {
                // Filter out duplicate entities
                if (AreDuplicateEntities(curveCrossingInfo))
                {
                    ((List <CurveCrossingInfo>)duplicateEntities).Add(curveCrossingInfo);
                    continue;
                }

                var sourcePoints = CurveUtils.GetCurveEndPoints(curveCrossingInfo.SourceId, _transaction);
                var targetPoints = new Point3d[0];
                if (curveCrossingInfo.TargetId != curveCrossingInfo.SourceId)
                {
                    targetPoints = CurveUtils.GetCurveEndPoints(curveCrossingInfo.TargetId, _transaction);
                }
                sourcePoints = DistinctEndPoints(sourcePoints);
                targetPoints = DistinctEndPoints(targetPoints);

                var points = new List <Point3d>();
                foreach (var point3D in curveCrossingInfo.IntersectPoints)
                {
                    // Whether point3D is end point of each cuve

                    //// If sourcePoints.Length is 1 or 0, means it's a loop, loop need to be splitted.
                    //if (sourcePoints.Length >= 2 && sourcePoints.Contains(point3D) &&
                    //    targetPoints.Length >= 2 && targetPoints.Contains(point3D))
                    //    continue;

                    // If curveCrossingInfo.SourceId == curveCrossingInfo.TargetId, it's a self intersection.
                    if (sourcePoints.Contains(point3D) && targetPoints.Contains(point3D) &&
                        curveCrossingInfo.SourceId != curveCrossingInfo.TargetId)
                    {
                        continue;
                    }

                    points.Add(point3D);
                }
                if (points.Count > 0)
                {
                    var newCrossingInfo = new CurveCrossingInfo(curveCrossingInfo.SourceId, curveCrossingInfo.TargetId,
                                                                points.ToArray());
                    result.Add(newCrossingInfo);
                }
            }
            return(result);
        }