Package org.openpixi.pixi.physics.util

Examples of org.openpixi.pixi.physics.util.Point


    // Test boundary corner regions

    int region = BoundaryRegions.X_MIN + BoundaryRegions.Y_MIN;
    int neighbor = neighborMap.getBoundaryNeighbor(region);
    Assert.assertEquals(7, neighbor);
    Point direction = neighborMap.getBoundaryNeighborsDirections(region);
    Assert.assertEquals(new Point(-1, -1), direction);

    region = BoundaryRegions.X_MAX + BoundaryRegions.Y_MAX;
    neighbor = neighborMap.getBoundaryNeighbor(region);
    Assert.assertEquals(3, neighbor);
    direction = neighborMap.getBoundaryNeighborsDirections(region);
    Assert.assertEquals(new Point(1, 1), direction);

    region = BoundaryRegions.X_MIN + BoundaryRegions.Y_MAX;
    neighbor = neighborMap.getBoundaryNeighbor(region);
    Assert.assertEquals(3, neighbor);
    direction = neighborMap.getBoundaryNeighborsDirections(region);
    Assert.assertEquals(new Point(-1, 1), direction);

    // Test boundary edge regions

    region = BoundaryRegions.X_MIN + BoundaryRegions.Y_CENTER;
    neighbor = neighborMap.getBoundaryNeighbor(region);
    Assert.assertEquals(2, neighbor);
    direction = neighborMap.getBoundaryNeighborsDirections(region);
    Assert.assertEquals(new Point(-1, 0), direction);

    region = BoundaryRegions.X_MAX + BoundaryRegions.Y_CENTER;
    neighbor = neighborMap.getBoundaryNeighbor(region);
    Assert.assertEquals(2, neighbor);
    direction = neighborMap.getBoundaryNeighborsDirections(region);
    Assert.assertEquals(new Point(1, 0), direction);

    region = BoundaryRegions.X_CENTER + BoundaryRegions.Y_MIN;
    neighbor = neighborMap.getBoundaryNeighbor(region);
    Assert.assertEquals(5, neighbor);
    direction = neighborMap.getBoundaryNeighborsDirections(region);
    Assert.assertEquals(new Point(0, -1), direction);

    // Test border corner regions

    region = BorderRegions.X_BORDER_MIN + BorderRegions.Y_BORDER_MIN;
    int[] neighbors = neighborMap.getBorderNeighbors(region);
    int on1 = assertContains(neighbors, 2);
    int on2 = assertContains(neighbors, 5);
    int on3 = assertContains(neighbors, 7);
    Point[] directions = neighborMap.getBorderNeighborsDirections(region);
    int od1 = assertContainsPoint(directions, new Point(-1, 0));
    int od2 = assertContainsPoint(directions, new Point(0, -1));
    int od3 = assertContainsPoint(directions, new Point(-1, -1));
    // Test order
    Assert.assertEquals(on1, od1);
    Assert.assertEquals(on2, od2);
    Assert.assertEquals(on3, od3);

    region = BorderRegions.X_BORDER_MAX + BorderRegions.Y_BORDER_MAX;
    neighbors = neighborMap.getBorderNeighbors(region);
    on1 = assertContains(neighbors, 1);
    on2 = assertContains(neighbors, 2);
    on3 = assertContains(neighbors, 3);
    directions = neighborMap.getBorderNeighborsDirections(region);
    od1 = assertContainsPoint(directions, new Point(0, 1));
    od2 = assertContainsPoint(directions, new Point(1, 0));
    od3 = assertContainsPoint(directions, new Point(1, 1));
    // Test order
    Assert.assertEquals(on1, od1);
    Assert.assertEquals(on2, od2);
    Assert.assertEquals(on3, od3);

    // Test border edge regions

    region = BorderRegions.X_CENTER + BorderRegions.Y_BORDER_MIN;
    neighbors = neighborMap.getBorderNeighbors(region);
    assertContains(neighbors, 5);
    directions = neighborMap.getBorderNeighborsDirections(region);
    assertContainsPoint(directions, new Point(0, -1));

    region = BorderRegions.X_BORDER_MAX + BorderRegions.Y_CENTER;
    neighbors = neighborMap.getBorderNeighbors(region);
    assertContains(neighbors, 2);
    directions = neighborMap.getBorderNeighborsDirections(region);
    assertContainsPoint(directions, new Point(1, 0));
  }
View Full Code Here


    // Test boundary corner regions

    int region = BoundaryRegions.X_MIN + BoundaryRegions.Y_MIN;
    int neighbor = neighborMap.getBoundaryNeighbor(region);
    Assert.assertEquals(NeighborMap.NO_NEIGHBOR, neighbor);
    Point direction = neighborMap.getBoundaryNeighborsDirections(region);
    Assert.assertNull(direction);

    region = BoundaryRegions.X_MAX + BoundaryRegions.Y_MAX;
    neighbor = neighborMap.getBoundaryNeighbor(region);
    Assert.assertEquals(3, neighbor);
    direction = neighborMap.getBoundaryNeighborsDirections(region);
    Assert.assertEquals(new Point(1, 1), direction);

    region = BoundaryRegions.X_MIN + BoundaryRegions.Y_MAX;
    neighbor = neighborMap.getBoundaryNeighbor(region);
    Assert.assertEquals(1, neighbor);
    direction = neighborMap.getBoundaryNeighborsDirections(region);
    Assert.assertEquals(new Point(0, 1), direction);

    // Test boundary edge regions

    region = BoundaryRegions.X_MIN + BoundaryRegions.Y_CENTER;
    neighbor = neighborMap.getBoundaryNeighbor(region);
    Assert.assertEquals(NeighborMap.NO_NEIGHBOR, neighbor);
    direction = neighborMap.getBoundaryNeighborsDirections(region);
    Assert.assertNull(direction);

    region = BoundaryRegions.X_MAX + BoundaryRegions.Y_CENTER;
    neighbor = neighborMap.getBoundaryNeighbor(region);
    Assert.assertEquals(2, neighbor);
    direction = neighborMap.getBoundaryNeighborsDirections(region);
    Assert.assertEquals(new Point(1, 0), direction);

    region = BoundaryRegions.X_CENTER + BoundaryRegions.Y_MAX;
    neighbor = neighborMap.getBoundaryNeighbor(region);
    Assert.assertEquals(1, neighbor);
    direction = neighborMap.getBoundaryNeighborsDirections(region);
    Assert.assertEquals(new Point(0, 1), direction);

    // Test border corner regions

    region = BorderRegions.X_BORDER_MIN + BorderRegions.Y_BORDER_MAX;
    int[] neighbors = neighborMap.getBorderNeighbors(region);
    int on1 = assertContains(neighbors, 1);
    assertContains(neighbors, NeighborMap.NO_NEIGHBOR);
    Point[] directions = neighborMap.getBorderNeighborsDirections(region);
    int od1 = assertContainsPoint(directions, new Point(0, 1));
    // Test order
    Assert.assertEquals(on1, od1);

    region = BorderRegions.X_BORDER_MAX + BorderRegions.Y_BORDER_MAX;
    neighbors = neighborMap.getBorderNeighbors(region);
    on1 = assertContains(neighbors, 1);
    int on2 = assertContains(neighbors, 2);
    int on3 = assertContains(neighbors, 3);
    directions = neighborMap.getBorderNeighborsDirections(region);
    od1 = assertContainsPoint(directions, new Point(0, 1));
    int od2 = assertContainsPoint(directions, new Point(1, 0));
    int od3 = assertContainsPoint(directions, new Point(1, 1));
    // Test order
    Assert.assertEquals(on1, od1);
    Assert.assertEquals(on2, od2);
    Assert.assertEquals(on3, od3);

    // Test border outside corner regions

    region = BorderRegions.X_BORDER_MAX + BorderRegions.Y_BOUNDARY_MIN;
    neighbors = neighborMap.getBorderNeighbors(region);
    assertContains(neighbors, 2);
    directions = neighborMap.getBorderNeighborsDirections(region);
    assertContainsPoint(directions, new Point(1, 0));

    region = BorderRegions.X_BOUNDARY_MAX + BorderRegions.Y_BORDER_MIN;
    neighbors = neighborMap.getBorderNeighbors(region);
    assertContains(neighbors, NeighborMap.NO_NEIGHBOR);
    directions = neighborMap.getBorderNeighborsDirections(region);
    Assert.assertEquals(1, directions.length);
    Assert.assertNull(directions[0]);

    // Test border edge regions

    region = BorderRegions.X_CENTER + BorderRegions.Y_BORDER_MAX;
    neighbors = neighborMap.getBorderNeighbors(region);
    assertContains(neighbors, 1);
    directions = neighborMap.getBorderNeighborsDirections(region);
    assertContainsPoint(directions, new Point(0, 1));

    region = BorderRegions.X_BORDER_MAX + BorderRegions.Y_CENTER;
    neighbors = neighborMap.getBorderNeighbors(region);
    assertContains(neighbors, 2);
    directions = neighborMap.getBorderNeighborsDirections(region);
    assertContainsPoint(directions, new Point(1, 0));
  }
