-
Notifications
You must be signed in to change notification settings - Fork 252
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
Unified layout and limits functions for vtile and htile. #416
Unified layout and limits functions for vtile and htile. #416
Conversation
…axis. Refactored the tile code so that the limit and layout method on vtile_element and htile_element call common templated code using that axis dependent code. Gives single code path for both.
@@ -24,6 +24,9 @@ namespace cycfi { namespace elements | |||
constexpr point move(float dx, float dy) const; | |||
constexpr point move_to(float x, float y) const; | |||
|
|||
constexpr float coord(bool is_x_axis) const; |
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.
Would an operator [] be useful here as well?
constexpr float operator[](bool is_x_axis) const
Refactored the 'bounds_of' method on vtile and htile to use a common code patht that exploits the axis aware constructor of rect.
Looking at this a bit, I think it can be done non-intrusively of Axis can be an enum class:
Accessing axis specified coordinates can be done non intrusively:
Usage:
This is a lot better than
Same for |
That's how I normally write my vector/point classes, not that I do that any more, currently my code uses the Eigen library, https://gitlab.com/libeigen/eigen. The only issue is then is bounds checking, which a bool saves you from in the 2D case. To me, logically treating bounding boxes/rects as flat arrays doesn't make as much sense as it does for vectors/points. It's two point values representing the min/max values on the axii in your N dimensional space. Happy to flip it to free functions. |
Ha! You edited your comment as I was posting. My other unstatate idea was for an axis enum to do the indexing into points/rects as opposed to a bool. |
Yes, sorry. my mind was wandering as I explored some more. |
Yes. The general rule is ... If it can be a free function, make it so. |
True! And that is why I took it back :-) |
Only issue then is the axis specifiying rect constructor.
Given it's creating a rect I'd argue this shouldn't be a free function. |
similarly:
|
I'm removing my camelHump method names and refactoring it now. Looking at the code I'd argue for an pair of
You can't write [] operators as free functions. |
Go for it! I like it! |
Except for the ALLCAPS :-P Haha. |
WeDontNeedEmHumps :-) |
snakes_are_evil! |
It's a template arg, I'll flip it to your stylee. |
HumpsAreForTemplateTypenames :-) We love evil_snakes everywhere else. |
If it's a non-type template arg, then it's also an evil_snake :-) |
|
If we are being pedantic, from that thread....
My member variuables end with an underscore as opposed to starting with them. :-P |
Done! |
That is actually wrong. The standard says never start with TWO underscores. But also never start a underscore and a cap, like _BAD |
Basically... The use of two underscores ( BUT!!! C++ is scoped. Take that recommendation as old-fashioned, pre namespaces and strict scopes. |
I learn something new everyday. |
Summary:
|
Done |
One thing though: we will have to the same with the |
I can't get onto this again for a few days. The |
I suspect all that is needed is to apply the rect/point changes. The tiles will use that automatically by a simple |
In the meantime, I changed the target to a feature branch |
OK to merge so far? |
I haven't fixed the formatting yet. |
Just made the last set of changed you suggested. Feel free to merge. |
* Added functions to get values out of rect, point and view_stretch by axis. Refactored the tile code so that the limit and layout method on vtile_element and htile_element call common templated code using that axis dependent code. Gives single code path for both. * Added an axis aware constructor to rect. Refactored the 'bounds_of' method on vtile and htile to use a common code patht that exploits the axis aware constructor of rect. * Tidied up the axis accessing APIs * Using inline macro CYCFI_FORCE_INLINE * Formatting changes --------- Co-authored-by: bjn <[email protected]>
Added functions to get values out of rect, point and view_stretch by axis.
Refactored the tile code so that the limit and layout method on vtile_element and htile_element call common templated code using that axis dependent code. Gives single code path for both.