Search in sources :

Example 1 with Bounds

use of com.google.maps.android.geometry.Bounds in project cw-omnibus by commonsguy.

the class PointQuadTreeTest method testVeryDeepTree.

public void testVeryDeepTree() {
    for (int i = 0; i < 3000; i++) {
        mTree.add(new Item(0, 0));
    }
    assertEquals(3000, searchAll().size());
    assertEquals(3000, mTree.search(new Bounds(0, .1, 0, .1)).size());
    assertEquals(0, mTree.search(new Bounds(.1, 1, .1, 1)).size());
}
Also used : Bounds(com.google.maps.android.geometry.Bounds) Point(com.google.maps.android.geometry.Point)

Example 2 with Bounds

use of com.google.maps.android.geometry.Bounds in project cw-omnibus by commonsguy.

the class PointQuadTreeTest method testSearch.

public void testSearch() {
    for (int i = 0; i < 1000; i++) {
        mTree.add(new Item(i / 2000.0, i / 2000.0));
    }
    assertEquals(1000, searchAll().size());
    assertEquals(1, mTree.search(new Bounds((double) 0, 0.0001, (double) 0, 0.0001)).size());
    assertEquals(0, mTree.search(new Bounds(.7, .8, .7, .8)).size());
}
Also used : Bounds(com.google.maps.android.geometry.Bounds) Point(com.google.maps.android.geometry.Point)

Example 3 with Bounds

use of com.google.maps.android.geometry.Bounds in project android-maps-utils by googlemaps.

the class UtilTest method testGetBounds.

public void testGetBounds() {
    /*
        y
        ^
        |  3
        |     1
        |        2
        ------------> x
         */
    ArrayList<WeightedLatLng> data = new ArrayList<WeightedLatLng>();
    WeightedLatLng first = new WeightedLatLng(new LatLng(10, 20));
    data.add(first);
    double x1 = first.getPoint().x;
    double y1 = first.getPoint().y;
    Bounds bounds = HeatmapTileProvider.getBounds(data);
    Bounds expected = new Bounds(x1, x1, y1, y1);
    assertTrue(bounds.contains(expected) && expected.contains(bounds));
    WeightedLatLng second = new WeightedLatLng(new LatLng(20, 30));
    data.add(second);
    double x2 = second.getPoint().x;
    double y2 = second.getPoint().y;
    bounds = HeatmapTileProvider.getBounds(data);
    expected = new Bounds(x1, x2, y2, y1);
    assertTrue(bounds.contains(expected) && expected.contains(bounds));
    WeightedLatLng third = new WeightedLatLng(new LatLng(5, 10));
    data.add(third);
    double x3 = third.getPoint().x;
    double y3 = third.getPoint().y;
    bounds = HeatmapTileProvider.getBounds(data);
    expected = new Bounds(x3, x2, y2, y3);
    assertTrue(bounds.contains(expected) && expected.contains(bounds));
}
Also used : Bounds(com.google.maps.android.geometry.Bounds) ArrayList(java.util.ArrayList) LatLng(com.google.android.gms.maps.model.LatLng)

Example 4 with Bounds

use of com.google.maps.android.geometry.Bounds in project android-maps-utils by googlemaps.

the class PointQuadTreeTest method testFourPoints.

public void testFourPoints() {
    mTree.add(new Item(0.2, 0.2));
    mTree.add(new Item(0.7, 0.2));
    mTree.add(new Item(0.2, 0.7));
    mTree.add(new Item(0.7, 0.7));
    assertEquals(2, mTree.search(new Bounds(0.0, 0.5, 0.0, 1.0)).size());
}
Also used : Bounds(com.google.maps.android.geometry.Bounds)

Example 5 with Bounds

use of com.google.maps.android.geometry.Bounds in project android-maps-utils by googlemaps.

the class NonHierarchicalDistanceBasedAlgorithm method getClusters.

@Override
public Set<? extends Cluster<T>> getClusters(double zoom) {
    final int discreteZoom = (int) zoom;
    final double zoomSpecificSpan = MAX_DISTANCE_AT_ZOOM / Math.pow(2, discreteZoom) / 256;
    final Set<QuadItem<T>> visitedCandidates = new HashSet<QuadItem<T>>();
    final Set<Cluster<T>> results = new HashSet<Cluster<T>>();
    final Map<QuadItem<T>, Double> distanceToCluster = new HashMap<QuadItem<T>, Double>();
    final Map<QuadItem<T>, StaticCluster<T>> itemToCluster = new HashMap<QuadItem<T>, StaticCluster<T>>();
    synchronized (mQuadTree) {
        for (QuadItem<T> candidate : mItems) {
            if (visitedCandidates.contains(candidate)) {
                // Candidate is already part of another cluster.
                continue;
            }
            Bounds searchBounds = createBoundsFromSpan(candidate.getPoint(), zoomSpecificSpan);
            Collection<QuadItem<T>> clusterItems;
            clusterItems = mQuadTree.search(searchBounds);
            if (clusterItems.size() == 1) {
                // Only the current marker is in range. Just add the single item to the results.
                results.add(candidate);
                visitedCandidates.add(candidate);
                distanceToCluster.put(candidate, 0d);
                continue;
            }
            StaticCluster<T> cluster = new StaticCluster<T>(candidate.mClusterItem.getPosition());
            results.add(cluster);
            for (QuadItem<T> clusterItem : clusterItems) {
                Double existingDistance = distanceToCluster.get(clusterItem);
                double distance = distanceSquared(clusterItem.getPoint(), candidate.getPoint());
                if (existingDistance != null) {
                    // Item already belongs to another cluster. Check if it's closer to this cluster.
                    if (existingDistance < distance) {
                        continue;
                    }
                    // Move item to the closer cluster.
                    itemToCluster.get(clusterItem).remove(clusterItem.mClusterItem);
                }
                distanceToCluster.put(clusterItem, distance);
                cluster.add(clusterItem.mClusterItem);
                itemToCluster.put(clusterItem, cluster);
            }
            visitedCandidates.addAll(clusterItems);
        }
    }
    return results;
}
Also used : HashMap(java.util.HashMap) Bounds(com.google.maps.android.geometry.Bounds) Cluster(com.google.maps.android.clustering.Cluster) Point(com.google.maps.android.geometry.Point) HashSet(java.util.HashSet)

Aggregations

Bounds (com.google.maps.android.geometry.Bounds)10 Point (com.google.maps.android.geometry.Point)7 ArrayList (java.util.ArrayList)2 Bitmap (android.graphics.Bitmap)1 LatLng (com.google.android.gms.maps.model.LatLng)1 Cluster (com.google.maps.android.clustering.Cluster)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1