Skip to content

Commit

Permalink
#2088 Selection Tool: fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantinEpam23 committed May 19, 2023
1 parent d41af8e commit 1e19987
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
3 changes: 2 additions & 1 deletion packages/ketcher-core/src/application/render/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ function defaultOptions(opt) {
},
hoverStyle: {
stroke: '#0097A8',
fill: '#CCFFDD',
fill: 'transparent',
fillSelected: '#CCFFDD',
'stroke-width': (0.6 * scaleFactor) / 20
},
sgroupBracketStyle: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,8 @@ class ReBond extends ReObject {
const regularSelectionThikness = doubleBondWidth + bondThickness

// half-bonds
const hbStart = restruct.molecule.halfBonds.get(bond.hb1!)
const hbEnd = restruct.molecule.halfBonds.get(bond.hb2!)

const halfBondStart = new Vec2(hbStart?.p.x, hbStart?.p.y)
const halfBondEnd = new Vec2(hbEnd?.p.x, hbEnd?.p.y)
const halfBondStart = restruct.molecule.halfBonds.get(bond.hb1!)!.p
const halfBondEnd = restruct.molecule.halfBonds.get(bond.hb2!)!.p

const isStereoBond =
bond.stereo !== Bond.PATTERN.STEREO.NONE &&
Expand Down Expand Up @@ -241,7 +238,7 @@ class ReBond extends ReObject {

const rect = this.getSelectionContour(render)

return rect.attr({ ...options.hoverStyle, fill: 'transparent' })
return rect.attr({ ...options.hoverStyle })
}

makeSelectionPlate(restruct: ReStruct, _: any, options: any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@ class ReObject {
this.visel = new Visel(viselType)
}

changeSelectionStyle(isHovering: boolean, options: any) {
const { selectionStyle, hoverStyle } = options
this.selectionPlate?.attr({
fill: isHovering ? hoverStyle.fill : selectionStyle.fill
})
changeSelectionStyle(options: any) {
const { hoverStyle } = options
this.hovering?.attr({
fill: this.selected ? hoverStyle.fill : 'transparent',
fill: this.selected ? hoverStyle.fillSelected : hoverStyle.fill,
'fill-opacity': this.selected ? 1 : 0
})
}
Expand Down Expand Up @@ -65,15 +62,15 @@ class ReObject {
}
}
if (noredraw) {
this.changeSelectionStyle(true, options)
this.changeSelectionStyle(options)
this.hovering.show()
} else {
render.paper.setStart()
this.drawHover(render)
this.hovering = render.paper.setFinish()
}
} else if (this.hovering) {
this.changeSelectionStyle(false, options)
this.changeSelectionStyle(options)
this.hovering.hide()
}

Expand Down
10 changes: 6 additions & 4 deletions packages/ketcher-core/src/domain/entities/vec2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,15 @@ export class Vec2 {
)
}

rotateAroundOrigin(angle: number, origin: Vec2) {
const angleRad = (angle * Math.PI) / 180
rotateAroundOrigin(angleInDegrees: number, origin: Vec2) {
const angleInRadians = (angleInDegrees * Math.PI) / 180
const offsetX = this.x - origin.x
const offsetY = this.y - origin.y

const rotatedX = Math.cos(angleRad) * offsetX - Math.sin(angleRad) * offsetY
const rotatedY = Math.sin(angleRad) * offsetX + Math.cos(angleRad) * offsetY
const rotatedX =
Math.cos(angleInRadians) * offsetX - Math.sin(angleInRadians) * offsetY
const rotatedY =
Math.sin(angleInRadians) * offsetX + Math.cos(angleInRadians) * offsetY

const x = rotatedX + origin.x
const y = rotatedY + origin.y
Expand Down

0 comments on commit 1e19987

Please sign in to comment.