Skip to content

Commit

Permalink
#2229 - rename pos0/pos1
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Permiakov committed Feb 16, 2023
1 parent 5d20ad8 commit 5d7e595
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions packages/ketcher-react/src/script/editor/tool/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ class TemplateTool {

const dragCtx = this.dragCtx
const ci = dragCtx.item
let pos0: Vec2 | null | undefined = null
const pos1 = this.editor.render.page2obj(event)
let targetPos: Vec2 | null | undefined = null
const eventPos = this.editor.render.page2obj(event)
const struct = restruct.molecule

/* moving when attached to bond */
if (ci && ci.map === 'bonds' && this.mode !== 'fg') {
const bond = struct.bonds.get(ci.id)
let sign = getSign(struct, bond, pos1)
let sign = getSign(struct, bond, eventPos)

if (dragCtx.sign1 * this.template.sign > 0) {
sign = -sign
Expand Down Expand Up @@ -296,21 +296,22 @@ class TemplateTool {
// calc initial pos and is extra bond needed
if (!ci) {
// ci.type == 'Canvas'
pos0 = dragCtx.xy0
targetPos = dragCtx.xy0
} else if (ci.map === 'atoms') {
pos0 = struct.atoms.get(ci.id)?.pp
targetPos = struct.atoms.get(ci.id)?.pp

if (pos0) {
extraBond = this.mode === 'fg' ? true : Vec2.dist(pos0, pos1) > 1
if (targetPos) {
extraBond =
this.mode === 'fg' ? true : Vec2.dist(targetPos, eventPos) > 1
}
}

if (!pos0) {
if (!targetPos) {
return true
}

// calc angle
let angle = utils.calcAngle(pos0, pos1)
let angle = utils.calcAngle(targetPos, eventPos)

if (!event.ctrlKey) {
angle = utils.fracAngle(angle, null)
Expand Down Expand Up @@ -432,12 +433,12 @@ class TemplateTool {
})

if (groupAttachmentAtomId !== null) {
const pos0 =
const targetPos =
this.editor.struct().atoms.get(groupAttachmentAtomId)?.pp ||
dragCtx.xy0
const pos1 = this.editor.render.page2obj(event)
const eventPos = this.editor.render.page2obj(event)

const dist = Vec2.dist(pos0, pos1)
const dist = Vec2.dist(targetPos, eventPos)
ci = { map: 'atoms', dist, id: groupAttachmentAtomId }
}
}
Expand Down

0 comments on commit 5d7e595

Please sign in to comment.