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

#2088 Selection Tool: use rounded rectangles for selection of bonds and atom labels #2602

Conversation

KonstantinEpam23
Copy link
Collaborator

@KonstantinEpam23 KonstantinEpam23 commented May 15, 2023

Closes #2088

@KonstantinEpam23 KonstantinEpam23 self-assigned this May 15, 2023
@KonstantinEpam23 KonstantinEpam23 force-pushed the 2088-selection-tool-use-rounded-rectangles-for-selection-of-bonds-and-atom-labels branch from 51e7670 to 216c45b Compare May 16, 2023 09:15
@KonstantinEpam23 KonstantinEpam23 marked this pull request as ready for review May 17, 2023 08:15
@auto-assign auto-assign bot requested review from Nitvex and VasilevDO May 17, 2023 08:15
@KonstantinEpam23 KonstantinEpam23 force-pushed the 2088-selection-tool-use-rounded-rectangles-for-selection-of-bonds-and-atom-labels branch from 3c900d6 to 6ec58d3 Compare May 19, 2023 05:43
Copy link
Collaborator

@yuleicul yuleicul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @KonstantinEpam23 , almost everything looks good to me.
One thing I'm not sure about is the fill of circle when I'm adding a bond or an atom. I thought the fill would be none because I was just adding a new bond instead of hovering on a selected one. What's your take on this?

selection-01

Copy link
Collaborator

@yuleicul yuleicul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another issue is also about the fill of circle.

Scenario 1

Reproduction steps

  1. Click Bond Tool
  2. Click canvas to create a new bond
  3. Move slowly to the closest atom

Actual behavior

Fill of circle is light green

Expected behavior

Fill of circle would be none, because the atom was not selected

Scenario 2

Reproduction steps

  1. Click Bond Tool
  2. Click canvas to create a new bond
  3. Click Select Tool
  4. Move slowly to one of the atoms

Actual behavior

Fill of circle is light green

Expected behavior

Fill of circle is none, because the atom is not selected

selection-02

.circle(ps.x, ps.y, options.atomSelectionPlateRadius)
.attr(options.hoverStyle)

const result =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be we can move this repeating block to a separate function?


hb1.p = shiftBondEnd(atom1, p1, hb1.dir, 2 * options.lineWidth)
hb2.p = shiftBondEnd(atom2, p2, hb2.dir, 2 * options.lineWidth)
bond.b.center = Vec2.lc2(atom1.a.pp, 0.5, atom2.a.pp, 0.5)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be you can add a comment for lc2 (where it is defined)?
For me it is still a mystery, what it does.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nitvex I actually just moved the bondRecalc function so it is a static method now, its a bit of a mystery for myself what lc2 does 😄 I'll try to figure it out and a dd a comment

Copy link
Collaborator

@yuleicul yuleicul May 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KonstantinEpam23 @Nitvex I thought lc was the abbreviation of Linear Combination. The difference between lc() and lc2() was the number of arguments they could receive. lc() could combine lots of vectors, but lc2() could only combine 2 vectors, so functionality-wise lc2 could be replaced by lc.

const regularSelectionThikness = doubleBondWidth + bondThickness

// half-bonds
const hbStart = restruct.molecule.halfBonds.get(bond.hb1!)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be we can?

const halfBondStart = restruct.molecule.halfBonds.get(bond.hb1!).p // p at the end

@@ -221,6 +232,40 @@ export class Vec2 {
)
}

rotateAroundOrigin(angle: number, origin: Vec2) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be we can rename a angle param to something like angleInDegrees?

@KonstantinEpam23
Copy link
Collaborator Author

Another issue is also about the fill of circle.

Thx, good catch! Fixed.

@@ -24,7 +24,7 @@ function defaultOptions(opt) {
if (opt.rotationStep) utils.setFracAngle(opt.rotationStep)
Copy link
Collaborator Author

@KonstantinEpam23 KonstantinEpam23 May 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In options.js we just change the values to suit the new UX

@@ -57,18 +57,167 @@ class ReBond extends ReObject {
return true
}

static bondRecalc(bond: ReBond, restruct: ReStruct, options: any): void {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is just converted from member to static function, b/c we need to recalculate bond positions after they moved (it is used later in dropAndMerge.ts)

for (const bondId of bonds) {
const rebond = restruct.bonds.get(bondId)
if (rebond) {
ReBond.bondRecalc(rebond, restruct, editor.options())
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we add bond recalculation b/c without it the position values for halfBonds do not update

drawHover(render: Render) {
const ret = this.makeHoverPlate(render)
render.ctab.addReObjectPath(LayerMap.hovering, this.visel, ret)
return ret
}

getSelectionPoints(render: Render) {
const bond: Bond = this.b
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We render both regular and stereo bonds using the same SVG path, just with slightly different parameters.
Both bond types use two lines and two bezier curves to draw their paths:
Screenshot 2023-05-19 at 15 14 48

halfBondEnd,
-bondThickness * 2.5
)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2023-05-22 at 09 17 00

// rotate the points +/-90 degrees to find the
// perpendicular points that will be used for actual drawing
// of selection contour on canvas
const startTop = startPoint.rotateAroundOrigin(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2023-05-22 at 09 49 48

angle - 90,
contourPaddedEnd
)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hover_selection_exp

@KonstantinEpam23 KonstantinEpam23 merged commit c8f9479 into master May 22, 2023
@KonstantinEpam23 KonstantinEpam23 deleted the 2088-selection-tool-use-rounded-rectangles-for-selection-of-bonds-and-atom-labels branch May 22, 2023 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Selection Tool: use rounded rectangles for selection of bonds and atom labels
3 participants