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:
function (tform::CoordinateTransformations.Transformation)(l::Line)
Line((tform.(l))...)
end
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 of Transformation, e.g.:
function (tform::CoordinateTransformations.AffineMap)(l::Line)
Line((tform.(l))...)
end
function (tform::CoordinateTransformations.LinearMap)(l::Line)
Line((tform.(l))...)
end
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.
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.Linethen I can not simply implement:since the call to the functor then becomes ambiguous (There are methods with a more specific
Transformationsubtype 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.