View Full Code Here

   * Decomposes the region id to X and Y components.
   */
  public static Point decomposeRegionID(int regionID) {
    int y = findHighestPossibleY(regionID);
    int x = findX(y, regionID);
    return new Point(x, y);
  }
View Full Code Here

   * E.g.:
   *   X_MIN + Y_MIN = (-1, -1)
   *   X_CENTER + Y_MAX = (0, 1)
   */
  public static Point getSign(int regionID) {
    Point region = decomposeRegionID(regionID);
    return new Point(region.x - 1, region.y / 3 - 1);
  }
View Full Code Here

    int xmid = partition.xmin() + partition.xsize() / 2;
    int ymid = partition.ymin() + partition.ysize() / 2;

    boundaryPoints[BoundaryRegions.X_MIN + BoundaryRegions.Y_MIN] =
        new Point(partition.xmin() - 1, partition.ymin() - 1);
    boundaryPoints[BoundaryRegions.X_MIN + BoundaryRegions.Y_CENTER] =
        new Point(partition.xmin() - 1, ymid);
    boundaryPoints[BoundaryRegions.X_MIN + BoundaryRegions.Y_MAX] =
        new Point(partition.xmin() - 1, partition.ymax() + 1);

    boundaryPoints[BoundaryRegions.X_CENTER + BoundaryRegions.Y_MIN] =
        new Point(xmid, partition.ymin() - 1);
    // The point for the center region remains null.
    boundaryPoints[BoundaryRegions.X_CENTER + BoundaryRegions.Y_MAX] =
        new Point(xmid, partition.ymax() + 1);

    boundaryPoints[BoundaryRegions.X_MAX + BoundaryRegions.Y_MIN] =
        new Point(partition.xmax() + 1, partition.ymin() - 1);
    boundaryPoints[BoundaryRegions.X_MAX + BoundaryRegions.Y_CENTER] =
        new Point(partition.xmax() + 1, ymid);
    boundaryPoints[BoundaryRegions.X_MAX + BoundaryRegions.Y_MAX] =
        new Point(partition.xmax() + 1, partition.ymax() + 1);
  }
