Skip to content

Commit

Permalink
#1990 - Detect if group is attached to smth + get attachment atom
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Permiakov authored and Stanislav Permiakov committed Feb 16, 2023
1 parent 5d7e000 commit 3075830
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/ketcher-core/src/domain/entities/sgroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,23 @@ export class SGroup {
this.pp = topLeftPoint
}

getAttAtomId(struct: Struct): number {
for (const atomId of this.atoms) {
const atom = struct.atoms.get(atomId)
if (!atom) continue
if (Number.isInteger(atom.attpnt)) return atomId
}
// in normal circumstances this should never be invoked
return this.atoms[0]
}

isGroupAttached(struct: Struct): boolean {
const attachPointId = this.getAttAtomId(struct)
const neighbours = struct.atomGetNeighbors(attachPointId)

return !!neighbours?.every(({ aid }) => this.atoms.includes(aid))
}

static getOffset(sgroup: SGroup): null | Vec2 {
if (!sgroup?.pp) return null
return Vec2.diff(sgroup.pp, sgroup.bracketBox.p1)
Expand Down

0 comments on commit 3075830

Please sign in to comment.