Jump to content

PdnRegion.GetBoundsInt() (or Union) issue


Recommended Posts

I checked my MeasureSelection and MeasureObject plugins (created 2014) and detected that the last one is no longer working correctly.

 

As other object plugins MeasureObject expects that all surrounding pixels of an object use an alpha value of zero.

The plugin creates a region containig all pixels of the object (I know it is not working fine if there is more than one object).

startX/Y and endX/Y are the bounds of the source surface.

 

                    _measureRegion = new PdnRegion(Rectangle.Empty);
                    for (int y = startY; y < endY; y++)
                    {
                        for (int x = startX; x < endX; x++)
                        {
                            if (src[x, y].A != 0)
                            {
                                int xx = x;
                                do
                                {
                                    x++;
                                } while ((x < endX) && (src[x, y].A != 0));
                                _measureRegion.Union(new Rectangle(xx, y, x - xx, 1));
                            }
                        }
                    }

 

GetBoundsInt() now returns 0/0 for the top/left. I'm pretty sure this was not the case in 2014 😉

 

Maybe the problem is that Union does no longer ignore the Rectangle.Empty initialization of the PdnRegion.

 

 

midora%20signature.gif
Link to post
Share on other sites

I will do some more tests Rick.

But as I remember there is no GetBoundsInt().

So one of the questions is why does pdnregion.GetBoundsInt() returns X/Y=0/0 but pdnregion.GetBounds() works fine.

So for this issue I'm just rounding the values from the RectangleF to get a Rectangle.

midora%20signature.gif
Link to post
Share on other sites

Create the Region using the code you have above (but of course substituting Region for PdnRegion)

 

Then create a new PdnRegion using the constructor that takes a Region. This will copy the Region and wrap it (remember, PdnRegion is just a wrapper around Region anyway, mostly for thread safety stuff)

 

Then call the PdnRegion's GetBoundsInt()

 

This is for troubleshooting purposes -- this will just tell me if there's a bug and along what code path it might be on. You shouldn't need to worry about this at all, PdnRegion should just work.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to post
Share on other sites

Also if you can give me a list of the rectangles that you are union-ing, I can more easily test this out myself.

 

Just a text file with each rectangle's ToString() on its own line is fine, you can paste it here into a code block

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to post
Share on other sites

I will do this.

Still I would check how it could happen that GetBoundsIn()t returns 0/0 for top/left compared to GetBounds() which seems to return the correct bounding rectangle always.

 

I merged MeasureSelection and MeasureObject now to one because it makes not really sense to provide two separate plugins

(guess I have to look for a solution to paste images here because of the limit).

 

 

 

 

 

midora%20signature.gif
Link to post
Share on other sites

https://ibb.co/YQmNmBN  (2021-03-30 Measure Selection.png)

 

No idea how to show this image in the post. Maybe someone can provide a hint. Or is just possible for imgur?

 

Anyway I like to add some remarks regarding the image

- I have stolen the ruler icon of paint.net and added a selection. I hope this is OK 🙂

- I'm wondering why when creating a circle (while shift is pressed) sometimes a different width and height is visible in the status line. Rounding issue?

- The area of the selection differs between paint.net and plugin. I expect the reason is that I can just count the pixels of the scan lines while paint.net can add fractions of a pixel

 

 

midora%20signature.gif
Link to post
Share on other sites
3 hours ago, midora said:

- I have stolen the ruler icon of paint.net and added a selection. I hope this is OK 🙂

 

 

I'm okay with it in this instance. In general, however, you can't do that -- the icons are not licensed for that, partly because I don't have the rights to give them away like that (many/most come via https://axialis.com). I made the ruler icon from scratch though, so I can do whatever I want with it.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to post
Share on other sites

Fine that this has been clarified. By using the word 'stolen' it should be clear that I'm looking for the rights.

The old icon just didn't fit to the new icons.

midora%20signature.gif
Link to post
Share on other sites

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...