View Full Code Here


  private void initBoundaryNeighborsDirections(IntBox partition) {

    boundaryNeighborsDirections[BoundaryRegions.X_MIN + BoundaryRegions.Y_MIN] =
        new Point(-1, -1);
    boundaryNeighborsDirections[BoundaryRegions.X_MIN + BoundaryRegions.Y_CENTER] =
        new Point(-1, 0);
    boundaryNeighborsDirections[BoundaryRegions.X_MIN + BoundaryRegions.Y_MAX] =
        new Point(-1, +1);

    boundaryNeighborsDirections[BoundaryRegions.X_CENTER + BoundaryRegions.Y_MIN] =
        new Point(0, -1);
    boundaryNeighborsDirections[BoundaryRegions.X_CENTER + BoundaryRegions.Y_MAX] =
        new Point(0, +1);

    boundaryNeighborsDirections[BoundaryRegions.X_MAX + BoundaryRegions.Y_MIN] =
        new Point(+1, -1);
    boundaryNeighborsDirections[BoundaryRegions.X_MAX + BoundaryRegions.Y_CENTER] =
        new Point(+1, 0);
    boundaryNeighborsDirections[BoundaryRegions.X_MAX + BoundaryRegions.Y_MAX] =
        new Point(+1, +1);
  }
View Full Code Here

     * The first point always identifies the corner neighbor.
     */

    borderPoints[BorderRegions.X_BORDER_MIN + BorderRegions.Y_BORDER_MIN] =
        new Point[] {
            new Point(partition.xmin() - 1, partition.ymin() - 1),
            new Point(partition.xmin(), partition.ymin() - 1),
            new Point(partition.xmin() - 1, partition.ymin())
        };

    borderPoints[BorderRegions.X_BORDER_MIN + BorderRegions.Y_BORDER_MAX] =
        new Point[] {
            new Point(partition.xmin() - 1, partition.ymax() + 1),
            new Point(partition.xmin(), partition.ymax() + 1),
            new Point(partition.xmin() - 1, partition.ymax())
        };

    borderPoints[BorderRegions.X_BORDER_MAX + BorderRegions.Y_BORDER_MIN] =
        new Point[] {
            new Point(partition.xmax() + 1, partition.ymin() - 1),
            new Point(partition.xmax(), partition.ymin() - 1),
            new Point(partition.xmax() + 1, partition.ymin())
        };

    borderPoints[BorderRegions.X_BORDER_MAX + BorderRegions.Y_BORDER_MAX] =
        new Point[] {
            new Point(partition.xmax() + 1, partition.ymax() + 1),
            new Point(partition.xmax(), partition.ymax() + 1),
            new Point(partition.xmax() + 1, partition.ymax())
        };

    /*
     * Outside hardwall corner points (only needed at the edges of the global simulation).
     * It is important to note that for region X_BORDER_MIN + Y_BOUNDARY_MIN (region 1)
     * the point which identifies the neighbor is from region X_BOUNDARY_MIN + Y_BORDER_MIN
     * (region 2). In another words, the data from region 1 needs to be sent to region 2.
     */

    borderPoints[BorderRegions.X_BORDER_MIN + BorderRegions.Y_BOUNDARY_MIN] =
        new Point[] { new Point(partition.xmin() - 1, partition.ymin()) };
    borderPoints[BorderRegions.X_BORDER_MAX + BorderRegions.Y_BOUNDARY_MIN] =
        new Point[] { new Point(partition.xmax() + 1, partition.ymin()) };

    borderPoints[BorderRegions.X_BORDER_MIN + BorderRegions.Y_BOUNDARY_MAX] =
        new Point[] { new Point(partition.xmin() - 1, partition.ymax()) };
    borderPoints[BorderRegions.X_BORDER_MAX + BorderRegions.Y_BOUNDARY_MAX] =
        new Point[] { new Point(partition.xmax() + 1, partition.ymax()) };

    borderPoints[BorderRegions.X_BOUNDARY_MIN + BorderRegions.Y_BORDER_MIN] =
        new Point[] { new Point(partition.xmin(), partition.ymin() - 1) };
    borderPoints[BorderRegions.X_BOUNDARY_MIN + BorderRegions.Y_BORDER_MAX] =
        new Point[] { new Point(partition.xmin(), partition.ymax() + 1) };

    borderPoints[BorderRegions.X_BOUNDARY_MAX + BorderRegions.Y_BORDER_MIN] =
        new Point[] { new Point(partition.xmax(), partition.ymin() - 1) };
    borderPoints[BorderRegions.X_BOUNDARY_MAX + BorderRegions.Y_BORDER_MAX] =
        new Point[] { new Point(partition.xmax(), partition.ymax() + 1) };

    /*
     * Edge points.
     */

    int xmid = partition.xmin() + partition.xsize() / 2;
    int ymid = partition.ymin() + partition.ysize() / 2;

    borderPoints[BorderRegions.X_BORDER_MIN + BorderRegions.Y_CENTER] =
        new Point[] { new Point(partition.xmin() - 1, ymid) };
    borderPoints[BorderRegions.X_BORDER_MAX + BorderRegions.Y_CENTER] =
        new Point[] { new Point(partition.xmax() + 1, ymid) };
    borderPoints[BorderRegions.X_CENTER + BorderRegions.Y_BORDER_MIN] =
        new Point[] { new Point(xmid, partition.ymin() - 1) };
    borderPoints[BorderRegions.X_CENTER + BorderRegions.Y_BORDER_MAX] =
        new Point[] { new Point(xmid, partition.ymax() + 1) };
  }
