Beispiel #1
0
    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);
    }
Beispiel #2
0
 public boolean isTransitive(DepthSegment seg1, DepthSegment seg2, DepthSegment seg3) {
   int cmp12 = seg1.compareTo(seg2);
   int cmp23 = seg2.compareTo(seg3);
   int cmp13 = seg1.compareTo(seg3);
   if (cmp12 > 0 && cmp23 > 0) {
     if (cmp13 <= 0) {
       System.out.println(seg1 + " " + seg2 + " " + seg3);
       return false;
     }
   }
   return true;
 }
Beispiel #3
0
 public boolean isSymmetric(DepthSegment seg1, DepthSegment seg2) {
   int cmp12 = seg1.compareTo(seg2);
   int cmp21 = seg2.compareTo(seg1);
   return cmp12 == -cmp21;
 }