JuliaGeometry / GeometryBasics.jl

Basic Geometry Types
MIT License
164 stars 54 forks source link

Construction from SVector is ambiguous #216

Open aplavin opened 5 months ago

aplavin commented 5 months ago

For example, Point2(SVector(1, 2)) throws:

MethodError: (GeometryBasics.Point2)(::StaticArraysCore.SVector{2, Int64}) is ambiguous.
Candidates:
(::Type{SV})(x::StaticArraysCore.StaticArray{Tuple{N}, T, 1} where {N, T}) where SV<:GeometryBasics.Point
@ GeometryBasics ~/.julia/packages/GeometryBasics/bLARu/src/fixed_arrays.jl:74
(GeometryBasics.Point{S})(x::AbstractVector{T}) where {S, T}
@ GeometryBasics ~/.julia/packages/GeometryBasics/bLARu/src/fixed_arrays.jl:34
(::Type{SA})(sa::StaticArraysCore.StaticArray) where SA<:StaticArraysCore.StaticArray
@ StaticArrays ~/.julia/packages/StaticArrays/EHHaF/src/convert.jl:170
(GeometryBasics.Point{S})(x::T) where {S, T}
@ GeometryBasics ~/.julia/packages/GeometryBasics/bLARu/src/fixed_arrays.jl:48
(T::Type{<:StaticArraysCore.StaticArray})(a::AbstractArray)
@ StaticArrays ~/.julia/packages/StaticArrays/EHHaF/src/convert.jl:174
Possible fix, define
(GeometryBasics.Point{S})(::StaticArraysCore.StaticArray{Tuple{N}, T, 1} where N) where {S, T}
asinghvi17 commented 5 months ago

Ah, I think this is because Point2 is also a subtype of StaticArray. We would probably need to define that dispatch in the macro which generates the point definitions.

In this case, the fix would be GB.Point{N}(::SArray{Tuple{N}, T, 1}) where N = ... or so. I've abbreviated a bit but it should make sense anyway...