Can we find out in CodeLab if a selection is tilted?

Recommended Posts

The value of the angle of inclination does not matter. Just a True or False flag.

Share on other sites

I don't think so...

What is the difference between a square selection that is rotated 45* and a diamond shaped selection made using the magic wand?

Share on other sites

None, except that one shape is rotated and the other is not.

Share on other sites

As BoltBait also seems to be, I'm curious about what use you'd like to put this information. Unless it's a rectangular selection, why does it matter whether the selection was rotated or not? In what significant way is a rotated non-rectangular selection different from a non-rotated non-rectangular selection? And if you want to check if a selection is an unrotated rectangle, that doesn't seem to be too difficult. You could confirm that the selection matches its bounding box.

You've asked this question twice, so it apparently matters to you, but I don't quite see why.

EDIT: I remembered that there's a very easy and efficient method to tell if the selection is a singe rectangle, oriented to the X and Y axes, if that happens to be what you want to determine.

Share on other sites

If you are wanting to have an effect (like directional blur, for example) follow the angle you've rotated the selection to, I think you're better off using an angle chooser control.

Share on other sites

5 hours ago, MJW said:

I remembered that there's a very easy and efficient method to tell if the selection is a singe rectangle, oriented to the X and Y axes, if that happens to be what you want to determine.

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

Share on other sites

I believe the following works. Call:

Rectangle[] selectionRectangles = EnvironmentParameters.GetSelectionAsPdnRegion().GetRegionScansInt();

This returns a list of rectangles that together cover the selection. If it has only one rectangle, it's a rectangular selection.

Share on other sites

16 minutes ago, MJW said:

If it has only one rectangle, it's a rectangular selection.

So, that would be:

`bool isOneRectangle = EnvironmentParameters.GetSelectionAsPdnRegion().GetRegionScansInt().Length == 1;`

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

Share on other sites

I think so. I admit I can't say with absolute certainty that it does work.

Share on other sites

It's definitely true that if there's only one rectangle, it must be a rectangular selection.  I believe the converse is also true, but I don't know if I've ever confirmed it. Whenever I've stepped through code calling the routine, it's only returned one rectangle for rectangular selections.  The only case I've used it was to determine if I could use a simpler method, so if it had failed, and said a rectangular region was non-rectangular, the only result would be slightly worse performance.

Share on other sites

Thanks  MJW!

This code seems to work fine only for rectangular selection:

```Rectangle sel = EnvironmentParameters.SelectionBounds;

//check if selection is tilted
Rectangle[] selectionRectangles = EnvironmentParameters.GetSelectionAsPdnRegion().GetRegionScansInt();
if(selectionRectangles[0].X != sel.X)
{
//selection is tilted
}```

Edited by NSD
Share on other sites

1 hour ago, Rick Brewster said:

That's not a very good way to do that

Could you please elaborate; or at least clarify whether "that" refers to determining if the selection is tilted (as NSD wishes to do), or to determining if the selection is a non-tilted rectangle (as the method I proposed attempts to do), or to both.

If the method I suggested doesn't work because a non-tilted rectangle may produce more than one rectangle in the returned list, an alternate method would be to sum the area of the returned rectangles and compare that to the bounding-box area. I realize there are cases where a minutely-tilted rectangular selection (or similar) could produce a false positive, since the rectangles and bounding box have integer coordinates, but that seems impossible to avoid without access to the actual selection path (the one that can be written to the clipboard). As far as I could determine, that isn't available to plugins, though you once mentioned that you might consider providing it.

(I don't see how tilted versus not-tilted is very meaningful for anything but a rectangular selection. I suppose it could have meaning for any symmetric selection, but I can't see to what good use the information could be put.)

Share on other sites

I'm referring to @NSD's code. You can't just compare X and conclude that the selection is "tilted".

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

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

Share on other sites

33 minutes ago, Rick Brewster said:

You can't just compare X and conclude that the selection is "tilted".

Thanks. I certainly agree there.

Join the conversation

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.