New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposed update to ofRectangle::scaleTo - now with more scaling modes. #1513
Conversation
Now ofRectangle::ScaleToMe. More scaling options via ofRectScaleMode.
On Ubuntu 12.04 there's Tile (tile smaller images, for larger images this == CENTER), Zoom (your FILL), Centre (your CENTER), Scale (your FIT), Fill (your STRETCH), Span (spanning for dual monitors, otherwise == Scale). |
this feature is very useful indeed... something im always using in my projects. ive always used the term CROP instead of FILL but FILL also makes perfect sense. |
@bilderbuchi I left out tile because it's a little more specialized and I wasn't sure how to have a method signature of ofRectangle that could encompass all of them and include tiling. If you think tile is important and have a suggestion on how it might be included and the syntax of scaleInMe -- maybe it will give you a vector full of ofRectangles? The names are Mac-biased, but I'm not -- so if there is a more intuitive naming scheme (I kind of feel like the Linux names are actually more intuitive), I'd prefer that. @julapy I think I'd prefer Linux's Linux Scale/Mac Fit over Crop -- as crop seems to imply that the aspect ratio of the original rect might be lost. Your ofxResizeUtil class is really nice. While the math seems to be the same, I do prefer how you explicitly named wRatio / hRatio before calculating the MAX/MIN. I think it would be easier to read than mine. |
this looks great. |
This was no request to include tiling (nor spanning), I just wanted to be complete in the list of options available on Ubuntu. :-) Nomenclature-wise, CENTER and STRETCH are intuitive, but I think for distinguishing the two AR-preserving fitting modes, I find neither fill/fit nor zoom/scale very intuitive. I think maybe it's a better idea to got with something like FIT_INSIDE/FIT_OUTSIDE, like the source rectangle can be thought of as being inside (as you already say in your comment) or outside the target rectangle. |
looks good to me too. definitely going to switch to using this in the future. it would be nice to have a demo that just shows different rectangles drawn in different colors using the different modes. regarding nomenclature, i've previously called "FIT" "fit inside" and "FILL" "fit outside". it's not clear to me what the difference is between "OF_RECTSCALEMODE_STRETCH" and just saying rectA = rectB also i wanted to mention: some of your initial post says |
@kylemcdonald I'm happy to fill out the demo code here https://gist.github.com/3492711 into full-fledged example / demo. Any more votes for the FIT_INSIDE / FIT_OUTSIDE? @kylemcdonald and @bilderbuchi to be in favor. Others haven't registered a strong opinion. @ofZach @ofTheo @julapy thoughts? @kylemcdonald -- There is no difference "OF_RECTSCALEMODE_STRETCH" and just saying rectA = rectB. It is just there for enum completeness. For instance, in my use case, I have a toggle that switches between all enum values when I'm scaling an image into an fbo. Without the STRETCH option, it would require extra code and another special case to do that operation. Sorry about the capital S. All typos. The code is king here. |
I prefer FIT / FILL - but that is because it is similar to what its called in InDesign. I'm easy though :) |
I guess I prefer FIT / FILL but would ideally like the name to self-describe the preservation of the subject's aspect ratio. I don't want people to have to read the comments every time. Adding "XXX_PROPORTIONALLY" or "XXX_PRESERVE_ASPECT" gets a bit long though. Maybe scaling via fit/fill/center already implies aspect ratio preservation and stretching doesn't? |
I think FIT, FILL and STRETCH_TO_FILL imply just the last is non-aspect ratio respecting. |
✓+ for the |
for me, "scale" implies AR-preservation, and "stretch" implies non-AR preservation. "fit/fill" is more ambiguous (which is probably why, in Theo's InDesign screenshot, it's called "fit proportionally"). So maybe, inmproving my initial proposal, SCALE_INSIDE/OUTSIDE? edit: FIT/FILL/STRETCH_TO_FILL also sounds ok I guess. |
Hi all, just a note -- I've continued working with this, paying careful attention to the emerging alignment |
Still working on a few things. Don't pull :) |
…rks into ofRectangle_Additions
…are based on Qt and could, if desired, be combined into a single bit-wise combined alignment flag.
- x/y are now references to an underlying ofPoint for easier ofPoint/ofVec manipulations of an ofRectangl. (addresses issue openframeworks#821 by @danomatika) - Added setters for x/y/width/height/position (vec) - Changed the variable names on translateXXX to dx/dy (delta x/y) - Added translateX, translateY - Added scaleWidth / scaleHeight for independent control. - changed scaleToMe to simply be scaleTo. + remove personal pronoun. + Scales itself, rather than returning the scaled version of another ofRectangle. - Added scaleTo functions that are more generic, using the new ofAspectRatioMode. + This allows more flexible scaling with alternate alignments. + Overridden functions provide easier access w/o changing defaults. - Added alignTo functions that now work with the new ofAlignHorz and ofAlignVert enums. + contain functions for aligning to other rects, points, and a single value, based on a the anchor. - Moved the overridden operators to the bottom of the implementation file / header. - Added getLeft()/getRight()/getTop()/getBottom(). + since our ofRectangle class supports negative width/height, these offer more intuitive interaction with known edges. - Added getHorzAnchor() / getVertAnchor() to get edges by using the new alignment enums. Throws errors if the alignment enums are invalid. - getPosition and getPositionRef added. - Moved getCenter() to live with the other getters.
Hello all, I just pushed some significant changes to this pull request based on our discussions. In addition to a few new getters and setters and a response to issue #821, I also added a suite of alignment tools and more complex scaling tools. Please read through the full commit messages for specific comments. Also, please check out the branch and run the example program. It should be self explanatory (and pretty cool if you like lining things up and scaling things.). One note, I searched long and hard to figure out the best way to do alignment in oF. My goal was to mimic the simple alignment constants in Processing (i.e. align left works for text and other things as well), but after much work, I am pretty convinced that text alignment needs its own enum -- particularly with all of the fancy options for justification. In the future, methods that need an My motivation for these alignment functions is ultimately based on my development of |
…rks into ofRectangle_Additions
@@ -363,11 +363,52 @@ enum ofWindowMode{ | |||
OF_GAME_MODE = 2 | |||
}; | |||
|
|||
enum ofAspectRatioMode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These names were borrowed from Qt's similar enum.
@@ -10,22 +11,26 @@ | |||
ofRectangle::~ ofRectangle(){} | |||
|
|||
//---------------------------------------------------------- | |||
ofRectangle::ofRectangle(float px, float py, float w, float h){ | |||
ofRectangle::ofRectangle(float px, float py, float w, float h) : x(position.x), y(position.y) | |||
{ | |||
set(px,py,w,h); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a big thing but curious why the brackets were dropped down a line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea. I'll fix them.
mostly this looks good to me, apart from some small naming questions. |
Yes, I know canonicalize is a bit awkward and not very self-descriptive. I used it because that's how what the process is called in other frameworks and geometry examples I've found on the net. I'll do a bit more research on this and make some proposals. |
thanks - that all sounds great! |
just a btw, the uncrustifier is ready to go, just waiting for someone to pull the trigger. (a helper script for it is in #1542). |
Indeed, at least to me "normalize" sounds like it would return a square or something like that. |
IIRC one of the issues we had in Maine with the problem is that what it is doing (enforcing non-negative width/height) only makes sense if you make the (non-obvious) assumption that width and height may be negative numbers. my vote would be for a verbose function name like however i think a stronger case can be made for removing the function completely, as the existence of such a function would seem to imply that ofRectangle is actually capable of correctly dealing with rectangles with negative width/height (i would not at all assume that it is). |
Normalize makes more sense, but agree on the potential for confusion. what about: I can see the need for non-positive dimensions, @bakercp does ofRectangle fully support that at the moment? |
One argument for the In terms of support for non-positive dimensions -- it is currently completely supported (with careful attention paid to that fact). You'll see lots of Finally, the normalization/canonicalization functions are Anyway, with all of that said -- while would I still vote for the
It basically needs to be a shorted version of this ...
:) |
@bakercp ok, that makes a lot of sense. i think your point around re: naming, my intuition for re: scaling functions auto-normalizing: yes, i agree, this is a bit weird and/or inconsistent. scaling functions should not alter the sign of incoming width/height arguments. |
Hi all -- sorry to keep this thread going -- but I just found that Just to quote:
Would folks be opposed to this I'm removing the auto normalization stuff from the scaling functions. Like the Apple Doc, we just need to be sure to mention that we don't enforce positive width / height and if users want to have predictable results, they should get a standardized copy or standardize the rectangle itself before using the other member methods like scaling, etc. Thanks for all the feedback on this! |
standardize() getStandardized() isStandardized()
|
… of the dimensions width/height will never be implicitly modified during member method execution, with the single exception of the explicit `standardize` methods.
merging this - would be good for people to test!! thanks @bakercp for all the changes! |
Proposed update to ofRectangle::scaleTo - now with more scaling modes.
Thanks for all of the input! For those interested in testing, please check out the new |
Since implementing @ofZach's suggestion for the recently added
ofRectangle::scaleTo
(formerly known asofRectangle::scaleIntoMe
) method (see PR #1332), I have started using it quite extensively.In using it, I have found a lot of other situations where other scaling modes based on an existing rectangle would be quite useful. While there are other ways to do it, this would be useful when scaling an image into an FBO like this:
This PR proposes the addition of an enum called
ofRectScaleMode
. And a change fromofRectangle::ScaleIntoMe()
toofRectangle::ScaleToMe()
to capture the idea thatofRectangle
can be scaled by otherofRectangle
s in a variety of ways. It would be nice to get this method name change in before the next release so we won't have to worry about backward compatibility.The original
ofRectangle::ScaleIntoMe()
might best be described as a "fit" scaling operation. The newofRectangle::ScaleToMe()
usesOF_RECTSCALEMODE_FIT
by default.Below is the new enum with comments. Comments are also included in the commit, and should possibly be removed before any merges.
If you would like to see it in action and try it out, here is a test app https://gist.github.com/3492711.
If you want to compare it to a another familiar paradigm, on a mac go to System Preferences -> Desktop & Screensaver -> Desktop and you can scale your desktop image similarly. I believe there is a similar option in windows + Linux, but I don't have it in front of me.