-
Notifications
You must be signed in to change notification settings - Fork 999
Minor additions #2520
base: master
Are you sure you want to change the base?
Minor additions #2520
Conversation
@MystMagus I have slight hostility towards proposed changes in IntVector.
It is (1, 1) before and (0, 0) after your PR, and I even cannot say that (0, 0) is more correct. Can you please elaborate in what use cases you need these operations? |
@eugeneko I would say that (0, 0) in that example is more correct (after all, if you do int(3 / 3.2f) the result is 0). What I am using the conversion for is calculating int position in a grid based on screen position. Implicit conversion was causing it to become the wrong value in certain situations. I did not know that VectorFloorToInt existed, my bad for not looking harder. I do however think that the change I made makes sense. |
After I wrote my previous comment, I came to the same conclusion -- that (0, 0) feels a bit more natural. So, one point for this change. However, I have three points againts this change:
I tried to make Urho math template several times. If I ever try it again and succeed, it would be simpler to maintain classes with "pure" interfaces than classes with mixed types. Upd: I remember now why I failed. Manual script bindings. They suck so much. Maybe I'll do math refactoring in rbfx... |
Are you sure there are any implicit calls with floats on IntVectors in the codebase? I tried setting the float operators to private, and it seems to compile without issue. In any case, I don't really agree with the third point but it is as you say subjective. For the second one, dividing an int by a float is a legal operation though, and the current behavior results in the implicit conversion happening before the operation so the result isn't what you would normally expect. |
I'm not sure. However, Urho codebase is bigger than just this We already had similar issue before when @weitjong made StringHash case-sensitive.
It's up to user whether to enable or disable this warning.
If math is converted to templates (and I'm going to do it eventually), these additional operators for |
Well, I've no more things to add. My main point remains that by doing the conversion before the actual operations, the result is not the logically expected one. Who is to say if rather than things relying on this, perhaps there are things that are stealthily not working correctly because of it at the moment. |
Okay, I can point out one more reason why math classes should be pure. Math classes already have dozens of operators for just one type. For example, why can I multiply IntVector2 and float, but cannot multiply IntVector2 and Vector2? If you add IntVector2 and Vector2 multiplication and disivion, then you should add addition and subtraction for consistency, and so on... You see where it's going. By the way, you've already added one critical UX bug in this PR. PS. I'd like to hear out others regarding these changes before doing anything |
@eugeneko can you cut the crap and point out what you think is the “critical bug”. We are contributing to the Urho3D project on their spare time and some may be like me reading all the comments on a phone in the toilet. Our focus should be constantly making Urho3D better and not to keep it stale so that the downstream forks which don’t merge back to upstream have an easy time. We should be allowed to break things |
@eugeneko very accurately pointed out math class purity issue. While those additions do sound convenient and tempting to have i think we should be conservative on this one. These classes are core of everything, they should be perfect in every possible way. |
@eugeneko I'm not trying to pick a fight with you you know. I am very well aware that it is not my decision how this goes forward, all I want to do is to make my case for this. I do not agree with some of the arguments you have put forward, you do not agree with some of mine. And no, I don't see the issue so please enlighten us. |
Maybe this might be a dumb suggestion. But what if we implement a thin wrapper type for fundamental types with an explicit constructor. So as to avoid implicit conversions. Imagine this wrapper: https://gist.github.com/iSLC/adc5d643aa745ab55a5e6a9c948e647f And then something like this: using FloatType = NamedType< float >; And an operator like: IntVector2 operator *(FloatType rhs) const { return IntVector2(x_ * rhs.Get(), y_ * rhs.Get()); } You can't implicitly do This should prevent the user from getting unwanted implicit operations. Bur still give you the flexibility you need without much performance cost. Since the compiler should be able to optimize the wrapper away. I honestly have no idea if that code works. I'm at work and i can't test. But it's a dumb idea that can be considered and even gracefully rejected. It doesn't affect me either way. |
Nah, it's not about fights at all. I'm just trying to clarify my position. There are basically two ways how to design math library. You can make it type-inclusive, so all the types are reasonably compatible with each other. On the other hand, you can make your library strict-typed, so all the types can be used only with their corresponding scalars. For example, GLSL. You must use same scalar type everywhere in calculations and explicitly cast if you need. From your perspective, you expected Urho math behave like type-inclusive library, i.e. like built-in scalars. From my perspective... well, I know that Urho math library is strict-typed. I'm fine with keeping Urho library strict-typed. |
Fair enough, but if one were to make it strict wouldn't it be best to disable those implicit conversions completely (by having them as private non-implemented methods)? Not everyone thinks about turning on more warnings and the bugs that the conversion can cause at the moment are very subtle. |
Didn't think about it... I like this idea. Yes, this option sounds much better. These free functions should be enough to sink in all unwanted conversions:
Are there any other potentially harmful conversions? Cannot think of any. What do you think? |
Yes, that would work. I can get behind that. I guess we can wait a bit longer and see if anyone else has anything to add, and if not then you or I can add that. |
Just my two cents, but I'm much more in favor of having the type stystem be more inclusive, maybe with a limitation that implicit conversions that cause loss of precision will be avoided to avoid some errors (I wouldn't mind if that possibility did exist though). But mostly that's because I don't like having to write really verbose code, so take that as you will. |
@SirNate0 I think this is exactly the case here -- precision loss. And inclusive math has its own issues, e.g. ambiguity. E.g. you multiply Whatever option you choose, you hide possible bugs in user code. |
I'm not sure static_assert will work for this, it seems to me like it always errors when done like this, even if the function isn't used. |
@MystMagus Oh, my bad. Can you try deleted functions instead?
|
*= and /= cases as well, and made explicit IntVector(Vector) constructors for usability (and since Vector already has the reverse too). Ed.: Actually should probably have been two commits in retrospect. |
Thanks! Just a minor note -- can you use E.g. it's trivial to find all places in codebase where you do |
Oh yeah sure, I just did the same one as in one of the other constructors. I'll do it tomorrow. |
I have a feeling that the build is broken because you are trying to reference Oh god, I hate AS so much. I wish it had died already. |
Hold my 🍺 |
Yes, I noticed just earlier this morning. In the process of fixing now. |
I mashed the register functions together rather than putting some of them in the other, unsure if that is the preferred way. Considering the C++ classes are defined in the same file I think it should be okay? |
Stale pull request message |
Just a few misc additions.