Skip to content

Commit

Permalink
Cache some BB area calcs
Browse files Browse the repository at this point in the history
  • Loading branch information
cam72cam committed Mar 25, 2020
1 parent 99bd87e commit e4e4c27
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/main/java/cam72cam/immersiverailroading/util/RealBB.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ public double calculateYOffset(IBoundingBox other, double offsetY) {
public double calculateZOffset(IBoundingBox other, double offsetZ) {
return 0;
}


private Area myArea;
public Pair<Boolean, Double> intersectsAt(Vec3d min, Vec3d max, boolean useHeightmap) {
if (!(this.min.x < max.x && this.max.x > min.x && this.min.y < max.y && this.max.y > min.y && this.min.z < max.z && this.max.z > min.z)) {
return Pair.of(false, min.y);
Expand All @@ -172,17 +173,19 @@ public Pair<Boolean, Double> intersectsAt(Vec3d min, Vec3d max, boolean useHeigh
} else {
otherRect.add(max.x, max.z);
}

Rectangle2D myRect = new Rectangle2D.Double(this.rear, -this.width/2, 0, 0);
myRect.add(this.front, this.width/2);


if (myArea == null) {
Rectangle2D myRect = new Rectangle2D.Double(this.rear, -this.width / 2, 0, 0);
myRect.add(this.front, this.width / 2);

myArea = new Area(myRect);
AffineTransform myTransform = new AffineTransform();
myTransform.translate(this.centerX, this.centerZ);
myArea.transform(myTransform);
}

Area otherArea = new Area(otherRect);
Area myArea = new Area(myRect);

AffineTransform myTransform = new AffineTransform();
myTransform.translate(this.centerX, this.centerZ);
myArea.transform(myTransform);


AffineTransform otherTransform = new AffineTransform();
otherTransform.rotate(Math.toRadians(180-yaw+90), this.centerX, this.centerZ);
otherArea.transform(otherTransform);
Expand Down Expand Up @@ -232,7 +235,7 @@ public Pair<Boolean, Double> intersectsAt(Vec3d min, Vec3d max, boolean useHeigh
public boolean intersects(Vec3d minIn, Vec3d maxIn) {
Vec3d min = minIn.min(maxIn);
Vec3d max = maxIn.max(minIn);
return intersectsAt(min, max, true).getLeft();
return intersectsAt(min, max, false).getLeft();
}

@Override
Expand Down

0 comments on commit e4e4c27

Please sign in to comment.