Commit a1447453 authored by Luna Riegel's avatar Luna Riegel
Browse files

Feat: Implement getCandidates

parent 09ecf2bf
......@@ -22,6 +22,8 @@ public interface CityObjectCache {
*/
CityObject get(GmlId id);
Collection<CityObject> getCandidates(CityObject subject, double collectionRadius);
Collection<CityObject> getAll(List<GmlId> ids);
/**
......
......@@ -119,6 +119,12 @@ public class FeatureCache implements CityObjectCache{
return cache.get(id);
}
@Override
public Collection<CityObject> getCandidates(CityObject subject, double collectionRadius){
List<GmlId> ids = handler.getBufferCollisionCandidates(subject, collectionRadius);
return this.getAll(ids);
}
@Override
public Collection<CityObject> getAll(List<GmlId> ids){
Map<GmlId, CityObject> map = cache.getAll(new HashSet<>(ids));
......
......@@ -38,6 +38,19 @@ public class UnconnectedCache implements CityObjectCache{
return cache.get(id);
}
@Override
public Collection<CityObject> getCandidates(CityObject subject, double collectionRadius) {
List<CityObject> candidates = new ArrayList<>();
// Quick and dirty candidate selection
cache.forEach((gmlId, cityObject) -> {
double distance = cityObject.getBbox().getCenter().getDistance(subject.getBbox().getCenter());
if (distance - cityObject.getBbox().getLongestSide() - subject.getBbox().getLongestSide() < collectionRadius){
candidates.add(cityObject);
}
});
return candidates;
}
@Override
public Collection<CityObject> getAll(List<GmlId> ids) {
return ids.stream().map(cache::get).toList();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment