euclid icon indicating copy to clipboard operation
euclid copied to clipboard

Add `ReferenceFrame#hasBeenRemoved`

Open calvertdw opened this issue 1 year ago • 3 comments

There's not way to check if a ReferenceFrame has been removed from the tree in order to handle that case properly. The only option currently is checkIsRemoved which is protected and throws a RuntimeException.

calvertdw avatar Aug 11 '23 19:08 calvertdw

Typically, the frame gets removed for garbage collection, this was not intended to be a feature allowing a frame to be added and then removed by hand really. I'm getting the feel that you're trying to use the remove thingy in a particular way and we should prob do an iteration on the class to support that properly. Can you expand on what you're trying to do?

SylvainBertrand avatar Aug 14 '23 14:08 SylvainBertrand

Sneaky workaround

private static final Field referenceFrameHasBeenRemoved;
static
{
   try
   {
      referenceFrameHasBeenRemoved = ReferenceFrame.class.getDeclaredField("hasBeenRemoved");
      referenceFrameHasBeenRemoved.setAccessible(true);
   }
   catch (NoSuchFieldException e)
   {
      throw new RuntimeException(e);
   }
}
public static boolean hasBeenRemoved(ReferenceFrame referenceFrame)
{
   try
   {
      return referenceFrameHasBeenRemoved.getBoolean(referenceFrame);
   }
   catch (IllegalAccessException e)
   {
      throw new RuntimeException(e);
   }
}

calvertdw avatar Aug 16 '23 19:08 calvertdw

Two improvements would help:

  • Being able to change the parent frame
  • Being able to access the transformToParent to modify it rather than having to hold onto an instance that was passed in on construction

calvertdw avatar Aug 16 '23 19:08 calvertdw