GeometryBasics.jl icon indicating copy to clipboard operation
GeometryBasics.jl copied to clipboard

Do not define `Base.in` instead of `Base.issubset` (taking set theory seriously)

Open goretkin opened this issue 3 years ago • 3 comments

The definition at

https://github.com/JuliaGeometry/GeometryBasics.jl/blob/234699e015ccb23bdaab26539dfc8fdfa9ff6add/src/primitives/rectangles.jl#L469-L481

is not in the spirit of Base.in, and instead that procedure should be a method for Base.issubset ().

see for example:

https://github.com/invenia/Intervals.jl/blob/168565ef0a40d022bfe4030d0178cb1b83fff6cb/src/interval.jl#L370-L375

Base.in(a, b::AbstractInterval) = !(a ≫ b || a ≪ b)

function Base.in(a::AbstractInterval, b::AbstractInterval)
    # Intervals should be compared with set operations
    throw(ArgumentError("Intervals can not be compared with `in`. Use `issubset` instead."))
end

These operations are related, even graphically (∈ ⊂), but should not be mixed up.

goretkin avatar Nov 25 '20 22:11 goretkin

Related distinction for sequences:

julia> "h" in "hey"
ERROR: use occursin(x, y) for string containment
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] in(::String, ::String) at ./strings/search.jl:535
 [3] top-level scope at REPL[79]:1

julia> 'h' in "hey"
true

goretkin avatar Nov 25 '20 22:11 goretkin

@goretkin if you are interested in a more consistent mathematical approach to these issues, consider taking a look at Meshes.jl. I believe it is too hard to fix GeometryBasics.jl without breaking other packages downstream.

juliohm avatar Nov 25 '20 22:11 juliohm

Renaming in seems like something we can easily fix with proper deprecation ;)

SimonDanisch avatar Nov 26 '20 12:11 SimonDanisch