Skip to content

Commit

Permalink
Small fix for adjusting double bonds to be flush with extreme angles …
Browse files Browse the repository at this point in the history
…- we don't adust more than half the bond length.
  • Loading branch information
johnmay committed Sep 11, 2015
1 parent f2a0839 commit 8f10844
Showing 1 changed file with 9 additions and 0 deletions.
Expand Up @@ -804,6 +804,7 @@ private IRenderingElement generateCenteredDoubleBond(IBond bond, IAtom atom1, IA
final Vector2d perpendicular1 = newPerpendicularVector(unit);
final Vector2d perpendicular2 = negate(perpendicular1);

final double halfBondLength = atom1BackOffPoint.distance(atom2BackOffPoint) / 2;
final double halfSeparation = separation / 2;

ElementGroup group = new ElementGroup();
Expand All @@ -821,6 +822,10 @@ private IRenderingElement generateCenteredDoubleBond(IBond bond, IAtom atom1, IA
double line1Adjust = adjacentLength(nearest1, perpendicular1, halfSeparation);
double line2Adjust = adjacentLength(nearest2, perpendicular2, halfSeparation);

// don't adjust beyond half the bond length
if (line1Adjust > halfBondLength) line1Adjust = 0;
if (line2Adjust > halfBondLength) line2Adjust = 0;

// corner case when the adjacent bonds are acute to the double bond,
if (nearest1.dot(unit) > 0) line1Adjust = -line1Adjust;
if (nearest2.dot(unit) > 0) line2Adjust = -line2Adjust;
Expand All @@ -837,6 +842,10 @@ private IRenderingElement generateCenteredDoubleBond(IBond bond, IAtom atom1, IA
double line1Adjust = adjacentLength(nearest1, perpendicular1, halfSeparation);
double line2Adjust = adjacentLength(nearest2, perpendicular2, halfSeparation);

// don't adjust beyond half the bond length
if (line1Adjust > halfBondLength) line1Adjust = 0;
if (line2Adjust > halfBondLength) line2Adjust = 0;

// corner case when the adjacent bonds are acute to the double bond
if (nearest1.dot(unit) < 0) line1Adjust = -line1Adjust;
if (nearest2.dot(unit) < 0) line2Adjust = -line2Adjust;
Expand Down

0 comments on commit 8f10844

Please sign in to comment.