// calculate two points that are perpendicular to the highlighted bond
// and have a certain distance from the bond center
Point2d firstPoint = firstAtom.getPoint2d();
Point2d secondPoint = secondAtom.getPoint2d();
Vector2d diff = new Vector2d(secondPoint);
diff.sub(firstPoint);
double bondLength = firstPoint.distance(secondPoint);
double angle = GeometryTools.getAngle(diff.x, diff.y);
Point2d newPoint1 = new Point2d( // FIXME: what is this point??
(Math.cos(angle + (Math.PI / 2)) * bondLength / 4)
+ sharedAtomsCenter.x, (Math.sin(angle + (Math.PI / 2))
* bondLength / 4)
+ sharedAtomsCenter.y);
Point2d newPoint2 = new Point2d( // FIXME: what is this point??
(Math.cos(angle - (Math.PI / 2)) * bondLength / 4)
+ sharedAtomsCenter.x, (Math.sin(angle - (Math.PI / 2))
* bondLength / 4)
+ sharedAtomsCenter.y);
// decide on which side to draw the ring??
IAtomContainer connectedAtoms = bond.getBuilder().newInstance(IAtomContainer.class);
for (IAtom atom : sourceContainer.getConnectedAtomsList(firstAtom)) {
if (atom != secondAtom)
connectedAtoms.addAtom(atom);
}
for (IAtom atom : sourceContainer.getConnectedAtomsList(secondAtom)) {
if (atom != firstAtom)
connectedAtoms.addAtom(atom);
}
Point2d conAtomsCenter = GeometryTools.get2DCenter(connectedAtoms);
double distance1 = newPoint1.distance(conAtomsCenter);
double distance2 = newPoint2.distance(conAtomsCenter);
Vector2d ringCenterVector = new Vector2d(sharedAtomsCenter);
if (distance1 < distance2) {
ringCenterVector.sub(newPoint1);
} else { // distance2 <= distance1
ringCenterVector.sub(newPoint2);
}
// construct a new Ring that contains the highlighted bond an its two
// atoms
IRing newRing = createAttachRing(sharedAtoms, size, "C", phantom);