use of org.activityinfo.legacy.shared.reports.content.Point in project activityinfo by bedatadriven.
the class CircleMathTest method testCompletelyContained.
@Test
public void testCompletelyContained() {
Point a = new Point(297, 212);
Point b = new Point(295, 213);
Assert.assertEquals(CircleMath.area(5), CircleMath.intersectionArea(a, b, 8, 5), DELTA);
}
use of org.activityinfo.legacy.shared.reports.content.Point in project activityinfo by bedatadriven.
the class TileMath method tileBounds.
public static Extents tileBounds(int zoom, int x, int y) {
Point upperLeft = pointForTile(new Tile(x, y));
Point lowerRight = pointForTile(new Tile(x + 1, y + 1));
AiLatLng northWest = inverse(upperLeft, zoom);
AiLatLng southEast = inverse(lowerRight, zoom);
return new Extents(southEast.getLat(), northWest.getLat(), northWest.getLng(), southEast.getLng());
}
use of org.activityinfo.legacy.shared.reports.content.Point in project activityinfo by bedatadriven.
the class TileMathTest method inverse.
@Test
public void inverse() {
AiLatLng latlng = new AiLatLng(15, 30);
Point px = TileMath.fromLatLngToPixel(latlng, 6);
AiLatLng inverse = TileMath.inverse(px, 6);
assertThat("longitude", inverse.getLng(), equalTo(latlng.getLng()));
assertThat("latitude", inverse.getLat(), closeTo(latlng.getLat(), 0.0001));
}
use of org.activityinfo.legacy.shared.reports.content.Point in project activityinfo by bedatadriven.
the class IconLayerGenerator method generate.
@Override
public void generate(TiledMap map, MapContent content) {
List<PointValue> points = new ArrayList<PointValue>();
IconRectCalculator rectCalculator = new IconRectCalculator(icon);
IntersectionCalculator intersectionCalculator = new IntersectionCalculator() {
@Override
public boolean intersects(Node a, Node b) {
return a.getPointValue().getIconRect().intersects(b.getPointValue().getIconRect());
}
};
Clusterer clusterer = ClustererFactory.fromClustering(layer.getClustering(), rectCalculator, intersectionCalculator);
for (SiteDTO site : sites) {
if (meetsCriteria(site)) {
AiLatLng geoPoint = getPoint(site);
if (geoPoint != null || clusterer.isMapped(site)) {
Point point = null;
if (geoPoint != null) {
point = map.fromLatLngToPixel(geoPoint);
}
points.add(new PointValue(site, point, point == null ? null : rectCalculator.iconRect(point), getValue(site, layer.getIndicatorIds())));
} else {
content.getUnmappedSites().add(site.getId());
}
}
}
List<Cluster> clusters = clusterer.cluster(map, points);
createMarkersFrom(clusters, map, content);
IconLayerLegend legend = new IconLayerLegend();
legend.setDefinition(layer);
content.addLegend(legend);
}
use of org.activityinfo.legacy.shared.reports.content.Point in project activityinfo by bedatadriven.
the class KMeans method computeCenters.
/**
* Computes the centers of the assigned clusters
*
* @param nodes The list of nodes
* @param membership An array containing the cluster membership for each node
* @param centers Array of center points to update
*/
private static void computeCenters(List<MarkerGraph.Node> nodes, int[] membership, Point[] centers) {
int[] sumX = new int[centers.length];
int[] sumY = new int[centers.length];
int[] counts = new int[centers.length];
for (int i = 0; i != nodes.size(); ++i) {
Point point = nodes.get(i).getPoint();
sumX[membership[i]] += point.getX();
sumY[membership[i]] += point.getY();
counts[membership[i]]++;
}
for (int i = 0; i != centers.length; ++i) {
if (counts[i] > 0) {
centers[i] = new Point(sumX[i] / counts[i], sumY[i] / counts[i]);
}
}
}
Aggregations