-
Notifications
You must be signed in to change notification settings - Fork 24
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
Functor overloading for custom types? #65
Comments
Having a wrapper seems rather annoying! I think it's ok to do some type piracy in the short term, especially at the application level (not so much in a reusable library). Perhaps part of the solution would be for Generally I think transforming extended non-point like objects is a bit tricky: if they're based on a discretization like |
Okay, this makes a lot of sense. In view of this fact it seems sensible to overload the functors for the concrete subtypes of |
I think for piecewise linear geometry you want to overload for Many transformations are almost-affine at practical scales and it often makes sense to ignore the curvature and do a pointwise transformation of the vertices for piecewise linear geometry. But I'm not sure what's the best way is to model this — the validity depends on the scale of the geometry, the curvature of the coordinate system, and the tolerance in your actual application. A practical option might be to have a There's other things you could consider, such as subdividing piecewise geometry according to some tolerance. But whether this is a good idea is very application-specific (in particular, it makes the transformation very non-invertible). Related note - you can create a locally affine approximation of any transformation using one of the |
Can you put methods on (instances of) abstract types now? I thought that was a no-go? Generally yes we should probably only support While I think it's fine to transform a complex object like a line through a transform meant for points, these days I also often think of complex geometric objects as containing sets of points and might be modelled to behave as collections - in which case |
You can do this as of JuliaLang/julia#31916 |
Oh right - I had forgotten! Well, adding call overloads to I’d say tighten our built-in definitions to |
Yes I like this model.
This seems ok, but I don't think it addresses the core difficulty which is that mapping such sets through non-affine transformations is generally approximate, and that various approximations might be applicable depending on application. So you could choose one particular approximation but somebody else could end up needing a different one. Whether it's called |
My favourite way to deal with such approximations is to avoid them by making such transforms lazy, and you can still determine predicates like But yeah, it totally depends on application! Not sure what that means for a package like this? |
Yes! I almost wrote that you could have a lazy version :-) But again, it does depend on application a lot - the lazy version using the inverse would work for pointwise containment queries, but not for many interesting things such as geometric intersection when the two objects are not in the same source coordinates. Also it's likely to be less efficient.
As a fairly simple and arguably "core" geometric package, I think it means we leave these operations undefined when the best method is ambiguous and application-specific. Or at most, provide some of the simpler versions in an explicitly opt-in way. (For example, the idea of the |
Has any action been taken on this issue? I want to non-uniformly scale a tesselation of a sphere. Coming from a graphics background I naively expected that I could combine CoordinateTransformations and GeometryBasics to transform meshes. But applying a transformation to a geometry object or a Tessellation object causes a run time error. What is the recommended solution? In graphics we use trees of these transformations to create and animate scenes with each leaf holding a geometric object and the interior nodes holding transformations. Is it not possible to combine CoordinateTransformations and GeometryBasics this way? If not, what's the recommended alternative? |
@BrianGun someone would need to provide overloads to support transforming those geometries. Triangular meshes would be pretty easy to implement since you’d just need to map the transform over the array of vertices. Points, multi points, lines and multi lines are similarly ok. There’s a slight difficulty in that non-Affine transformations don’t preserve straight lines and flat planes and the output is only an approximation (and sometimes a really poor one). Eg a polygon is no longer a polygon (with the exception of triangles) which violates an assumption of the widespread “simple geometry types”. Long geodesic lines in a geometric projection across the surface of earth become lines going through the centre of Earth (transforming a line into a multi line, arc or multi-arc might be more appropriate). Etc. Providing such transformations by default runs the risk of being a foot gun for someone, somewhere, someday (and more likely for geodesists - everyone, everywhere, all the time). |
To follow up @BrianGun - for your use case in particular it's probably as simple as |
I am trying to figure out what is the correct way to overload the transformation functors for custom types? For example, if I want to be able to transform something like
GeometryBasics.Line
then I can not simply implement:since the call to the functor then becomes ambiguous (There are methods with a more specific
Transformation
subtype but a less specific argument type (input to the transformation)). So instead I would overload the functor for concrete subtypes ofTransformation
, e.g.:But this does not seem very clean since it leads to a lot of code duplication.
Is there some kind of best practice for this? Should I not be overloading these functors at all (since it may be considered type piracy) but instead define my own thin wrapper like
apply_transformation(tform, x)
?It may be good to have some brief documentation on this somewhere in the README.
The text was updated successfully, but these errors were encountered: