* @param mode Input mode
* @param p1 first point of the selected rectangle
* @param p2 second point of the selected rectangle
*/
private void updateSelection(Mode mode, SVGPoint p1, SVGPoint p2) {
DBIDSelection selContext = context.getSelection();
// Note: we rely on SET semantics below!
final HashSetModifiableDBIDs selection;
if(selContext == null || mode == Mode.REPLACE) {
selection = DBIDUtil.newHashSet();
}
else {
selection = DBIDUtil.newHashSet(selContext.getSelectedIds());
}
int[] axisrange = getAxisRange(Math.min(p1.getX(), p2.getX()), Math.max(p1.getX(), p2.getX()));
for(DBID objId : relation.iterDBIDs()) {
double[] yPos = proj.fastProjectDataToRenderSpace(relation.get(objId));
if(checkSelected(axisrange, yPos, Math.max(p1.getX(), p2.getX()), Math.min(p1.getX(), p2.getX()), Math.max(p1.getY(), p2.getY()), Math.min(p1.getY(), p2.getY()))) {
if(mode == Mode.INVERT) {
if(!selection.contains(objId)) {
selection.add(objId);
}
else {
selection.remove(objId);
}
}
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(objId);
}
}
}
context.setSelection(new DBIDSelection(selection));
}