static boolean handlesOverlap(final List<MutablePoint> handles) { if (handles.isEmpty()) return false; MutablePoint h1 = handles.get(0); for (MutablePoint h : handles) { if (h1.distanceSq(h) > 0) return false; } return true; }
@Override public PolygonROI requestNewHandle(double x, double y) { if (activeHandle == null) return roi; // Can only add if there is an active handle - distance to this will be used // Move the active handle if it is very close to the requested region // (removed) // Don't add a handle at almost the sample place as an existing handle if (handles.size() >= 2 && activeHandle == handles.get(handles.size() - 1) && handles.get(handles.size() - 2).distanceSq(x, y) < 4) { return roi; } // // If we have 2 points, which are identical, shift instead of creating // if (handles.size() >= 2 && activeHandle == handles.get(handles.size() - 1) && activeHandle.distanceSq(handles.get(handles.size() - 2)) < 0.000001) { // System.err.println("UPDATING HANDLE"); // return updateActiveHandleLocation(x, y, false); // } activeHandle = new MutablePoint(x, y); handles.add(activeHandle); roi = new PolygonROI(createPoint2List(handles), roi.getC(), roi.getZ(), roi.getT()); // System.out.println("UPDATED HANDLES BY REQUEST: " + handles.size()); return roi; }
/** * If a handle has been grabbed, update its displacement. * If minDisplacement is > 0, smaller movements will be discarded to avoid unnecessary work. * * @param x * @param y * @param minDisplacement * @param modifiers - from a MouseEvent - may optionally be used to control how the handle is modified * @return */ public ROI setActiveHandlePosition(double x, double y, double minDisplacement, boolean shiftDown) { // System.err.println("Set position: " + activeHandle); // Check if we have an active handle, or have moved it anything worth considering if (adjuster == null || (activeHandle != null && activeHandle.distanceSq(x, y) < minDisplacement*minDisplacement)) return pathROI; // setROI(adjuster.updateActiveHandleLocation(x, y, shiftDown), false); pathROI = adjuster.updateActiveHandleLocation(x, y, shiftDown); return pathROI; }
protected static int getClosestHandleIndex(List<MutablePoint> handles, double x, double y, double maxDist) { // Get the closest handle within maxDist pixels away double closestDist = Double.POSITIVE_INFINITY; double distSq = maxDist*maxDist; int activeHandleIndex = -1; int counter = 0; for (MutablePoint p : handles) { double dist = p.distanceSq(x, y); if (dist <= distSq && dist <= closestDist) { closestDist = dist; activeHandleIndex = counter; } counter++; } return activeHandleIndex; }
public double distanceSq(final MutablePoint point) { return distanceSq(point.getX(), point.getY()); }
/** * Notify the editor that translation should end. * * @param pathROI * @return true if there is any displacement between the current and starting translation points, false otherwise. */ public boolean finishTranslation() { boolean displacement = isTranslating && pTranslateOrigin.distanceSq(pTranslateCurrent) > 0; isTranslating = false; pTranslateOrigin = null; pTranslateCurrent = null; return displacement; }