Skip to content

Commit

Permalink
#3469 fix bond path and attachmentpoint direction
Browse files Browse the repository at this point in the history
  • Loading branch information
StarlaStarla committed Nov 8, 2023
1 parent 7df38b1 commit 15a9265
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,26 @@ export class PolymerBondRenderer extends BaseRenderer {
);
}

private updateSnakeBondPath(startPosition, endPosition) {
private updateSnakeBondPath(
startPosition: Vec2,
endPosition: Vec2,
reCheckAttachmentpoint = true,
) {
const isR1TheCurrentAttachmentpointOfFirstMonomer =
this.polymerBond.firstMonomer.getAttachmentPointByBond(
this.polymerBond,
) === 'R1' ||
this.polymerBond.firstMonomer.getPotentialAttachmentPointByBond(
this.polymerBond,
) === 'R1';
if (this.isSecondMonomerBottomRight(startPosition, endPosition)) {
if (
isR1TheCurrentAttachmentpointOfFirstMonomer &&
reCheckAttachmentpoint
) {
this.updateSnakeBondPath(endPosition, startPosition, false);
return;
}
this.addLine(
LINE_DIRECTION.Horizontal,
LINE_FROM_MONOMER_LENGTH + this.getMonomerWidth() / 2,
Expand Down Expand Up @@ -210,6 +228,13 @@ export class PolymerBondRenderer extends BaseRenderer {
this.getMonomerWidth() / 2,
);
} else if (this.isSecondMonomerBottomLeft(startPosition, endPosition)) {
if (
isR1TheCurrentAttachmentpointOfFirstMonomer &&
reCheckAttachmentpoint
) {
this.updateSnakeBondPath(endPosition, startPosition, false);
return;
}
this.addLine(
LINE_DIRECTION.Horizontal,
LINE_FROM_MONOMER_LENGTH + this.getMonomerWidth() / 2,
Expand Down Expand Up @@ -241,6 +266,13 @@ export class PolymerBondRenderer extends BaseRenderer {
LINE_FROM_MONOMER_LENGTH + this.getMonomerWidth() / 2,
);
} else if (this.isSecondMonomerTopLeft(startPosition, endPosition)) {
if (
isR1TheCurrentAttachmentpointOfFirstMonomer &&
reCheckAttachmentpoint
) {
this.updateSnakeBondPath(endPosition, startPosition, false);
return;
}
this.addLine(
LINE_DIRECTION.Horizontal,
LINE_FROM_MONOMER_LENGTH + this.getMonomerWidth() / 2,
Expand Down
4 changes: 2 additions & 2 deletions packages/ketcher-core/src/domain/AttachmentPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class AttachmentPoint {
this.monomer.id ===
this.monomer.attachmentPointsToBonds[this.attachmentPointName]
?.firstMonomer?.id;

const isAttachmentpointR1 = this.attachmentPointName === 'R1';
if (!this.isUsed) {
angleDegrees = this.initialAngle;
} else if (
Expand All @@ -140,7 +140,7 @@ export class AttachmentPoint {
this.attachmentPointName
]?.renderer.isMonomersOnSameHorizontalLine()
) {
angleRadians = flip ? Math.PI : 0;
angleRadians = isAttachmentpointR1 ? 0 : Math.PI;
angleDegrees = Vec2.radiansToDegrees(angleRadians);
} else {
const angleRadians = this.rotateToAngle(
Expand Down

0 comments on commit 15a9265

Please sign in to comment.