GeometryBasics.jl icon indicating copy to clipboard operation
GeometryBasics.jl copied to clipboard

StructArrays interface for points

Open asinghvi17 opened this issue 5 years ago • 8 comments

When calling into C functions with large arrays of points, it would be useful to have mutable StructArrays of points. As far as I understand it, this would just involve defining a static schema for Points.

Would this be a wanted feature? Also, how would we handle vectors of n-dimensional Points?

asinghvi17 avatar May 05 '20 08:05 asinghvi17

it would be useful to have mutable StructArrays of point

Why? Can you give a concrete example?

SimonDanisch avatar May 05 '20 09:05 SimonDanisch

Transformations with the Proj library come to mind - it accepts separate arrays of x, y, and z, and the most efficient mode of operation is to operate in place. Having 3 arrays of x, y, and z which could be transformed in place would be pretty useful, especially when you get into >500K points.

asinghvi17 avatar May 05 '20 09:05 asinghvi17

I thought this was trivially supported, but can't find the correct constructor right now :D Evidence, that this should be made easier & documented...

SimonDanisch avatar May 05 '20 10:05 SimonDanisch

After talking with @piever it may be a bug: https://github.com/JuliaArrays/StructArrays.jl/issues/126

SimonDanisch avatar May 05 '20 10:05 SimonDanisch

Well I tried it a while ago...the issue is that we store the data in a tuple, so StructArrays just makes an array of tuples, which is useless for this. We need to define our own static schema which takes, for example, a Point3f0, and maps it to x, y, and z (or x1, x2 and x3, but that's uglier)...

asinghvi17 avatar May 05 '20 11:05 asinghvi17

Yeah, but this is supposed to "just work"... So lets see if we can have this fixed ;)

SimonDanisch avatar May 05 '20 11:05 SimonDanisch

I've commented over at https://github.com/JuliaArrays/StructArrays.jl/issues/126#issuecomment-624011508. It can be made to work already if one calls the constructor in a slightly different way, and one gets a

StructArray(data::StructArray(::Array{Float32,1}, ::Array{Float32,1}, ::Array{Float32,1}))

piever avatar May 05 '20 11:05 piever

Alright, that's fair! I think GeometryBasics should just support a convenience constructor for this :)

SimonDanisch avatar May 05 '20 12:05 SimonDanisch