Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow different type for LazyRow index #151

Open
touste opened this issue Sep 17, 2020 · 0 comments
Open

Allow different type for LazyRow index #151

touste opened this issue Sep 17, 2020 · 0 comments

Comments

@touste
Copy link
Contributor

touste commented Sep 17, 2020

Having the possibility to have a different type for the LazyRow index other than I

struct LazyRow{T, N, C, Ic, Ii}
    columns::StructArray{T, N, C, Ic} # a `Columns` object
    index::Ii
end

allows me to define a StructArray of points and a StructArray of triangles, with indexes being of type StaticVectors (a triangle always contains 3 points):

struct Point{T}
    position::SVector{3,T}
    force::SVector{3,T}
end

struct Triangle{Tp}
    points::Tp
end

points = StructArray([Point{Float64}(rand(3), zeros(3)) for _ in 1:10])

tris = StructArray([Triangle(LazyRow(points, @SVector [rand(1:10), rand(1:10), rand(1:10)])) for _ in 1:5])

I can now update the point forces in the triangles this way, which is really helpful in my case:

for t in tris
    pos = t.points.position
    f1 = sum.(pos)
    f2 = tan.(f1)
    f3 = sin.(f1)
    f = Vec3(f1, f2, f3)
    t.points.force += f
end

Does that make sense? Would that make some thing break somewhere?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant