Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backmerge: #3970 - Brackets are displayed incorrectly when a S-Group is added to an atom or an expanded Functional Group or Salt is added to an atom of a structure #4063

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions packages/ketcher-core/src/application/render/restruct/resgroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
Pile,
SGroup,
Vec2,
Bond,
Struct,
} from 'domain/entities';
import { SgContexts } from 'application/editor/shared/constants';
Expand All @@ -40,7 +39,7 @@ interface SGroupdrawBracketsOptions {
set: any;
render: Render;
sgroup: SGroup;
crossBonds: { [key: number]: Array<Bond> };
crossBonds: { [key: number]: Array<number> };
atomSet: Pile;
bracketBox: Box2Abs;
direction: Vec2;
Expand Down Expand Up @@ -460,8 +459,8 @@ function drawAttachedDat(restruct: ReStruct, sgroup: SGroup): any {

function getBracketParameters(
atomSet: Pile,
crossBondsPerAtom: Array<Array<Bond>>,
crossBondsValues: Array<Bond>,
crossBondsPerAtom: Array<Array<number>>,
crossBondsValues: Array<number>,
attachmentPoints: number[],
bracketBox: Box2Abs,
direction: Vec2,
Expand Down Expand Up @@ -490,7 +489,7 @@ function getBracketParameters(
);
} else if (crossBondsValues.length === 2 && crossBondsPerAtom.length === 1) {
getBracketParamersWithCrossBondsMoreThan2OnOneAtom(
crossBondsValues,
crossBondsValues as [number, number],
mol,
attachmentPoints,
render,
Expand All @@ -514,7 +513,7 @@ function getBracketParameters(
}

function getBracketParamersWithCrossBondsMoreThan2OnOneAtom(
crossBondsValues: Bond[],
crossBondsValues: [number, number],
mol: Struct,
attachmentPoints: number[],
render: Render,
Expand All @@ -528,10 +527,12 @@ function getBracketParamersWithCrossBondsMoreThan2OnOneAtom(
// if bonds direction is clockwise, then negated
const needNegated =
Vec2.crossProduct(bondDirections[0], bondDirections[1]) > 0;
crossBondsValues = crossBondsValues.sort((id1, id2) => {
notTemplateShapeFirstAtom = Math.abs(Number(id1) - Number(id2)) === 1;
return notTemplateShapeFirstAtom && !needNegated ? -1 : 0;
});
notTemplateShapeFirstAtom =
Math.abs(Number(crossBondsValues[0]) - Number(crossBondsValues[1])) === 1;
if (notTemplateShapeFirstAtom && !needNegated) {
crossBondsValues.reverse();
}

for (let i = 0; i < crossBondsValues.length; ++i) {
const bond = mol.bonds.get(Number(crossBondsValues[i]));
let bondDirection = bond?.getDir(mol) || new Vec2();
Expand Down Expand Up @@ -577,7 +578,7 @@ function getBracketParamersWithCrossBondsMoreThan2OnOneAtom(

function getBracketParamersWithCrossBondsEquals2(
mol: Struct,
crossBondsValues: Bond[],
crossBondsValues: number[],
id: number,
render: Render,
attachmentPoints: number[],
Expand Down
8 changes: 4 additions & 4 deletions packages/ketcher-core/src/domain/entities/sgroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,9 @@ export class SGroup {
static getCrossBonds(
mol: any,
parentAtomSet: Pile<number>,
): { [key: number]: Array<Bond> } {
const crossBonds: { [key: number]: Array<Bond> } = {};
mol.bonds.forEach((bond, bid) => {
): { [key: number]: Array<number> } {
const crossBonds: { [key: number]: Array<number> } = {};
mol.bonds.forEach((bond, bid: number) => {
if (parentAtomSet.has(bond.begin) && !parentAtomSet.has(bond.end)) {
if (!crossBonds[bond.begin]) {
crossBonds[bond.begin] = [];
Expand All @@ -464,7 +464,7 @@ export class SGroup {
static bracketPos(
sGroup,
mol,
crossBondsPerAtom?: { [key: number]: Array<Bond> },
crossBondsPerAtom?: { [key: number]: Array<number> },
remol?: ReStruct,
render?,
): void {
Expand Down
Loading