Skip to content

Commit

Permalink
Ensure hashed wedges are not streched for abnormal bond lengths.
Browse files Browse the repository at this point in the history
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Sep 2, 2014
1 parent 968cb50 commit f731cf1
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.openscience.cdk.renderer.elements.path.Close;
import org.openscience.cdk.renderer.elements.path.LineTo;
import org.openscience.cdk.renderer.elements.path.MoveTo;
import org.openscience.cdk.renderer.generators.BasicSceneGenerator;
import org.openscience.cdk.tools.ILoggingTool;
import org.openscience.cdk.tools.LoggingToolFactory;
import org.openscience.cdk.tools.manipulator.AtomContainerSetManipulator;
Expand Down Expand Up @@ -100,6 +101,7 @@ final class StandardBondGenerator {
private final Map<IBond, IAtomContainer> ringMap;

// parameters
private final double scale;
private final double stroke;
private final double separation;
private final double backOff;
Expand Down Expand Up @@ -130,6 +132,7 @@ private StandardBondGenerator(IAtomContainer container, AtomSymbol[] symbols, Re
ringMap = ringPreferenceMap(container);

// set parameters
this.scale = parameters.get(BasicSceneGenerator.Scale.class);
this.stroke = stroke;
this.separation = parameters.get(StandardGenerator.SeparationRatio.class) * stroke;
this.backOff = parameters.get(StandardGenerator.SymbolMarginRatio.class) * stroke;
Expand Down Expand Up @@ -364,12 +367,18 @@ IRenderingElement generateHashedWedgeBond(IAtom from, IAtom to, List<IBond> toBo
final double halfWideEnd = wedgeWidth / 2;

final double opposite = halfWideEnd - halfNarrowEnd;
final double adjacent = fromPoint.distance(toPoint);
double adjacent = fromPoint.distance(toPoint);

final boolean longBond = (adjacent * scale) - parameters.get(BasicSceneGenerator.BondLength.class) > 4;

// we subtract one due to fenceposts, this ensures the specified number
// of hashed sections is drawn
final double step = adjacent / (hatchSections - 1);
final double expectedStep = (parameters.get(BasicSceneGenerator.BondLength.class) / scale) / (hatchSections - 1);


final int nSections = longBond ? 1 + (int) Math.ceil(adjacent / expectedStep) : hatchSections;
final double step = adjacent / (nSections - 1);

final ElementGroup group = new ElementGroup();

final double start = hasDisplayedSymbol(from) ? fromPoint.distance(fromBackOffPoint)
Expand All @@ -384,7 +393,7 @@ IRenderingElement generateHashedWedgeBond(IAtom from, IAtom to, List<IBond> toBo
Vector2d hatchAngle = perpendicular;

// fancy hashed wedges with slanted hatch sections aligned with neighboring bonds
if (fancyHashedWedges && !hasDisplayedSymbol(to)) {
if (fancyHashedWedges && !longBond && !hasDisplayedSymbol(to)) {
if (toBonds.size() == 1) {
final IBond toBondNeighbor = toBonds.get(0);
final IAtom toNeighbor = toBondNeighbor.getConnectedAtom(to);
Expand All @@ -405,7 +414,7 @@ IRenderingElement generateHashedWedgeBond(IAtom from, IAtom to, List<IBond> toBo
}
}

for (int i = 0; i < hatchSections; i++) {
for (int i = 0; i < nSections; i++) {
final double distance = i * step;

// don't draw if we're within an atom symbol
Expand Down

0 comments on commit f731cf1

Please sign in to comment.