Skip to content

Functor overloading for custom types? #65

@lassepe

Description

@lassepe

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions