예제 #1
0
 /** @see Object3D#union(Object3D) */
 public Object3D union(Object3D space) {
   if (this.isContained(space)) return this;
   if (space.isContained(this)) return space;
   if (space instanceof Line3D) {
     /*
      * Try to avoid construction of an Object3DCombined.
      * If grade and offset in xz and xy area are matching and both lines
      * have a common x-range just create a longer Line3D.
      */
     Line3D other = (Line3D) space;
     if ((other.gradeY == this.gradeY)
         && (other.gradeZ == this.gradeZ)
         && (other.offsetY == this.offsetY)
         && (other.offsetZ == this.offsetZ)) {
       if ((this.start.x <= other.start.x) && (this.end.x >= other.start.x)) {
         return new Line3D(this.start, other.end);
       }
       if ((this.start.x <= other.end.x) && (this.end.x >= other.end.x)) {
         return new Line3D(other.start, this.end);
       }
     }
   }
   return new Object3DCombined(this).union(space);
 }