Skip to content

Commit

Permalink
Merge pull request #1611 from ag-grid/AG-NONE/fix_hittesting_rounded_…
Browse files Browse the repository at this point in the history
…rect

AG-NONE Fix hit-testing on rounded Rect shapes
  • Loading branch information
AG-DavidG authored May 23, 2024
2 parents 1e71e17 + 8cea0bf commit 855c947
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions packages/ag-charts-community/src/scene/shape/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@ export class Path extends Shape implements DistantObject {

distanceSquared(x: number, y: number): number {
const point = this.transformPoint(x, y);
if (this.path.closedPath && this.path.isPointInPath(point.x, point.y)) {
return this.distanceSquaredTransformedPoint(point.x, point.y);
}

protected distanceSquaredTransformedPoint(x: number, y: number): number {
if (this.path.closedPath && this.path.isPointInPath(x, y)) {
return 0;
}
return this.path.distanceSquared(point.x, point.y);
return this.path.distanceSquared(x, y);
}

protected isDirtyPath(): boolean {
Expand Down
4 changes: 2 additions & 2 deletions packages/ag-charts-community/src/scene/shape/rect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export class Rect extends Path implements DistantObject {
private effectiveStrokeWidth: number = Shape.defaultStyles.strokeWidth;

private hittester = super.isPointInPath;
private distanceCalculator = super.distanceSquared;
private distanceCalculator = super.distanceSquaredTransformedPoint;

/**
* When the rectangle's width or height is less than a pixel
Expand Down Expand Up @@ -434,7 +434,7 @@ export class Rect extends Path implements DistantObject {
this.distanceSquared = (hitX: number, hitY: number) => this.getCachedBBox().distanceSquared(hitX, hitY);
} else {
this.hittester = super.isPointInPath;
this.distanceCalculator = super.distanceSquared;
this.distanceCalculator = super.distanceSquaredTransformedPoint;
}

this.effectiveStrokeWidth = strokeWidth;
Expand Down

0 comments on commit 855c947

Please sign in to comment.