Skip to content

update Base.in for HyperSphere #144

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

Merged
merged 1 commit into from
Apr 12, 2021

Conversation

hyrodium
Copy link
Contributor

This PR fixes #108.

Before this PR

julia> using GeometryBasics

julia> C = Circle(Point(1,1),1)
Circle{Int64}([1, 1], 1)

julia> Point(0,0) in C
ERROR: MethodError: no method matching -(::Int64, ::Point2{Int64})
For element-wise subtraction, use broadcasting with dot syntax: scalar .- array
Closest candidates are:
  -(::Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8}) at int.jl:85
  -(::T, ::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8} at int.jl:86
  -(::Union{Int16, Int32, Int64, Int8}, ::BigInt) at gmp.jl:536
  ...
Stacktrace:
 [1] in(x::Point2{Int64}, c::Circle{Int64})
   @ GeometryBasics ~/.julia/dev/GeometryBasics/src/primitives/spheres.jl:36
 [2] top-level scope
   @ REPL[3]:1

julia> S = Sphere(Point(1,1,1),10)
Sphere{Int64}([1, 1, 1], 10)

julia> Point(1,1,1) in S
ERROR: MethodError: no method matching iterate(::Sphere{Int64})
Closest candidates are:
  iterate(::Union{LinRange, StepRangeLen}) at range.jl:664
  iterate(::Union{LinRange, StepRangeLen}, ::Int64) at range.jl:664
  iterate(::T) where T<:Union{Base.KeySet{var"#s79", var"#s78"} where {var"#s79", var"#s78"<:Dict}, Base.ValueIterator{var"#s77"} where var"#s77"<:Dict} at dict.jl:693
  ...
Stacktrace:
 [1] in(x::Point3{Int64}, itr::Sphere{Int64})
   @ Base ./operators.jl:1131
 [2] top-level scope
   @ REPL[5]:1

After this PR

julia> using GeometryBasics

julia> C = Circle(Point(1,1),1)
Circle{Int64}([1, 1], 1)

julia> Point(1,1) in C
true

julia> Point(0,0) in C
false

julia> S = Sphere(Point(1,1,1),10)
Sphere{Int64}([1, 1, 1], 10)

julia> Point(1,1,1) in S
true

@SimonDanisch
Copy link
Member

Thank you :)

@SimonDanisch SimonDanisch merged commit 20215bf into JuliaGeometry:master Apr 12, 2021
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.in(::Point, ::Circle) assumes a circle in L-infinity norm, not L2 norm
2 participants