r/processing • u/justjelle123 • Sep 18 '24
Help request Sub pixel line precision when zooming?
I am making a route map where you can zoom in on an image pretty far. You can place the beginning and end points for a route, and guide points as well, to guide where the route goes.
Now I want to make the order of guide points evident by drawing lines between them in the right order.
The problem is: it seems that line precision is limited, and I cannot use coordinates like "100.45" or "247.80" and using these will get them rounded to the nearest integer.

It looks like this is because even though I'm zooming this far in, processing would need to do "subpixel" drawing for this, or something like that.
I've tried using line(), using beginShape() and vertex(), but nothing seems to work
Here's the piece of code I used for the video:
beginShape(LINES);
for(int i = 0; i < guidePoints.length; i++){
fill(color(100, 100, 100));
if(i==0 && startPoint.x != -1){
println(startPoint.x * width/backgroundMap.width, startPoint.y * height/backgroundMap.height);
vertex(startPoint.x * width/backgroundMap.width, startPoint.y * height/backgroundMap.height);
vertex(guidePoints[i].x * width/backgroundMap.width, guidePoints[i].y * height/backgroundMap.height);
}
if(i < guidePoints.length-2){
vertex(guidePoints[i].x * width/backgroundMap.width, guidePoints[i].y * height/backgroundMap.height);
vertex(guidePoints[i+1].x * width/backgroundMap.width, guidePoints[i+1].y * height/backgroundMap.height);
}
else if(endPoint.x != -1){
vertex(guidePoints[guidePoints.length-1].x * width/backgroundMap.width, guidePoints[guidePoints.length-1].y * height/backgroundMap.height);
vertex(endPoint.x * width/backgroundMap.width, endPoint.y * height/backgroundMap.height);
}
}
endShape();Would anyone know a workaround to this? I would really appreciate it! Thanks!
View all comments
Show parent comment
1
u/justjelle123 Sep 18 '24
The background image size is 3200 by 4000 px, but it's placed with a width of 500 px (and also downscaled height). The screen size itself if just 500x500 as it's a canvas in a web app. For the zooming and panning I use scale and translate of course.
I think the mouse position is transformed correctly, as the markers (start and end of line) can be placed at excactly the expected location (these are PShapes from a vector image), and their x and y values are as expected. I scale the mouse as follows btw, and scaledX and Y are both of float type.
And when I print the following lines outside the vertex() function, they are, as well, exactly as expected and change correctly (as floats) when the click position changes
But when used in the vertex() function, still the line end points look rounded to the nearest integer, even when specifically casting to float inside the vertex()