Skip to content

Can't construct a LineString from a view of a point vector #231

@asinghvi17

Description

@asinghvi17

In v0.5,

using GeometryBasics
points = rand(Point2f, 10)

LineString(view(points, 1:5))

errors with:

ERROR: MethodError: no method matching LineString(::SubArray{Point{2, Float32}, 1, Vector{Point{2, Float32}}, Tuple{UnitRange{Int64}}, true})
The type `LineString` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  LineString(::Array{Point{Dim, T}, 1}) where {Dim, T<:Real}
   @ GeometryBasics ~/.julia/dev/GeometryBasics/src/basic_types.jl:347

Stacktrace:
 [1] top-level scope
   @ REPL[50]:1

It looks like the array type in LineString is now restrictive. Should we allow any abstract vector in there, and add an extra type parameter? Or is there some other way this should be done?

I ask because it's pretty hard to minimize allocations with this approach. If the issue is purely in the type printing, then it's easy enough to fix that to not show the last type parameter (the array type).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions