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

Add Comments about TransformTo #436

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,18 @@ localToGlobalMap.AtomicObject is ITransformable transformable // and ICurve
&& localToGlobalMap.AtomicObject["units"] is string units
)
{
//TODO TransformTo will be deprecated as it's dangerous and requires ID transposing which is wrong!
//ID needs to be copied to the new instance
var id = localToGlobalMap.AtomicObject.id;
ITransformable? newTransformable = null;
foreach (var mat in localToGlobalMap.Matrix)
{
transformable.TransformTo(new Transform() { matrix = mat, units = units }, out newTransformable);
transformable = newTransformable; // we need to keep the reference to the new object, as we're going to use it in the cache'
transformable = newTransformable; // we need to keep the reference to the new object, as we're going to use it in the cache
}

localToGlobalMap.AtomicObject = (newTransformable as Base)!;
localToGlobalMap.AtomicObject.id = id; // restore the id, as it's used in the cache'
localToGlobalMap.AtomicObject.id = id; // restore the id, as it's used in the cache
localToGlobalMap.Matrix = new HashSet<Matrix4x4>(); // flush out the list, as we've applied the transforms already
}

Expand Down
8 changes: 5 additions & 3 deletions Sdk/Speckle.Converters.Common/LocalToGlobalConverterUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ public Base TransformObjects(Base atomicObject, IReadOnlyCollection<Matrix4x4> m

if (atomicObject is ITransformable c)
{
//TODO TransformTo will be deprecated as it's dangerous and requires ID transposing which is wrong!
//ID needs to be copied to the new instance
string id = atomicObject.id.NotNull();
foreach (var transform in transforms)
{
c.TransformTo(transform, out ITransformable newObj);
c = newObj;
c = newObj; // we need to keep the reference to the new object, as we're going to use it in the cache
}

if (c is not Base)
Expand All @@ -46,8 +49,7 @@ public Base TransformObjects(Base atomicObject, IReadOnlyCollection<Matrix4x4> m
);
}

string id = atomicObject.id.NotNull();
atomicObject = (Base)c;
atomicObject = (Base)c; // restore the id, as it's used in the cache
atomicObject.id = id;

// .TransformTo only transfers typed properties, we need to add back the dynamic ones:
Expand Down
Loading