ihmcrobotics / euclid

Vector math, geometry, reference frame, and shapes 2D & 3D

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add `ReferenceFrame#hasBeenRemoved`

calvertdw opened this issue · 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.

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?

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);
   }
}

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