-
-
Notifications
You must be signed in to change notification settings - Fork 56
Cleanup Vec aliases #100
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
Cleanup Vec aliases #100
Conversation
I'd be happy to help with this refactoring, but I'm not quite clear what was the main problem with the vector types (and the discussion is spread out in other PRs). @juliohm could you expand a bit your summary with more context, maybe with a couple of before/after examples, to highlight the main goals? I think a complete list of all proposed changes (and their justifications) would be great to evaluate how much work it will take to adapt dependent packages. It would also be great to get feedback from the community (e.g. posting this "roadmap" to Discourse). Here are some ideas/remarks regarding the names:
|
fill is what base uses...We could scope it to apply to return Vecs/Points: |
Although I really feel, like nothing beats |
Hi @knuesel , thanks for considering joining the effort. I am happy to elaborate on the plans, and share some of the motivations behind the refactoring of the code. The first set of changes was initially discussed in #91. In that issue, you will find linked PRs that addressed it partially, including this one. The main problem before this set of changes is that Vectors and Points were being interchanged in the code incorrectly, and there were multiple vector types. By just sticking to The next PR in this set of changes will fix the Point type. Currently the Point type supports all kinds of operations that are only defined for vectors in the embedding space. We cannot add two points for example. Regarding the Rectangle types, it will require another set of changes. The constructors are being abused, and all this fuss with single versus double precision is compromising the generality of the implementations. Rectangle are just a polygon with vertices. The type of the coordinates is naturally inherited from the vertices. So all we need is to have a single Rectangle type with the correct vertices upon construction. If we don't fix this pattern in the codebase, we will end up with FSphere, FLineString, FPyramid, ... and similar noise. The only place where one should specify the type of the coordinates is in the constructor of vectors or points. Everything else should follow. Regarding your comments:
I can see that
Yes, I was really stuck on this one. Couldn't find a cleaner name. It should something that reminds us of the fact that we are repeating the same value for all the coordinates. I thought of using
Sure, do you mind preparing a PR to the
As I explained above, I have the opinion that we shouldn't be playing with specific precision all over the place. We should inherit the precision from the points or vectors like: What do you think of this plan? I hope it makes sense to you all. I am doing my best to put the efforts here and work together, but if you feel that these changes aren't welcome, please let me know and I can continue working in a separate project. |
I really like the |
For consistency, and to distinguish with future point utility functions, I've renamed to |
I will merge this one by the end of the day in case there are no additional suggestions. 👍 |
It is mainly for consistency and clarity of intention. When we introduce |
@juliohm thanks for the explanation, it's very helpful. Have consistent types, and keeping the implementation as generic as possible sound very good! However this is moving a bit fast for me (waiting less than a day for suggestions... no offense! but I can only work intermittently on this). Anyway, here are my two cents 😊: Regarding the type aliases for 2D, 3D, single and double precision: I think it's important to define these aliases because
I see no downside to these aliases (assuming we keep the Good point on the parallelepipeds! For the Euclidean basis: I think you actually mean "standard basis". It's the vector space that is (or isn't) Euclidean... I see a couple of results on Google for "euclidean basis" (well, more like 11'000) but AFAIK that's non-standard terminology. People could use I also like |
Thank you @knuesel , below are some follow up comments.
Users won't write
As pointed out, code becomes less readable with multiple aliases for each geometry. We are talking Rectangle here, imagine this pattern for all primitives. Take a look at the rectangle source code as it is currently, and you will realize the huge number of constructors just to provide these aliases: GeometryBasics.jl/src/primitives/rectangles.jl Lines 30 to 156 in 4bc7ebc
The plan is to cleanup this source of variation in a future PR, after #101 is ready. It is been a good exercise to fix these issues. I could already solve at least a couple dozen bugs in this last PR.
As I mentioned, there is no need for aliases after we get the point type aliases.
"Standard" is a function of the research community you are in. This basis may not be standard in other contexts. The better name for it is Cartesian. It is Euclidean because every point is obtained by simple addition and subtraction of coordinates, and it is Cartesian because of the orthonormality property.
Introducing new names is a good practice in general. After writing a lot of code in the GeoStats.jl stack and in Julia, I realized that life is much easier when we have our own names for a new functionality. The language doesn't provide a trait system and so extending behavior with |
This is a continuation of #93 . It supersedes #97. Addresses #91.
Now we have a single type for representing vectors in geometrical spaces, and it happens to be an alias for
SVector
(implementation detail). Additionally, we have type aliases for end users that often wish to materialize vectors with specific coordinate type and dimension. Here, we avoid partial instantiation. The aliasesVec2
andVec3
are concrete vector types in 2D and 3D using double precision, and the aliasesVec2f
andVec3f
are concrete vector types using single precision.We deprecate
unit
in favor ofeuclidbasis
, which is a more accurate name for the returned vectors. We addconstant
as a helper function to construct vectors with repeated coordinates. The nameconstant
isn't ideal, please let me know if you have a better suggestion.