JuliaGeometry / Meshes.jl

Computational geometry in Julia
https://juliageometry.github.io/MeshesDocs/stable
Other
389 stars 84 forks source link

Stack overflow when intersecting a triangle and a ball #246

Closed CameronBieganek closed 2 years ago

CameronBieganek commented 2 years ago

I'm not surprised that taking the intersection of a polygon with a primitive shape like a ball is not supported, since that's more in the realm of constructive solid geometry, but it might be nice if we could get a method error (or some other error) instead of a stack overflow:

julia> c = Ball(Point(0, 0), 1.0)
Ball{2,Float64}(Point(0.0, 0.0), 1.0))

julia> t = Triangle(Point(0, 0), Point(2, 0), Point(0, 2))
Triangle{2,Float64}
  └─Point(0.0, 0.0)
  └─Point(2.0, 0.0)
  └─Point(0.0, 2.0)

julia> t ∩ c
ERROR: StackOverflowError:
Stacktrace:
 [1] intersecttype(f::Function, g1::Ball{2, Float64}, g2::Triangle{2, Float64, SVector{3, Point2}}) (repeats 79984 times)
   @ Meshes ~/.julia/packages/Meshes/6EgDO/src/intersections.jl:37
juliohm commented 2 years ago

If you are only interested in knowing if they intersect you can do hasintersect(t, c) to get true or false as result. But I agree we should provide a better error message and avoid StackOverflow if the code changes aren't severe. Mind submitting a PR?

CameronBieganek commented 2 years ago

I'm interested in making some contributions. But I can't make any guarantees that I'll find the time. :sweat_smile: