1
0
mirror of https://github.com/demodude4u/Factorio-FBSR.git synced 2024-11-24 08:12:21 +02:00

Selection boxes are now rotated to correct alignment calculation

This commit is contained in:
Weston Rye (Demod) 2017-06-18 21:56:10 -05:00
parent a8aab64afc
commit 8c040d1a7c
2 changed files with 11 additions and 4 deletions

View File

@ -1,5 +1,6 @@
package com.demod.fbsr;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.awt.geom.Rectangle2D;
@ -86,4 +87,10 @@ public enum Direction {
Direction[] values = values();
return values[(((ordinal() + deltaIndex) % values.length) + values.length) % values.length];
}
public Rectangle2D rotateBounds(Rectangle2D bounds) {
AffineTransform at = new AffineTransform();
at.rotate(Math.PI * 2.0 * ordinal() / 8.0);
return at.createTransformedShape(bounds).getBounds2D();
}
}

View File

@ -93,14 +93,14 @@ public class FBSR {
}
Point2D.Double position = tuple.entity.getPosition();
Rectangle2D.Double selectionBox;
Rectangle2D selectionBox;
if (tuple.prototype != null) {
selectionBox = tuple.prototype.getSelectionBox();
selectionBox = tuple.entity.getDirection().rotateBounds(tuple.prototype.getSelectionBox());
} else {
selectionBox = new Rectangle2D.Double();
}
Rectangle2D.Double bounds = new Rectangle2D.Double(selectionBox.x + position.x, selectionBox.y + position.y,
selectionBox.width, selectionBox.height);
Rectangle2D.Double bounds = new Rectangle2D.Double(selectionBox.getX() + position.x,
selectionBox.getY() + position.y, selectionBox.getWidth(), selectionBox.getHeight());
// System.out.println(bounds);
// Everything is doubled and rounded to the closest original 0.5