public void CoverSegment(LineSegment lineSegment, Tesselation.SegmentCellCovered markedDirection, Cell cell) { switch (markedDirection) { case Tesselation.SegmentCellCovered.Left: lock (locker) { LeftCellsVisited[lineSegment.IdOnSource] = true; if (RightCellsVisited[lineSegment.IdOnSource] && cell != null && SegmentToCellMap[lineSegment.IdOnSource] != null) { SegmentToCellMap[lineSegment.IdOnSource].PairCellsByNeighbor(lineSegment, cell); } else { SegmentToCellMap[lineSegment.IdOnSource] = cell; } } break; case Tesselation.SegmentCellCovered.Right: lock (locker) { RightCellsVisited[lineSegment.IdOnSource] = true; if (LeftCellsVisited[lineSegment.IdOnSource] && cell != null && SegmentToCellMap[lineSegment.IdOnSource] != null) { SegmentToCellMap[lineSegment.IdOnSource].PairCellsByNeighbor(lineSegment, cell); } else { SegmentToCellMap[lineSegment.IdOnSource] = cell; } } break; } }
/// <summary> /// Gets the correct neighbor for a segment /// </summary> /// <param name="seg"></param> /// <param name="dir"></param> /// <returns></returns> public IEnumerable <LineSegment> GetSegmentNeighbors(LineSegment inSeg, Tesselation.SegmentCellCovered dir = Tesselation.SegmentCellCovered.Both) { var posLexProg = inSeg.IsPositiveLexicographicProgress(); //get neighboring segments var adjSegments = this[inSeg.SecondIntersection.Id].GetSegmentsFromLine(inSeg.Source) .Where(s => s != null) //find correct lexicographic order .Select(s => inSeg.Source.Id == s.FirstIntersection.Id ? s : this[inSeg.SecondIntersection.Id].GetSegmentInverse(s)) .ToList(); foreach (var seg in adjSegments) { var posAngle = inSeg.IsPositiveAngle(seg); if (posLexProg) { if (posAngle ^ (dir & Tesselation.SegmentCellCovered.Right) != 0) { yield return(seg); } } else if (!posAngle ^ (dir & Tesselation.SegmentCellCovered.Left) != 0) { yield return(seg); } } }
/// <summary> /// Cover the points in the segment from the segment's 'direction' side. /// </summary> /// <param name="seg"></param> /// <param name="direction"></param> public void CoverSegment(LineSegment seg, Tesselation.SegmentCellCovered direction) { //CoverCoordPair(seg.FirstIntersectionCoord,seg.SecondIntersectionCoord, direction); var inVertexId = seg.SecondIntersectionCoord.CoordId.Value; var inLexProg = seg.IsPositiveLexicographicProgress(); var covered = true; for (var i = 0; i < 4; i++) { var curr = LineIntersections[inVertexId, i]; if (curr == null || curr.CoordId == seg.FirstIntersectionCoord.CoordId) { continue; } var angle = LineSegment.GetAngle(seg.FirstIntersectionCoord, seg.SecondIntersectionCoord, seg.SecondIntersectionCoord, curr); var lineIds = LineIdsFromCoordId(curr.CoordId.Value); if ((direction & Tesselation.SegmentCellCovered.Right) != 0 && (inLexProg ? angle < 180 : angle > 180 && lineIds.Item1 != seg.Source.Id && lineIds.Item2 != seg.Source.Id)) { CoverCoordPair(seg.SecondIntersectionCoord, curr, direction); } if ((direction & Tesselation.SegmentCellCovered.Left) != 0 && (inLexProg ? angle > 180 : angle < 180 && lineIds.Item1 != seg.Source.Id && lineIds.Item2 != seg.Source.Id)) { CoverCoordPair(seg.SecondIntersectionCoord, curr, direction); } } /* * var neighborCoords = VertexNeighbors(inVertexId) * .Select((v, id) => new { Vertex = v, Id = id }).Where(v => v.Vertex != null).Select(v => new * { * v.Vertex, * v.Id, * Angle = LineSegment.GetAngle(seg.FirstIntersectionCoord, seg.SecondIntersectionCoord, * seg.SecondIntersectionCoord, v.Vertex), * LineIds = LineIdsFromCoordId(v.Vertex.CoordId.Value) * }).ToList(4); * if ((direction & Tesselation.SegmentCellCovered.Right) != 0) * { * var nextCoord = neighborCoords.FirstOrDefault(v => inLexProg ? v.Angle < 180 : v.Angle > 180 && v.LineIds.Item1 != seg.Source.Id && v.LineIds.Item2 != seg.Source.Id); * if (nextCoord != null) * CoverCoordPair(seg.SecondIntersectionCoord, nextCoord.Vertex, direction); * } * if ((direction & Tesselation.SegmentCellCovered.Left) != 0) * { * var nextCoord = neighborCoords.FirstOrDefault(v => inLexProg ? v.Angle > 180 : v.Angle < 180 && v.LineIds.Item1 != seg.Source.Id && v.LineIds.Item2 != seg.Source.Id); * if (nextCoord != null) * CoverCoordPair(seg.SecondIntersectionCoord, nextCoord.Vertex, direction); * } */ }
public void CoverCoordPair(Coordinate from, Coordinate to, Tesselation.SegmentCellCovered direction) { Interlocked.Increment(ref segmentCount); var fromid = GetCoordNeighborId(from.CoordId.Value, to.CoordId.Value); var toid = GetCoordNeighborId(to.CoordId.Value, from.CoordId.Value); if ((direction & Tesselation.SegmentCellCovered.Right) != 0) { this.CoveredIntersectionsRight[from.CoordId.Value, fromid] = true; this.CoveredIntersectionsLeft[to.CoordId.Value, toid] = true; } if ((direction & Tesselation.SegmentCellCovered.Left) != 0) { this.CoveredIntersectionsLeft[from.CoordId.Value, fromid] = true; this.CoveredIntersectionsRight[to.CoordId.Value, toid] = true; } }
public bool WasCovered(LineSegment nextSeg, Tesselation.SegmentCellCovered nextDirection) { var from = nextSeg.FirstIntersectionCoord.CoordId.Value; var to = nextSeg.SecondIntersectionCoord.CoordId.Value; var toNeighId = GetCoordNeighborId(from, to); if ((nextDirection & Tesselation.SegmentCellCovered.Right) != 0) { return(CoveredIntersectionsRight[from, toNeighId]); } if ((nextDirection & Tesselation.SegmentCellCovered.Left) != 0) { return(CoveredIntersectionsLeft[from, toNeighId]); } return(false); /* * var inVertexId = nextSeg.SecondIntersectionCoord.CoordId.Value; * var inLexProg = nextSeg.IsPositiveLexicographicProgress(); * var covered = true; * var neighborCoords = VertexNeighbors(inVertexId) * .Select((v, id) => new { Vertex = v, Id = id }).Where(v=>v.Vertex!=null).Select(v=> new * { * v.Vertex, * v.Id, * Angle = LineSegment.GetAngle(nextSeg.FirstIntersectionCoord, nextSeg.SecondIntersectionCoord, * nextSeg.SecondIntersectionCoord, v.Vertex), * LineIds = LineIdsFromCoordId(v.Vertex.CoordId.Value) * }).ToList(); * * if ((nextDirection & Tesselation.SegmentCellCovered.Right) != 0) * { * var nextCoord = neighborCoords.FirstOrDefault(v=> inLexProg ? v.Angle < 180 : v.Angle > 180 && v.LineIds.Item1 != nextSeg.Source.Id && v.LineIds.Item2 != nextSeg.Source.Id); * if(nextCoord != null) * covered = covered & this.CoveredIntersectionsRight[inVertexId, nextCoord.Id]; * } * if ((nextDirection & Tesselation.SegmentCellCovered.Left) != 0) * { * var nextCoord = neighborCoords.FirstOrDefault(v => inLexProg ? v.Angle > 180 : v.Angle < 180 && v.LineIds.Item1 != nextSeg.Source.Id && v.LineIds.Item2 != nextSeg.Source.Id); * if (nextCoord != null) * covered = covered & this.CoveredIntersectionsLeft[inVertexId, nextCoord.Id]; * } * return covered; */ }
public bool WasCovered(LineSegment lineSegment, Tesselation.SegmentCellCovered direction = Tesselation.SegmentCellCovered.Both) { switch (direction) { case Tesselation.SegmentCellCovered.Both: return(LeftCellsVisited[lineSegment.IdOnSource] && RightCellsVisited[lineSegment.IdOnSource]); case Tesselation.SegmentCellCovered.Left: return(LeftCellsVisited[lineSegment.IdOnSource]); case Tesselation.SegmentCellCovered.Right: return(RightCellsVisited[lineSegment.IdOnSource]); case Tesselation.SegmentCellCovered.None: return(false); default: throw new ArgumentOutOfRangeException(nameof(direction), direction, null); } }
public LineSegment GetSegmentNeighborBreaking(LineSegment prevSeg, Tesselation.SegmentCellCovered nextDirection) { var inVertexId = prevSeg.SecondIntersectionCoord.CoordId.Value; var relevantLines = LineIdsFromCoordId(inVertexId); var newSource = relevantLines.Item1 != prevSeg.Source.Id ? relevantLines.Item1 : relevantLines.Item2; for (var i = 0; i < 4; i++) { var curr = LineIntersections[inVertexId, i]; if (curr == null || curr.CoordId == prevSeg.FirstIntersectionCoord.CoordId) { continue; } var angle = LineSegment.GetAngle(prevSeg.FirstIntersectionCoord, prevSeg.SecondIntersectionCoord, prevSeg.SecondIntersectionCoord, curr); var lineIds = LineIdsFromCoordId(curr.CoordId.Value); if ((nextDirection & Tesselation.SegmentCellCovered.Right) != 0) { if (angle < 180 && lineIds.Item1 != prevSeg.Source.Id && lineIds.Item2 != prevSeg.Source.Id) { var coordlineid = lineIds.Item1 != newSource ? lineIds.Item1 : lineIds.Item2; return(new LineSegment(Lines[newSource], prevSeg.SecondIntersection, Lines[coordlineid], prevSeg.SecondIntersectionCoord, curr)); } } if ((nextDirection & Tesselation.SegmentCellCovered.Left) != 0) { if (angle > 180 && lineIds.Item1 != prevSeg.Source.Id && lineIds.Item2 != prevSeg.Source.Id) { var coordlineid = lineIds.Item1 != newSource ? lineIds.Item1 : lineIds.Item2; return(new LineSegment(Lines[newSource], prevSeg.SecondIntersection, Lines[coordlineid], prevSeg.SecondIntersectionCoord, curr)); } } } return(null); }
public IEnumerable <LineSegment> GetSegmentNeighbors(LineSegment prevSeg, Tesselation.SegmentCellCovered nextDirection) { var inVertexId = prevSeg.SecondIntersectionCoord.CoordId.Value; var relevantLines = LineIdsFromCoordId(inVertexId); var newSource = relevantLines.Item1 != prevSeg.Source.Id ? relevantLines.Item1 : relevantLines.Item2; for (var i = 0; i < 4; i++) { var curr = LineIntersections[inVertexId, i]; if (curr == null || curr.CoordId == prevSeg.FirstIntersectionCoord.CoordId) { continue; } var angle = LineSegment.GetAngle(prevSeg.FirstIntersectionCoord, prevSeg.SecondIntersectionCoord, prevSeg.SecondIntersectionCoord, curr); var lineIds = LineIdsFromCoordId(curr.CoordId.Value); if ((nextDirection & Tesselation.SegmentCellCovered.Right) != 0) { if (angle < 180 && lineIds.Item1 != prevSeg.Source.Id && lineIds.Item2 != prevSeg.Source.Id) { var coordlineid = lineIds.Item1 != newSource ? lineIds.Item1 : lineIds.Item2; yield return(new LineSegment(Lines[newSource], prevSeg.SecondIntersection, Lines[coordlineid], prevSeg.SecondIntersectionCoord, curr)); } } if ((nextDirection & Tesselation.SegmentCellCovered.Left) != 0) { if (angle > 180 && lineIds.Item1 != prevSeg.Source.Id && lineIds.Item2 != prevSeg.Source.Id) { var coordlineid = lineIds.Item1 != newSource ? lineIds.Item1 : lineIds.Item2; yield return(new LineSegment(Lines[newSource], prevSeg.SecondIntersection, Lines[coordlineid], prevSeg.SecondIntersectionCoord, curr)); } } } /* * var inLexProg = prevSeg.IsPositiveLexicographicProgress() ? 0 : 2; * var neighborCoords = VertexNeighbors(inVertexId) * .Select((v, id) => new { Vertex = v, Id = id }).Where(v => v.Vertex != null && v.Vertex.CoordId != prevSeg.FirstIntersectionCoord.CoordId) * .Select(v => new * { * v.Vertex, * v.Id, * Angle = LineSegment.GetAngle(prevSeg.FirstIntersectionCoord, prevSeg.SecondIntersectionCoord, * prevSeg.SecondIntersectionCoord, v.Vertex), * LineIds = LineIdsFromCoordId(v.Vertex.CoordId.Value) * }).ToList(); * if ((nextDirection & Tesselation.SegmentCellCovered.Right) != 0) * { * var nextCoord = neighborCoords.FirstOrDefault(v => v.Angle < 180 && v.LineIds.Item1 != prevSeg.Source.Id && v.LineIds.Item2 != prevSeg.Source.Id); * if (nextCoord != null) * { * var coordlineid = nextCoord.LineIds.Item1 != newSource ? nextCoord.LineIds.Item1 : nextCoord.LineIds.Item2; * yield return new LineSegment(Lines[newSource], prevSeg.SecondIntersection, Lines[coordlineid], prevSeg.SecondIntersectionCoord, nextCoord.Vertex); * } * } * if ((nextDirection & Tesselation.SegmentCellCovered.Left) != 0) * { * var nextCoord = neighborCoords.FirstOrDefault(v => v.Angle > 180 && v.LineIds.Item1 != prevSeg.Source.Id && v.LineIds.Item2 != prevSeg.Source.Id); * if (nextCoord != null) * { * var coordlineid = nextCoord.LineIds.Item1 != newSource ? nextCoord.LineIds.Item1 : nextCoord.LineIds.Item2; * yield return new LineSegment(Lines[newSource], prevSeg.SecondIntersection, Lines[coordlineid], prevSeg.SecondIntersectionCoord, nextCoord.Vertex); * } * } */ }