Search in sources :

Example 31 with DoubleInterval

use of org.bboxdb.commons.math.DoubleInterval in project bboxdb by jnidzwetzki.

the class TestDoubleInterval method testIntervalSplit5.

/**
 * Test split at invalid position
 */
@Test(expected = IllegalArgumentException.class)
public void testIntervalSplit5() {
    final DoubleInterval interval1 = new DoubleInterval(0, 100, false, false);
    interval1.splitAndGetLeftPart(0, false);
}
Also used : DoubleInterval(org.bboxdb.commons.math.DoubleInterval) Test(org.junit.Test)

Example 32 with DoubleInterval

use of org.bboxdb.commons.math.DoubleInterval in project bboxdb by jnidzwetzki.

the class TestDoubleInterval method testCompareTo.

/**
 * Test the compare to method
 */
@Test(timeout = 60000)
public void testCompareTo() {
    final DoubleInterval floatInterval1 = new DoubleInterval(1, 2, true, true);
    final DoubleInterval floatInterval2 = new DoubleInterval(3, 4, false, false);
    Assert.assertTrue(floatInterval1.compareTo(floatInterval1) == 0);
    Assert.assertTrue(floatInterval1.compareTo(floatInterval2) < 0);
    Assert.assertTrue(floatInterval2.compareTo(floatInterval1) > 0);
}
Also used : DoubleInterval(org.bboxdb.commons.math.DoubleInterval) Test(org.junit.Test)

Example 33 with DoubleInterval

use of org.bboxdb.commons.math.DoubleInterval in project bboxdb by jnidzwetzki.

the class DistributionRegionComponent method drawComponent.

/**
 * Draw this component
 * @param g
 * @param maxChildren
 * @return
 */
public BoundingBox drawComponent(final Graphics2D g) {
    // Recalculate the offsets
    this.xOffset = calculateXOffset(distributionRegion);
    this.yOffset = calculateYOffset();
    // Draw the node
    final Color oldColor = g.getColor();
    g.setColor(getColorForRegion(distributionRegion));
    g.fillRect(xOffset, yOffset, WIDTH, HEIGHT);
    g.setColor(oldColor);
    g.drawRect(xOffset, yOffset, WIDTH, HEIGHT);
    final BoundingBox converingBox = distributionRegion.getConveringBox();
    final double offset = (double) 0.9 / (double) (2.0 + converingBox.getDimension());
    // Write the region id
    final String regionId = "Region: " + Long.toString(distributionRegion.getRegionId());
    writeStringCentered(g, regionId, 1 * offset);
    // Write the state
    final String nodeState = distributionRegion.getState().getStringValue();
    writeStringCentered(g, nodeState, 2 * offset);
    // Write the bounding box
    for (int i = 0; i < converingBox.getDimension(); i++) {
        final DoubleInterval floatInterval = converingBox.getIntervalForDimension(i);
        final String text = "D" + i + ": " + floatInterval.getRoundedString(3);
        writeStringCentered(g, text, (3 + i) * offset);
    }
    // Draw the line to the parent node
    drawParentNodeLine(g);
    return getBoundingBox();
}
Also used : Color(java.awt.Color) BoundingBox(org.bboxdb.commons.math.BoundingBox) DoubleInterval(org.bboxdb.commons.math.DoubleInterval)

Example 34 with DoubleInterval

use of org.bboxdb.commons.math.DoubleInterval in project bboxdb by jnidzwetzki.

the class CellGrid method createCells.

/**
 * Create the cell intervals for the grid
 * @param coveringBox
 * @param cellSizeInDimension
 * @return
 */
private static CellGrid createCells(final BoundingBox coveringBox, final Function<Integer, Double> cellSizeInDimension) {
    final List<List<DoubleInterval>> cells = new ArrayList<>();
    // Generate all possible interval for each dimension
    for (int dimension = 0; dimension < coveringBox.getDimension(); dimension++) {
        final DoubleInterval baseInterval = coveringBox.getIntervalForDimension(dimension);
        final double cellSize = cellSizeInDimension.apply(dimension);
        final int cellsInDimension = (int) Math.ceil(baseInterval.getLength() / cellSize);
        if (cellsInDimension <= 0) {
            throw new IllegalArgumentException("Cells in dimension " + (dimension + 1) + " has to be > 0");
        }
        // List of intervals for this dimension
        final List<DoubleInterval> intervals = new ArrayList<>();
        cells.add(intervals);
        for (int offset = 0; offset < cellsInDimension; offset++) {
            final double begin = baseInterval.getBegin() + (offset * cellSize);
            final double end = Math.min(baseInterval.getBegin() + ((offset + 1) * cellSize), baseInterval.getEnd());
            // The last cell contains the end point
            final boolean endIncluded = (offset + 1 == cellsInDimension);
            final DoubleInterval interval = new DoubleInterval(begin, end, true, endIncluded);
            intervals.add(interval);
        }
    }
    final Set<BoundingBox> allBoxes = convertListsToBoxes(cells);
    return new CellGrid(coveringBox, allBoxes);
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DoubleInterval(org.bboxdb.commons.math.DoubleInterval)

Example 35 with DoubleInterval

use of org.bboxdb.commons.math.DoubleInterval in project bboxdb by jnidzwetzki.

the class CellGrid method convertListsToBoxes.

/**
 * Convert the lists of intervals to bounding boxes
 * @param cells
 * @return
 */
private static Set<BoundingBox> convertListsToBoxes(final List<List<DoubleInterval>> cells) {
    final Set<BoundingBox> allBoxes = new HashSet<>();
    final List<List<DoubleInterval>> intervallProduct = Lists.cartesianProduct(cells);
    for (List<DoubleInterval> intervalls : intervallProduct) {
        final BoundingBox boundingBox = new BoundingBox(intervalls);
        allBoxes.add(boundingBox);
    }
    return allBoxes;
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) List(java.util.List) DoubleInterval(org.bboxdb.commons.math.DoubleInterval) HashSet(java.util.HashSet)

Aggregations

DoubleInterval (org.bboxdb.commons.math.DoubleInterval)38 Test (org.junit.Test)29 BoundingBox (org.bboxdb.commons.math.BoundingBox)10 ArrayList (java.util.ArrayList)5 List (java.util.List)3 Color (java.awt.Color)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)1 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)1 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)1 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)1