Skip to content

Commit

Permalink
[426] DRAFT - Add cache
Browse files Browse the repository at this point in the history
  • Loading branch information
lredor committed Jul 31, 2024
1 parent 2464c27 commit 79e87c4
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -130,6 +131,8 @@ public final class GMFHelper {
*/
private static final int ICON_TEXT_GAP = 3;

private static Map<Node, Rectangle> boundsCache = new HashMap<>();

private GMFHelper() {
// Helper to not instantiate
}
Expand Down Expand Up @@ -616,9 +619,23 @@ public static Rectangle getAbsoluteBounds(Node node, boolean insetsAware, boolea
* @return the absolute bounds of the node relative to the origin (Diagram)
*/
public static Rectangle getAbsoluteBounds(Node node, boolean insetsAware, boolean boxForConnection, boolean recursiveGetBounds) {
Point location = getAbsoluteLocation(node, insetsAware);
Rectangle bounds = getBounds(node, false, false, boxForConnection, recursiveGetBounds, location);
return new PrecisionRectangle(location.preciseX(), location.preciseY(), bounds.preciseWidth(), bounds.preciseHeight());
if (!recursiveGetBounds) {
boundsCache.clear();
}
Rectangle result;
if (boundsCache.containsKey(node)) {
result = boundsCache.get(node);
} else {
Point location = getAbsoluteLocation(node, insetsAware);
Rectangle bounds = getBounds(node, false, false, boxForConnection, recursiveGetBounds, location);
result = new PrecisionRectangle(location.preciseX(), location.preciseY(), bounds.preciseWidth(), bounds.preciseHeight());
if (!recursiveGetBounds) {
boundsCache.clear();
} else {
boundsCache.put(node, result);
}
}
return result;
}

/**
Expand Down

0 comments on commit 79e87c4

Please sign in to comment.