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

#197 - attachment points should be within r group brackets #2935

Closed
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as utils from 'application/editor/actions/utils';

import { restruct, singleBond } from './data';
import { restruct, singleBond } from '../../../mock-data';
import { fromBondAddition } from 'application/editor/actions';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ReRGroup, ReStruct } from 'application/render/restruct';
import { restruct } from '../../../mock-data';
import { RGroup } from 'domain/entities';
import { mock, mockFn } from 'jest-mock-extended';
import { Render } from 'src';

describe('rergroup should calculate R-Group bounding box correctly', () => {
it('should calculate R-Group attachments points bounding box', () => {
const render = mock<Render>();
render.ctab = { ...restruct.molecule } as unknown as ReStruct;
const rGroup = new RGroup();
rGroup.frags.add(0);
const rerGroup = new ReRGroup(rGroup);
rerGroup.getAtoms = mockFn().mockReturnValue(restruct.molecule.atoms);
const attachmentsSpy = jest.spyOn(render.ctab, 'getAttachmentsPointsVBox');
rerGroup.calcBBox(render);
expect(attachmentsSpy).toHaveBeenCalled();
});
});
17 changes: 17 additions & 0 deletions packages/ketcher-core/__tests__/domain/entities/sgroup.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ReStruct } from 'application/render/restruct';
import { restruct } from '../../mock-data';
import { SGroup } from 'domain/entities';
import { mock } from 'jest-mock-extended';
import { Render } from 'src';

describe('sgroup should calculate S-Group bounding box correctly', () => {
it('should calculate S-Group attachments points bounding box', () => {
const render = mock<Render>();
render.ctab = { ...restruct.molecule } as unknown as ReStruct;
const sGroup = new SGroup('MUL');
sGroup.atoms = [0, 1, 2, 3, 4];
const attachmentsSpy = jest.spyOn(render.ctab, 'getAttachmentsPointsVBox');
SGroup.bracketPos(sGroup, restruct.molecule, {}, undefined, render);
expect(attachmentsSpy).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { ReAtom, ReBond } from 'application/render';

import { Pool } from 'domain/entities';
import { Box2Abs, Pool, Vec2 } from 'domain/entities';
import { mockFn } from 'jest-mock-extended';

const mockAtoms = [
{
Expand Down Expand Up @@ -634,6 +635,18 @@ const mockFrags = [
stereoFlagPosition: undefined,
enhancedStereoFlag: 'ABS',
updateStereoFlag() {},
calcBBox: mockFn().mockReturnValue({
p0: {
x: 4,
y: 6,
z: 0,
},
p1: {
x: 6,
y: 8,
z: 0,
},
}),
},
];
const frags = new Map();
Expand Down Expand Up @@ -680,11 +693,26 @@ const molecule = {
bondInitHalfBonds() {},
atomAddNeighbor() {},
setImplicitHydrogen() {},
getAttachmentsPointsVBox: mockFn().mockReturnValue(
new Box2Abs(
new Vec2({
x: 6,
y: 7,
z: 0,
}),
new Vec2({
x: 7,
y: 9,
z: 0,
}),
),
),
};

export const restruct = {
atoms: new Map(),
bonds: new Map(),
frags,
molecule,
connectedComponents: new Set(),
render: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ class ReRGroup extends ReObject {
: fragBox;
}
});

rGroupBoundingBox = rGroupBoundingBox
? rGroupBoundingBox.extend(BORDER_EXT, BORDER_EXT)
: rGroupBoundingBox;

let attachmentPointsVBox = render.ctab.getAttachmentsPointsVBox(
this.getAtoms(render),
);
Expand Down
19 changes: 15 additions & 4 deletions packages/ketcher-core/src/domain/entities/sgroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ export class SGroup {
remol?: ReStruct,
render?,
): void {
const BORDER_EXT = new Vec2(0.05 * 3, 0.05 * 3);
const PADDING_VECTOR = new Vec2(0.2, 0.4);
const atoms = sGroup.atoms;
const crossBonds = crossBondsPerAtom
? Object.values(crossBondsPerAtom).flat()
Expand All @@ -482,7 +484,6 @@ export class SGroup {
};
atoms.forEach((aid) => {
const atom = getAtom(aid);
const ext = new Vec2(0.05 * 3, 0.05 * 3);
let position;
let structBoundingBox;
if ('getVBoxObj' in atom && render) {
Expand All @@ -491,7 +492,7 @@ export class SGroup {
position = new Vec2(atom.pp);
structBoundingBox = new Box2Abs(position, position);
}
contentBoxes.push(structBoundingBox.extend(ext, ext));
contentBoxes.push(structBoundingBox.extend(BORDER_EXT, BORDER_EXT));
});
contentBoxes.forEach((bba) => {
let bbb: Box2Abs | null = null;
Expand All @@ -504,8 +505,18 @@ export class SGroup {
});
braketBox = !braketBox ? bbb : Box2Abs.union(braketBox, bbb!);
});
const vext = new Vec2(0.2, 0.4);
if (braketBox) braketBox = (braketBox as Box2Abs).extend(vext, vext);
if (!render) render = global._ui_editor.render;
let attachmentPointsVBox = render.ctab.getAttachmentsPointsVBox(atoms);
attachmentPointsVBox = attachmentPointsVBox
? attachmentPointsVBox.extend(BORDER_EXT, BORDER_EXT)
: attachmentPointsVBox;

braketBox =
attachmentPointsVBox && braketBox
? Box2Abs.union(attachmentPointsVBox, braketBox)
: braketBox;
if (braketBox)
braketBox = (braketBox as Box2Abs).extend(PADDING_VECTOR, PADDING_VECTOR);
sGroup.bracketBox = braketBox;
}

Expand Down