View Full Code Here

    // Corner neighbors directions

    borderNeighborsDirections[BorderRegions.X_BORDER_MIN + BorderRegions.Y_BORDER_MIN] =
        new Point[] {
            new Point(-1,  -1),
            new Point(0, -1),
            new Point(-1, 0)
        };

    borderNeighborsDirections[BorderRegions.X_BORDER_MIN + BorderRegions.Y_BORDER_MAX] =
        new Point[] {
            new Point(-1, +1),
            new Point(0, +1),
            new Point(-1, 0)
        };

    borderNeighborsDirections[BorderRegions.X_BORDER_MAX + BorderRegions.Y_BORDER_MIN] =
        new Point[] {
            new Point(+1, -1),
            new Point(0, -1),
            new Point(+1, 0)
        };

    borderNeighborsDirections[BorderRegions.X_BORDER_MAX + BorderRegions.Y_BORDER_MAX] =
        new Point[] {
            new Point(+1, +1),
            new Point(0, +1),
            new Point(+1, 0)
        };

    // Edge neighbors

    borderNeighborsDirections[BorderRegions.X_BORDER_MIN + BorderRegions.Y_CENTER] =
        new Point[] { new Point(-1, 0) };
    borderNeighborsDirections[BorderRegions.X_BORDER_MAX + BorderRegions.Y_CENTER] =
        new Point[] { new Point(+1, 0) };
    borderNeighborsDirections[BorderRegions.X_CENTER + BorderRegions.Y_BORDER_MIN] =
        new Point[] { new Point(0, -1) };
    borderNeighborsDirections[BorderRegions.X_CENTER + BorderRegions.Y_BORDER_MAX] =
        new Point[] { new Point(0, +1) };
  }
View Full Code Here

  private void setHardwallBoundaryNeighbors() {

    // Map edge neighbors
    for (int region: BoundaryRegions.EDGE_REGIONS) {
      Point p = boundaryPoints[region];
      int workerID = findNeighborByPoint(p);
      boundaryNeighbors[region] = workerID;
      }

    /*
     * Map corner regions to neighbors.
     * If the true corner neighbor does not exist the region should be mapped to
     * left, right, bottom or top neighbor (if one of them exists;
     * in the corner of the global simulation area there is no neighbor).
     */

    for (int region: BoundaryRegions.CORNER_REGIONS) {
      Point p = boundaryPoints[region];
      int workerID = findNeighborByPoint(p);
      if (workerID == NO_NEIGHBOR) {
        workerID = findNeighborAroundPoint(p);
      }
      boundaryNeighbors[region] = workerID;
View Full Code Here

    }
  }


  private void setSinglePeriodicBoundaryNeighbor(int region) {
    Point p = boundaryPoints[region];
    applyPeriodicBoundary(p);

    int workerID = findNeighborByPoint(p);
    assert workerID != NO_NEIGHBOR;
View Full Code Here

TOP

Related Classes of org.openpixi.pixi.physics.util.Point

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.