Example #1
0
  @Test
  public void testSplitBounds() {
    List<IStellar> stellars = new LinkedList<IStellar>();
    stellars.add(start);
    stellars.add(end);

    IBoundingBox box = BoundingBox.newInstance(stellars);
    SplitDegree splitDegree = box.splitDegree();
    IBoundingBox[] splitted = new IBoundingBox[splitDegree.value()];
    for (IOffset offset : splitDegree.offsets()) {
      splitted[offset.offsetIndex()] = (IBoundingBox) box.onSplit(ctx, offset);
    }

    IBoundingBox frontBottomLeft = splitted[0];
    IBoundingBox frontBottomRight = splitted[1];
    IBoundingBox frontTopLeft = splitted[2];
    IBoundingBox frontTopRight = splitted[3];
    IBoundingBox rearBottomLeft = splitted[4];
    IBoundingBox rearBottomRight = splitted[5];
    IBoundingBox rearTopLeft = splitted[6];
    IBoundingBox rearTopRight = splitted[7];

    assertEquals(new Location(-5, -5, -5, DistanceUnit.LIGHT_YEAR), frontBottomLeft.center());
    assertEquals(5, frontBottomLeft.radius(), 0);
    assertEquals(new Location(5, -5, -5, DistanceUnit.LIGHT_YEAR), frontBottomRight.center());
    assertEquals(new Location(-5, 5, -5, DistanceUnit.LIGHT_YEAR), frontTopLeft.center());
    assertEquals(new Location(5, 5, -5, DistanceUnit.LIGHT_YEAR), frontTopRight.center());
    assertEquals(new Location(-5, -5, 5, DistanceUnit.LIGHT_YEAR), rearBottomLeft.center());
    assertEquals(new Location(5, -5, 5, DistanceUnit.LIGHT_YEAR), rearBottomRight.center());
    assertEquals(new Location(-5, 5, 5, DistanceUnit.LIGHT_YEAR), rearTopLeft.center());
    assertEquals(new Location(5, 5, 5, DistanceUnit.LIGHT_YEAR), rearTopRight.center());
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * com.cohesiva.drifter.datastruct.IComplex#onSplitComplete(com.cohesiva
   * .drifter.common.Location, com.cohesiva.drifter.datastruct.IComplex[])
   */
  @Override
  public void onSplitComplete(ISplitContext ctx, IComplex[] splittedParts) {
    // {{ distribute all circles to splitted complexes
    for (Iterator<Circle> iter = this.circles.iterator(); iter.hasNext(); ) {
      Circle circle = iter.next();

      for (IOffset offset : this.splitDegree().offsets()) {
        SquareWithCircles holder = (SquareWithCircles) splittedParts[offset.offsetIndex()];
        if (holder.isSurrounding(ctx.referenceLocation(), 0)) {
          holder.circles.add(circle);
          iter.remove();

          break;
        }
      }
    }
    // }}
  }