JuliaGeometry / GeometryTypes.jl

Geometry types for Julia
Other
67 stars 41 forks source link

promote `HyperRectangle` numeric type instead of error #185

Open goretkin opened 4 years ago

goretkin commented 4 years ago
julia> bb1 = HyperRectangle{2,Int64}([0, 0], [1, 1])

HyperRectangle{2,Int64}([0, 0], [1, 1])

julia> bb2 = HyperRectangle{2,Float64}([-3.436309307146981, -3.4222642784489077], [-8.886452461851743, -14.325391136732803])
HyperRectangle{2,Float64}([-3.436309307146981, -3.4222642784489077], [-8.886452461851743, -14.325391136732803])

julia> bb1 ∩ bb2
ERROR: MethodError: no method matching iterate(::HyperRectangle{2,Int64})
sjkelly commented 4 years ago

I've fixed the numeric promotion error here, but I am not sure what the expected result should be with negative widths. With the current implementation I get:

    bb1 = HyperRectangle{2,Int64}([0, 0], [1, 1])
    bb2 = HyperRectangle{2,Float64}([-3.436309307146981, -3.4222642784489077], [-8.886452461851743, -14.325391136732803])
    @show bb1 ∩ bb2 == HyperRectangle{2,Float64}([0.0, 0.0], [-12.322761768998724, -17.74765541518171])

Which seems non sensical. Since the widths are negative it should be origin = [0,0] and widths=[0,0]?

goretkin commented 4 years ago

Thanks for fixing it! I didn't even notice the actual numbers. It was just an example that was randomly generated in my code.

The parameterization of axis-aligned bounding boxes here is origin and widths. If instead it was lower, and upper, then negative width would correspond to lower>upper. If the intersection logic were written in those terms, I think the result would be widths .== 0. But perhaps we can postpone that for later. It wasn't the intention of opening this issue.