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

Improved point detection accuracy on mouse hover #104

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/modules/Points/draw-points.vert
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ uniform float spaceSize;
uniform vec2 screenSize;
uniform float greyoutOpacity;
uniform bool scaleNodesOnZoom;
uniform float maxPointSize;

varying vec2 index;
varying vec3 rgbColor;
Expand All @@ -28,7 +29,8 @@ float pointSize(float size) {
} else {
pSize = size * ratio * min(5.0, max(1.0, transform[0][0] * 0.01));
}
return pSize;

return min(pSize, maxPointSize * ratio);
}

void main() {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/Points/find-hovered-point.vert
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ float pointSize(float size) {
} else {
pSize = size * ratio * min(5.0, max(1.0, transform[0][0] * 0.01));
}
return min(pSize, maxPointSize);
return min(pSize, maxPointSize * ratio);
}

float euclideanDistance (float x1, float x2, float y1, float y2) {
Expand All @@ -45,7 +45,7 @@ void main() {
vec2 pointScreenPosition = (final.xy + 1.0) * screenSize / 2.0;
rgba = vec4(0.0);
gl_Position = vec4(0.5, 0.5, 0.0, 1.0);
if (euclideanDistance(pointScreenPosition.x, mousePosition.x, pointScreenPosition.y, mousePosition.y) < pointRadius) {
if (euclideanDistance(pointScreenPosition.x, mousePosition.x, pointScreenPosition.y, mousePosition.y) < pointRadius / ratio) {
float index = indexes.g * pointsTextureSize + indexes.r;
rgba = vec4(index, pSize.r, pointPosition.xy);
gl_Position = vec4(-0.5, -0.5, 0.0, 1.0);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Points/find-points-on-area-selection.frag
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ float pointSize(float size) {
} else {
pSize = size * ratio * min(5.0, max(1.0, transform[0][0] * 0.01));
}
return min(pSize, maxPointSize);
return min(pSize, maxPointSize * ratio);
}

void main() {
Expand Down
1 change: 1 addition & 0 deletions src/modules/Points/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export class Points<N extends CosmosInputNode, L extends CosmosInputLink> extend
screenSize: () => store.screenSize,
greyoutOpacity: () => config.nodeGreyoutOpacity,
scaleNodesOnZoom: () => config.scaleNodesOnZoom,
maxPointSize: () => store.maxPointSize,
},
blend: {
enable: true,
Expand Down
Loading