Skip to content

Figure#translate...() may produce wrong results for PointLists #883

@HeikoKlare

Description

@HeikoKlare

Due to the limited implementation of the PrecisionPointList, the calculations on a wrapped PointList inside the Figure#translate...() calls may lead to wrong results. While this can effectively happen when using any non-overriden method of PrecisionPointList, it particularly happens for performTranslate(), which is called by Figure#translateToParent(), which calls that method:

public void translateToParent(Translatable t) {
if (useLocalCoordinates()) {
t.performTranslate(getBounds().x + getInsets().left, getBounds().y + getInsets().top);
}
}

The unexpected behavior can also be easily demonstrated with this test:

PointList list = new PointList();
list.addPoint(1, 1);
PrecisionPointList precisionList = new PrecisionPointList(list);
precisionList.performTranslate(1, 1);
precisionList.performScale(10);
assertEquals(20, precisionList.getFirstPoint().x);

Would it maybe make sense to update the precise values from the integer values at the beginning of every overridden method in case both became inconsistent? The only alternative to avoid broken behavior seems to be to override every single method with either a proper precision implementation or at least one that updates the precise values after being executed. So as long as all those overrides do not exist, maybe it would be reasonable to just update the precision values at the beginning of those methods that are overriden, if necessary?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions