* @param proj
* @param p1 first point of the selected rectangle
* @param p2 second point of the selected rectangle
*/
private void updateSelection(Mode mode, Projection2D proj, SVGPoint p1, SVGPoint p2) {
DBIDSelection selContext = context.getSelection();
// Note: we rely on SET semantics below!
HashSetModifiableDBIDs selection;
if(selContext == null || mode == Mode.REPLACE) {
selection = DBIDUtil.newHashSet();
}
else {
selection = DBIDUtil.newHashSet(selContext.getSelectedIds());
}
for(DBID id : rel.iterDBIDs()) {
double[] vec = proj.fastProjectDataToRenderSpace(rel.get(id));
if(vec[0] >= Math.min(p1.getX(), p2.getX()) && vec[0] <= Math.max(p1.getX(), p2.getX()) && vec[1] >= Math.min(p1.getY(), p2.getY()) && vec[1] <= Math.max(p1.getY(), p2.getY())) {
if(mode == Mode.INVERT) {
if(!selection.contains(id)) {
selection.add(id);
}
else {
selection.remove(id);
}
}
else {
// In REPLACE and ADD, add objects.
// The difference was done before by not re-using the selection.
// Since we are using a set, we can just add in any case.
selection.add(id);
}
}
}
context.setSelection(new DBIDSelection(selection));
}