Skip to content

Update math.getOffset algorithm to better align with spec #4119

@straker

Description

@straker

As part of #4117 we determined that the math.getOffset calculation is not correct and needs to be updated. It didn't produce any false-positives so we decided to update the code in another pr in order to get 4.8 out the door.

The algorithm should be as follows:

For targets with target size >= 24x24px, we should make sure we skip the (potentially expensive) offset calculation since the spacing exception isn't relevant. Target size === largest unobscured rect from math.splitRects. E.g. the result of calling dom.getTargetSize.

Otherwise, for undersized targets:

  1. determine bounding rect of target and get the center (we'll call centerTarget). Bounding rect === the result of calling math.getBoundingRect for each rect in splitRects. (should be a new function)
  2. determine the target's "neighbors" using grid (any other target that might be within 24px of any part of target's bounding rect is a neighbor)
  3. for each neighbor:
    1. determine neighborSplitRects using math.splitRects(neighbor)
    2. for each neighborSplitRect:
      1. calculate distance from centerTarget to the nearest point in neighborSplitRect (may be 0 if centerTarget lies within neighborSplitRect)
    3. let neighborSpacing be the minimum neighborSplitRect distance
    4. if the neighbor is also undersized (target size < 24x24px):
      1. calculate centerNeighbor similarly to centerTarget using the neighbor's bounding box
      2. if the distance from centerTarget to centerNeighbor is < neighborSpacing, use that as the new neighborSpacing
  4. return the minimum neighborSpacing from among all neighbors

Metadata

Metadata

Assignees

No one assigned

    Labels

    prA pr has been created for the issuetech debtTechnical debt related tasks

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions