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: #5753 - Fixed issue with tail normalization when moving #5806

Merged
merged 2 commits into from
Oct 18, 2024
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
11 changes: 11 additions & 0 deletions packages/ketcher-core/src/application/ketcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,17 @@ export class Ketcher {
return getStructure(format, this.#formatterFactory, this.#editor.struct());
}

getRdf(molfileFormat: MolfileFormat = 'v2000'): Promise<string> {
if (window.isPolymerEditorTurnedOn) {
throw new Error('RDF format is not available in macro mode');
}
const format =
molfileFormat === 'v2000'
? SupportedFormat.rdf
: SupportedFormat.rdfV3000;
return getStructure(format, this.#formatterFactory, this.#editor.struct());
}

getCDXml(): Promise<string> {
if (window.isPolymerEditorTurnedOn) {
throw new Error('CDXML format is not available in macro mode');
Expand Down
23 changes: 17 additions & 6 deletions packages/ketcher-core/src/domain/entities/multitailArrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,20 +481,27 @@ export class MultitailArrow extends BaseMicromoleculeEntity {
normalizeTailPosition(
proposedPosition: FixedPrecisionCoordinates,
tailId: number,
): FixedPrecisionCoordinates {
): FixedPrecisionCoordinates | null {
const proposedPositionFloatingPrecision =
proposedPosition.getFloatingPrecision();
const getDistanceToTailDistance = (tailDistance: TailDistance): number =>
Math.abs(tailDistance.center - proposedPositionFloatingPrecision) -
tailDistance.distance / 2;

const tailsWithoutCurrent = Array.from(this.tailsYOffset.entries())
.filter(([key]) => key !== tailId)
.map(([_, value]) => value);
const tailMinDistance = this.getTailsDistance(tailsWithoutCurrent)
.filter((item) => MultitailArrow.canAddTail(item.distance))
.sort(
(a, b) =>
Math.abs(a.center - proposedPositionFloatingPrecision) -
Math.abs(b.center - proposedPositionFloatingPrecision),
(a, b) => getDistanceToTailDistance(a) - getDistanceToTailDistance(b),
)
.at(0) as TailDistance;
.at(0);

if (!tailMinDistance) {
return null;
}

const positionCenter = FixedPrecisionCoordinates.fromFloatingPrecision(
tailMinDistance.center,
);
Expand Down Expand Up @@ -568,7 +575,11 @@ export class MultitailArrow extends BaseMicromoleculeEntity {
),
);
if (normalize) {
updatedHeight = this.normalizeTailPosition(updatedHeight, second);
const result = this.normalizeTailPosition(updatedHeight, second);
if (result === null) {
return originalValue.getFloatingPrecision();
}
updatedHeight = result;
}

const realOffset = updatedHeight.sub(originalValue);
Expand Down
Loading