From: <gil...@us...> - 2009-02-06 13:09:56
|
Revision: 14086 http://cdk.svn.sourceforge.net/cdk/?rev=14086&view=rev Author: gilleain Date: 2009-02-06 13:09:51 +0000 (Fri, 06 Feb 2009) Log Message: ----------- Testing for highlight distance was happening in two places, and not scaled correctly either. Modified Paths: -------------- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/ControllerHub.java cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/HighlightModule.java Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/ControllerHub.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/ControllerHub.java 2009-02-06 12:47:11 UTC (rev 14085) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/ControllerHub.java 2009-02-06 13:09:51 UTC (rev 14086) @@ -281,38 +281,35 @@ IAtom closestAtom = null; double closestDistance = Double.MAX_VALUE; - Iterator<IAtomContainer> containers = ChemModelManipulator.getAllAtomContainers(chemModel).iterator(); - while (containers.hasNext()) { - Iterator<IAtom> atoms = containers.next().atoms().iterator(); - while (atoms.hasNext()) { - IAtom nextAtom = atoms.next(); - double distance = nextAtom.getPoint2d().distance(worldCoord); - if (distance <= renderer.getRenderer2DModel().getHighlightRadiusModel() && - distance < closestDistance) { - closestAtom = nextAtom; + for (IAtomContainer atomContainer : + ChemModelManipulator.getAllAtomContainers(chemModel)) { + + for (IAtom atom : atomContainer.atoms()) { + double distance = atom.getPoint2d().distance(worldCoord); + if (distance < closestDistance) { + closestAtom = atom; closestDistance = distance; } } } + return closestAtom; } public IBond getClosestBond(Point2d worldCoord) { IBond closestBond = null; double closestDistance = Double.MAX_VALUE; - - Iterator<IAtomContainer> containers = ChemModelManipulator.getAllAtomContainers(chemModel).iterator(); - while (containers.hasNext()) { - Iterator<IBond> bonds = containers.next().bonds().iterator(); - while (bonds.hasNext()) { - IBond nextBond = bonds.next(); - double distance = nextBond.get2DCenter().distance(worldCoord); - if (distance <= renderer.getRenderer2DModel().getHighlightRadiusModel() && - distance < closestDistance) { - closestBond = nextBond; - closestDistance = distance; - } - } + + for (IAtomContainer atomContainer : + ChemModelManipulator.getAllAtomContainers(chemModel)) { + + for (IBond bond : atomContainer.bonds()) { + double distance = bond.get2DCenter().distance(worldCoord); + if (distance < closestDistance) { + closestBond = bond; + closestDistance = distance; + } + } } return closestBond; } Modified: cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/HighlightModule.java =================================================================== --- cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/HighlightModule.java 2009-02-06 12:47:11 UTC (rev 14085) +++ cdk/branches/jchempaint-primary/src/main/org/openscience/cdk/controller/HighlightModule.java 2009-02-06 13:09:51 UTC (rev 14086) @@ -83,33 +83,33 @@ IBond bond = chemObjectRelay.getClosestBond(worldCoord); RendererModel model = chemObjectRelay.getRenderer().getRenderer2DModel(); + double dH = model.getHighlightDistance() / model.getScale(); if (atom != null && bond != null) { double dA = atom.getPoint2d().distance(worldCoord); double dB = bond.get2DCenter().distance(worldCoord); - if (dA > model.getHighlightRadiusModel() && - dB > model.getHighlightRadiusModel()) { + if (dA > dH && dB > dH) { unsetHighlights(model); return; // done } // highlight atom or bond, which ever is closer - if (dA < dB && dA < model.getHighlightRadiusModel()) { + if (dA < dB && dA < dH) { // atom closest updateAtom(atom, model); - } else if (dB < model.getHighlightRadiusModel()) { + } else if (dB < dH) { // bond closest updateBond(bond, model); } } else if (atom != null) { // atom is only closest, but in range? double dA = atom.getPoint2d().distance(worldCoord); - if (dA < model.getHighlightRadiusModel()) + if (dA < dH) updateAtom(atom, model); } else if (bond != null) { // bond is only closest, but in range? double dB = bond.get2DCenter().distance(worldCoord); - if (dB < model.getHighlightRadiusModel()) + if (dB < dH) updateBond(bond, model); } else { // nothing nearby This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |