public bool OverlapsInclusive(Segment1D other) { if (this.end >= other.start) { return(other.end >= this.start); } return(false); }
public static bool OverlapsInclusive(Segment1D segment1, Segment1D segment2) { if (segment1.end >= segment2.start) { return(segment2.end >= segment1.start); } return(false); }
public static IList <Segment1D> GetDifference( IList <Segment1D> segments, IList <Segment1D> toBeSubtractedSegments) { List <Segment1D> segment1DList = new List <Segment1D>(); foreach (Segment1D segment in (IEnumerable <Segment1D>)segments) { List <double> doubleList = new List <double>(); doubleList.Add(segment.start); doubleList.Add(segment.end); foreach (Segment1D subtractedSegment in (IEnumerable <Segment1D>)toBeSubtractedSegments) { if (segment.ContainsExclusive(subtractedSegment.start) && !doubleList.Contains(subtractedSegment.start)) { doubleList.Add(subtractedSegment.start); } if (segment.ContainsExclusive(subtractedSegment.end) && !doubleList.Contains(subtractedSegment.end)) { doubleList.Add(subtractedSegment.end); } } doubleList.Sort(); double start = doubleList[0]; for (int index = 1; index < doubleList.Count; ++index) { double end = doubleList[index]; Segment1D segment1D = new Segment1D(start, end); double center = segment1D.GetCenter(); bool flag = false; foreach (Segment1D subtractedSegment in (IEnumerable <Segment1D>)toBeSubtractedSegments) { if (subtractedSegment.ContainsExclusive(center)) { flag = true; break; } } if (!flag) { segment1DList.Add(segment1D); } start = end; } } return((IList <Segment1D>)segment1DList); }