JuliaGeometry / Meshes.jl

Computational geometry and meshing algorithms in Julia
https://juliageometry.github.io/MeshesDocs/stable
Other
376 stars 80 forks source link

`Scale` and `LengthUnit` transforms on geometries #888

Closed cserteGT3 closed 1 month ago

cserteGT3 commented 1 month ago

I'm updating my code after the "unitful" update and found that transformations are not working as I expected on geometries. For example, LengthUnit only changes the point and vector units:

julia> LengthUnit(u"mm")(Sphere(Point(1,1,1)))
Sphere
├─ center: Point(x: 1000.0 mm, y: 1000.0 mm, z: 1000.0 mm)
└─ radius: 1.0 m

or Scale only scales the points, which is (for me at least) counterintuitive for spheres (I expect to change only the radius):

julia> Scale(2)(Sphere(Point(1,1,1)))
Sphere
├─ center: Point(x: 2.0 m, y: 2.0 m, z: 2.0 m)
└─ radius: 1.0 m

I think former is straightforward: the units of all fields should be updated. Scaling (and stretching) could be however controversial.

cserteGT3 commented 1 month ago

In theory this would be enough for LengthUnit:

applycoord(t::LengthUnit, q::Quantity) = uconvert(t.unit, q)
juliohm commented 1 month ago

Thank you for reporting these issues @cserteGT3 , we will take a look.

juliohm commented 1 month ago

or Scale only scales the points, which is (for me at least) counterintuitive for spheres (I expect to change only the radius):

julia> Scale(2)(Sphere(Point(1,1,1)))
Sphere
├─ center: Point(x: 2.0 m, y: 2.0 m, z: 2.0 m)
└─ radius: 1.0 m

In this case, the Scale of a Sphere will be a Ellipsoid, both the center and the radius change: https://juliageometry.github.io/MeshesDocs/stable/geometries/primitives.html#Ellipsoid

The Stretch only affects the radius.