public boolean envelopesOverlap(LineSegment seg1, LineSegment seg2) { if (seg1.maxX() <= seg2.minX()) return false; if (seg2.maxX() <= seg1.minX()) return false; if (seg1.maxY() <= seg2.minY()) return false; if (seg2.maxY() <= seg1.minY()) return false; return true; }
public int XcompareTo(Object obj) { DepthSegment other = (DepthSegment) obj; // if segments are collinear and vertical compare endpoints if (isVertical() && other.isVertical() && upwardSeg.p0.x == other.upwardSeg.p0.x) return compareX(this.upwardSeg, other.upwardSeg); // check if segments are trivially ordered along X if (upwardSeg.maxX() <= other.upwardSeg.minX()) return -1; if (upwardSeg.minX() >= other.upwardSeg.maxX()) return 1; /** * try and compute a determinate orientation for the segments. Test returns 1 if other is left * of this (i.e. this > other) */ int orientIndex = upwardSeg.orientationIndex(other.upwardSeg); // if orientation is determinate, return it if (orientIndex != 0) return orientIndex; /** * If comparison between this and other is indeterminate, try the opposite call order. * orientationIndex value is 1 if this is left of other, so have to flip sign to get proper * comparison value of -1 if this is leftmost */ if (orientIndex == 0) orientIndex = -1 * other.upwardSeg.orientationIndex(upwardSeg); // if orientation is determinate, return it if (orientIndex != 0) return orientIndex; // otherwise, segs must be collinear - sort based on minimum X value return compareX(this.upwardSeg, other.upwardSeg); }