public List <Segment> GetSplitSegmentForVertecies(PolygonEdgeIterator touchingEnumerator) { IntPoint start2D = new IntPoint(Start) { Z = 0 }; IntPoint end2D = new IntPoint(End) { Z = 0 }; SortedList <long, IntPoint> requiredSplits2D = new SortedList <long, IntPoint>(); // get some data we will need for the operations IntPoint direction = (end2D - start2D); long length = direction.Length(); long lengthSquared = length * length; IntPoint rightDirection = direction.GetPerpendicularRightXY(); long maxDistanceNormalized = touchingEnumerator.OverlapAmount * length; // for every vertex foreach (int touchingPoint in touchingEnumerator.GetTouching(new Quad(this.Left, this.Bottom, this.Right, this.Top))) //for (int splintIndex = 0; splintIndex < splitPoints.Count; splintIndex++) { IntPoint vertex = new IntPoint(touchingEnumerator.SourcePoints[touchingPoint]) { Z = 0 } -start2D; // if the vertex is close enough to the segment long dotProduct = rightDirection.Dot(vertex); if (Math.Abs(dotProduct) < maxDistanceNormalized) { long dotProduct2 = direction.Dot(vertex); if (dotProduct2 > 0 && dotProduct2 < lengthSquared) { long distance = dotProduct2 / length; // don't add if there is already a point at this position if (!requiredSplits2D.ContainsKey(distance)) { // we are close enough to the line split it requiredSplits2D.Add(distance, start2D + direction * distance / length); } } } } if (requiredSplits2D.Count > 0) { // add in the start and end if (!requiredSplits2D.ContainsKey(0)) { requiredSplits2D.Add(0, start2D); } if (!requiredSplits2D.ContainsKey(length)) { requiredSplits2D.Add(length, end2D); } // convert to a segment list List <Segment> newSegments = Segment.ConvertPathToSegments(requiredSplits2D.Values, Start.Z, false); // return them; return(newSegments); } return(null); }