Jump to content

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


Recommended Posts

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.

Link to post
Share on other sites
5 minutes ago, toe_head2001 said:

Please share.

 

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.

  • Upvote 1
Link to post
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.

Link to post
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
added info
Link to post
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.)

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...