// Input N rectangles -> 2N vertical line segment, 2N horizontal line segments // Output all true intersections rectangles private void OrthogonalLineSegmentIntersection(DisplayList dl) { // Sweep through sorted x coordiates from left to right, skipping MinValue/MaxValue for (int i = 1; i < _xCount - 1; i++) { Coordinate c = _xCoord[i]; bool left = Double.Equals(c.value, dl[c.index].Left); // Left endpoint => insertion into range tree // Right endpoint => delection from range tree c.top.active = left; c.bottom.active = left; // Vertical segment [y0..y1] => report [y0..y1] AND range tree double y0 = c.top.value; double y1 = c.bottom.value; int p = Array.BinarySearch(_yCoord, y0, new CoordinateSearcher()); if (p >= 0) { do { if ((_yCoord[p].active) && (c.index != _yCoord[p].index)) { dl.ReportOverlapping(c.index, _yCoord[p].index); // Console.WriteLine("{0} {1} intersects ({2},{3})", c.index, _yCoord[p].index, c.value, _yCoord[p].value); } p++; }while (_yCoord[p].value <= y1); } } }
public void ReportIntersection(DisplayList dl, int index, double x) { if (_sList != null) { foreach (int i in _sList) { if (index != i) { dl.ReportOverlapping(index, i); } } } if ((_left != null) && (x >= _left._min) && (x <= _left._max)) { _left.ReportIntersection(dl, index, x); } if ((_right != null) && (x >= _right._min) && (x <= _right._max)) { _right.ReportIntersection(dl, index, x); } }