MeasuringRocks 0 Posted May 17, 2019 Report Share Posted May 17, 2019 Hello everybody! I am a really satisfied Paint.net user. I have been using the software for years and it is great, simply the best pixel editor I have tried. Congratulations for your work!! I use the software mainly for pixel counting purposes, and I have recently discovered what I think is a bug or at least a calculation problem. I would like to show it to you using an example: · Attachement number 1: I have created a blank image with a resolution of 10x10 pixels. If I draw a horizontal line (width = 1 pixel) from left to right, the length of the line appears as 10.00 pixels, which is right. · Attachement number 2: If I do the same but with a vertical line, the result is also right: 10.00 pixels. In both cases, the angle is also right (0.00 degrees for the horizontal line, and 90.00 degrees for the vertical line). · Attachement number 3: The problem appear when I am getting the length of a diagonal straight line. Theoretically, a 10x10 pixel resolution image needs to have a diagonal length of 14.14 pixels (calculated using the Pythagorean theorem), but Paint.net is giving always a lower value. Although the angle is perfectly fixed at 45.00 degrees, the length value is 13.73 pixels instead of the calculated 14.14 we would have expected, so that is what is bothering me. I have tried the same approach in similar programs and I obtain the expected 14.14 pixel length when measuring that diagonal. I would really appreciate your opinions. Thanks!! Quote Link to post Share on other sites

MJW 1,246 Posted May 17, 2019 Report Share Posted May 17, 2019 Ten pixels on the diagonal is correct. What do you expect, an irrational number of pixels? That would be quite a trick! The pixels are always in the same place, in a grid pattern, much like your illustrations. You can take solace in the fact that the diagonal distance between two corner-connected pixels is the square root of two, so it all works out. With raster graphics, you won't be able to get the length of lines by counting the number of pixels. If you have a single-width aliased line, you could get a rough approximation by stepping along the line, adding one for each horizontal or vertical step, and the square root of two for every diagonal step. For antialiased lines, you could probably get a rough approximation by adding the intensities (treated as zero to one), then dividing by the width. Quote Link to post Share on other sites

MeasuringRocks 0 Posted May 18, 2019 Author Report Share Posted May 18, 2019 Hello and thanks for answering my post! I think you didn't urderstand me well... I know there are 10 pixel, that's ok, but Paint.net gives you the length of a line while you're drawing it in the status bar, and that's what's wrong. What I am saying is that the value given by the software for the diagonal line (13.73 pixels, you can see it in the status bar in my screenshot with the diagonal line in it) is wrong, as it should be 14.14 pixels for a 10x10 pixel image. I've checked the image with other software and the result is the expected 14.14, so there is a problem with Paint.net way of calculating the length of a diagonal line. That's what's bothering me Quote Link to post Share on other sites

MJW 1,246 Posted May 18, 2019 Report Share Posted May 18, 2019 Oh, I see! I thought it was an odd question. (But then, a lot of odd questions get asked.) Computing the actual length instead of the pixel count might be a good idea. Off hand, I don't know the formula for length a Bezier curve; but since it's a parameterized cubic curve, I expect it isn't too difficult to compute. It is, of course, up to Rick Brewster, and he may have a reason for using the pixel-count version. Quote Link to post Share on other sites

Rick Brewster 1,679 Posted May 18, 2019 Report Share Posted May 18, 2019 @MeasuringRocks, btw, those screenshots are from a very old version of the app. Make sure you install the latest updates. If you don't install updates then you can't get fixes for things like this. Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to post Share on other sites

MeasuringRocks 0 Posted May 21, 2019 Author Report Share Posted May 21, 2019 Thanks MJW and Rick!! It seems clear that the problem is related to the length calculation for a Spline/Bézier, as Paint.net considers a straight line as a curve without curvature. I have uploaded 2 screenshots with the latest version of the software: one showing the issue when using inches as unit (the result for the diagonal should be 70,71 instead of 70,30), and a second one using the plugin "Measure selection" (by Martin Osieka) to show that it gives the correct result in the diagonal: 70,71 inches. Rick, thanks again for creating this great software we all love Regards. Quote Link to post Share on other sites

Rick Brewster 1,679 Posted May 21, 2019 Report Share Posted May 21, 2019 Yeah this has to do with some super funky weirdness inside the Line/Curve shape's geometry generation. Let's say you have a 10x10 image and draw a line from the top left to the bottom right. When you're zoomed in you will see the control points rest on half-pixel offsets: (0.5, 0.5) and (9.5, 9.5) (not including the splint control points). So, the length between those is sqrt(9*9 + 9*9) or ~12.73. Obvously that's not right, as the line you see goes to the very corner of the image. So why isn't the length sqrt(10*10 + 10*10) or ~14.14? Why is it 13.73? Well, to make rendering look correct, the line is extended by 0.4999 pixels in such a way that we end up with a length of 13.73. It's sort of a fudge factor to help ensure the line looks correct in many different circumstances: different angles, brush widths, start/end caps, etc. Rendering geometry is weird. It should be possible to special-case this calculation to be correct when antialiasing is disabled, however. There's no need to calculate this based on the weird stuff that's added, as the length is supposed to help you, it's not supposed to be some reflection of what's actually going on inside the rendering engine (unless that's helpful of course!). Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to post Share on other sites

## Recommended Posts

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.