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

Remove methods like +(::Number, ::Point) and update around broadcasting #294

Merged

Conversation

hyrodium
Copy link
Contributor

This PR fixes #270.

Before this PR

julia> using Luxor

julia> Point(1,2) .+ 3
Point(4.0, 5.0)

julia> Point(1,2) + 3  # Should throw an error like `(1,2) + 3` or `[1,2] + 3`
Point(4.0, 5.0)

julia> [Point(1,2), Point(4,3)] .+ Ref(Point(0,-2))
2-element Vector{Point}:
 Point(1.0, 0.0)
 Point(4.0, 1.0)

julia> [Point(1,2), Point(4,3)] .+ Point(0,-2)
2-element Vector{Point}:
 Point(1.0, 0.0)
 Point(4.0, 1.0)

julia> Point(1,2) + (3,4)
Point(4.0, 6.0)

julia> Point(1,2) .+ (3,4)  # Should be equal to `Point(1,2) + (3,4)`
(Point(4.0, 5.0), Point(5.0, 6.0))

julia> Point(1,2) .+ [3,4]  # Should be 2-element collection
2-element Vector{Point}:
 Point(4.0, 5.0)
 Point(5.0, 6.0)

After this PR

julia> using Luxor

julia> Point(1,2) .+ 3
Point(4.0, 5.0)

julia> Point(1,2) + 3
ERROR: MethodError: no method matching +(::Point, ::Int64)
[...]

julia> [Point(1,2), Point(4,3)] .+ Ref(Point(0,-2))  # Now requires `Ref` for broadcasting
2-element Vector{Point}:
 Point(1.0, 0.0)
 Point(4.0, 1.0)

julia> [Point(1,2), Point(4,3)] .+ Point(0,-2)
ERROR: MethodError: no method matching +(::Point, ::Float64)
[...]

julia> Point(1,2) + (3,4)
Point(4.0, 6.0)

julia> Point(1,2) .+ (3,4)
Point(4.0, 6.0)

julia> Point(1,2) .+ [3,4]
2-element Vector{Float64}:
 4.0
 6.0

Copy link

codecov bot commented Feb 17, 2024

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (87ae952) 73.96% compared to head (8507466) 73.94%.

Files Patch % Lines
src/point.jl 63.15% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #294      +/-   ##
==========================================
- Coverage   73.96%   73.94%   -0.02%     
==========================================
  Files          36       36              
  Lines        6680     6687       +7     
==========================================
+ Hits         4941     4945       +4     
- Misses       1739     1742       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cormullion cormullion merged commit 8b88e39 into JuliaGraphics:master Feb 17, 2024
9 of 13 checks passed
@cormullion
Copy link
Member

Cool, thanks! This looks like a version 4.0... :)

@hyrodium
Copy link
Contributor Author

Should we create a branch release/v3.9 to release v3.9.0 with deprecation messages? If so, I will create a PR for that!

@cormullion
Copy link
Member

Should we create a branch release/v3.9 to release v3.9.0 with deprecation messages? If so, I will create a PR for that!

Cool, thanks! Can you do this using the commit I've just uploaded? - I've been fixing the broadcasting regressions in the docs...

    # -> 3.9
    # rule.(between.(O - (250, 0), O + (250, 0), 0:0.01:1), -π/3)
    # 4.0 ->
    rule.(between.(Ref(O - (250, 0)), Ref(O + (250, 0)), 0:0.01:1), -π/3)

I write the 3.9 form all the time... :)

@hyrodium hyrodium mentioned this pull request Feb 18, 2024
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.

Base Subtract operator between Luxor.Point and a Number is incorrect
2 participants