Skip to content

Commit 0a8528f

Browse files
committed
Only snap if > 50% bonds are aligned
1 parent f26add1 commit 0a8528f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

tool/sdg/src/main/java/org/openscience/cdk/layout/StructureDiagramGenerator.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -986,20 +986,22 @@ private static void calcDirectionHistogram(IAtomContainer mol,
986986
* @param widthDiff parameter at which to consider orientations equally good (wide select)
987987
* @param alignDiff parameter at which we consider orientations equally good (bond align select)
988988
*/
989-
private static void selectOrientation(IAtomContainer mol, double widthDiff, int alignDiff) {
989+
private void selectOrientation(IAtomContainer mol, double widthDiff, int alignDiff) {
990990

991991
int[] dirhist = new int[180];
992992
double[] minmax = GeometryUtil.getMinMax(mol);
993993
Point2d pivot = new Point2d(minmax[0] + ((minmax[2] - minmax[0]) / 2),
994994
minmax[1] + ((minmax[3] - minmax[1]) / 2));
995995

996-
// initial alignment to 60 degrees
996+
// initial alignment to snapping bonds 60 degrees
997997
calcDirectionHistogram(mol, dirhist, 60);
998998
int max = 0;
999999
for (int i = 1; i < dirhist.length; i++)
10001000
if (dirhist[i] > dirhist[max])
10011001
max = i;
1002-
if (max != 0)
1002+
// only apply if 50% of the bonds are pointing the same 'wrapped'
1003+
// direction, max=0 means already aligned
1004+
if (max != 0 && dirhist[max]/(double)mol.getBondCount() > 0.5)
10031005
GeometryUtil.rotate(mol, pivot, Math.toRadians(60-max));
10041006

10051007
double maxWidth = minmax[2] - minmax[0];

0 commit comments

Comments
 (0)