-
-
Notifications
You must be signed in to change notification settings - Fork 56
Vec, Point, SVector, ... in the codebase #91
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
Comments
I'm pretty convinced of having a Point type... I suppose the Vec type could be deprecated in favor of SVector though |
I remember this distinction between |
So I looked into the code again as someone that is trying to become more familiar with the codebase to be able more actively contribute, and I confess that I still couldn't figure out why so many different "point/vec" types. I understand that they are all defined in the For the sake of maintainability, could we reduce these types to a single point type or even use vanilla |
I have not looked into the usage here, but I am in favor of the distinction between something like point and vector. from https://doc.cgal.org/latest/Kernel_23/index.html#Kernel_23PointsandVectors
If we wanted to carry out this distinction, I would expect the following:
The following should be undefined: |
Yes. I agree with this distinction. What is not clear to me is what is the
current vector type basically. The codebase sometimes uses Tuples, SVector,
Vec, and I was not sure if Point had the meaning described in the GDAL
snippet above. We certainly need this to be officially documented in the
code for future maintainers.
…On Thu, Sep 24, 2020, 21:56 Gustavo Goretkin ***@***.***> wrote:
I have not looked into the usage here, but I am in favor of the
distinction between Point and Vector.
from
https://doc.cgal.org/latest/Kernel_23/index.html#Kernel_23PointsandVectors
In CGAL we strictly distinguish between points, vectors and directions. A
point is a point in the Euclidean space Ed, a vector is the difference of
two points p2, p1 and denotes the direction and the distance from p1 to p2
in the vector space ℝd, and a direction is a vector where we forget about
its length. They are different mathematical concepts. For example, they
behave different under affine transformations and an addition of two points
is meaningless in affine geometry. By putting them in different classes we
not only get cleaner code, but also type checking by the compiler which
avoids ambiguous expressions. Hence, it pays twice to make this distinction.
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#91 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAZQW3P45PKGOLRGTXIG2VDSHPTFBANCNFSM4RXU2GFA>
.
|
All those different uses are historical... I'm in favor of the snippet posted by @goretkin, and would be behind making that the definition for the point type - and then replace all uses of Vec by SVector, and disallow tuple etc ;) |
One more question before I start start working on the PR :) What is the semantic behind the |
I think we can & should remove the Particle type! |
That is good to hear. I will add this to the PR 👍 |
One more question. I am finding it difficult to understand the macro In summary, can we simplify the complex machinery in abstract type AbstractPoint{N,T} end
struct Point{N,T} <: AbstractPoint{N,T}
coords::SVector{N,T}
end and a vector type Also I keep seeing this C pattern in the code base where various type alias are introduced for specific floating point types and dimensions like |
You'd need to overload lots of functions, to achieve the same functionality as inheriting from StaticArray.
Pfew, I use those a lot in different packages, so I ended up moving them lower and lower in the dependency chain, until I finally moved them here. So, I don't really want to go back on that progression :D I don't think those type aliases are hard to maintain? |
What about making abstract AbstractPoint{N,T} <: StaticVector{...} end
struct Point{N,T} <: AbstractPoint{N,T}
coords::SVector{N,T}
end
# add whatever is missing
foo(::Point) = "I am a point"
Assuming that most algorithms are agnostic to the coordinate type, and that we want to be as generic as possible (please correct me if I am wrong), I see these types as just an extra overhead to keep in mind. The codebase has various snippets like: FRect2D(Vec2f0(0), Vec2f0(1.0)) which I think could be simplified to Maintainability-wise it would be nice to stick to a single name for point and a single name for vector. How can we improve this experience? |
A brief history here. First there was ImmutableArrays around 0.2. Then came allowing integers in type parameters around 0.4 or 0.5, followed by the tuple revamp and we got FixedSizedArrays and StaticArrays so we could have the I would say that before we start redesigning and breaking dependant projects, we should reduce that layer as much as possible and see what happens. E.g. there are a lot of |
I am happy to help with this reduction of the base layer as much as possible, that is why I am pushing these changes now :) I love to improve readability and maintainability of code, and given that GeometryBasics.jl is such a fundamental base package, we should make it as clean as possible early on. So even though these changes are breaking, they are breaking for a good long-term reason. |
Ok, I will implement these changes in a few steps:
Will submit a PR soon for your review 👍 |
I would like to share an update regarding this issue. The above PRs have been merged into the In the next PR I will address the concept of point, which will definitely be the most challenging part to refactor. |
Btw, this and some other comments make it sound, like we're currently re-implementing Vec & Point in GeometryBasics instead of using StaticArrays... I just want to make sure, that it's clear, that we absolutely don't do that, but instead inherit more than 95% of the functionality from StaticArrays, by using the official way of creating a new StaticArray vector type! |
I tried to say that we don't have a new static array type. It is a vanilla |
This issue is fixed in the |
As I continue to study the source code to suggest improvements, I would like to clean up all the variations around the notion of a point as a static n-dimensional vector. Currently, the code uses
Vec
,Point
,SVector
in different places, and it is hard to understand if there is an actual reason behind these variations or if it is just a result of the code evolving quickly. Can we pick a single name and stick to it? I can submit a PR with a single name if that is ok.The text was updated successfully, but these errors were encountered: