Skip to content
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

Allow arrows to take a Function to produce the vector #2597

Closed
wants to merge 13 commits into from

Conversation

asinghvi17
Copy link
Member

@asinghvi17 asinghvi17 commented Jan 15, 2023

Description

Allow arrows to take input of the form x::AbstractVector, y::AbstractVector, [z::AbstractVector,] f::Function

Add a description of your PR here.

Type of change

Delete options that do not apply:

  • New feature (non-breaking change which adds functionality)

Checklist

  • Added an entry in NEWS.md (for new features and breaking changes)
  • Added or changed relevant sections in the documentation
  • Added unit tests for new algorithms, conversion methods, etc.
  • Added reference image tests for new plotting functions, recipes, visual options, etc.

@asinghvi17 asinghvi17 marked this pull request as ready for review January 15, 2023 02:38
src/conversions.jl Outdated Show resolved Hide resolved
# and magnitude of the arrows. The function must accept `Point2f` as input.
# and return Point2f or Vec2f or some array like structure as output.
function convert_arguments(::Type{<: Arrows}, x::AbstractVector, y::AbstractVector, f::Function)
points = Point2f.(x, y')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that be Point2f.(x, y)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, arrows always creates a matrix - the eventual positions are Point2f.(x, y') anyway. Plus the inputs are AbstractVectors so we know that we have to make the grid.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it does one or the other depending on the type of directions:

convert_arguments(::Type{<: Arrows}, x, y, u, v) = (Point2f.(x, y), Vec2f.(u, v))
function convert_arguments(::Type{<: Arrows}, x::AbstractVector, y::AbstractVector, u::AbstractMatrix, v::AbstractMatrix)
(vec(Point2f.(x, y')), vec(Vec2f.(u, v)))
end

That makes this a bit awkward to reason with...

@ffreyer
Copy link
Collaborator

ffreyer commented Jan 17, 2023

To me it seems more intuitive to just directly pass on args rather than doing a conversion beforehand. I.e.

arrows(xs, ys, (xs, ys) -> Vec2f.(-ys, xs))

rather than

arrows(xs, ys, ps -> Vec2f[(-p[2], p[1]) for p in ps])

That seems to be what surface and volume do.

I also wonder if we should just have a default conversion of (args..., f) -> (args..., f(args...)) for all plot types.

@asinghvi17
Copy link
Member Author

I do like the idea of that second conversion - but it might be easier to implement it per plot type.

@SimonDanisch
Copy link
Member

Closing in favor of #3080

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants