Reducing allocations count when working with bounding boxes (#843)

This commit is contained in:
Konstantin Shandurenko 2022-03-31 20:48:43 +03:00 committed by GitHub
parent 4c8b4c1abc
commit eebdb4a7a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,7 @@ import org.jetbrains.annotations.NotNull;
public final class BoundingBox implements Shape {
private final double width, height, depth;
private final Point offset;
private Point relativeEnd;
BoundingBox(double width, double height, double depth, Point offset) {
this.width = width;
@ -73,7 +74,9 @@ public final class BoundingBox implements Shape {
@Override
public @NotNull Point relativeEnd() {
return offset.add(width, height, depth);
Point relativeEnd = this.relativeEnd;
if (relativeEnd == null) this.relativeEnd = relativeEnd = offset.add(width, height, depth);
return relativeEnd;
}
@Override