summaryrefslogtreecommitdiff
path: root/NET/worlds/console/MoveablePolygon.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/MoveablePolygon.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/console/MoveablePolygon.java')
-rw-r--r--NET/worlds/console/MoveablePolygon.java58
1 files changed, 58 insertions, 0 deletions
diff --git a/NET/worlds/console/MoveablePolygon.java b/NET/worlds/console/MoveablePolygon.java
new file mode 100644
index 0000000..7607a4f
--- /dev/null
+++ b/NET/worlds/console/MoveablePolygon.java
@@ -0,0 +1,58 @@
+package NET.worlds.console;
+
+import java.awt.Graphics;
+import java.awt.Polygon;
+import java.awt.Rectangle;
+
+class MoveablePolygon extends Polygon {
+ private static final long serialVersionUID = 8800634603983512717L;
+ private int xOffset;
+ private int yOffset;
+ private Rectangle boundingBox = new Rectangle();
+
+ public MoveablePolygon() {
+ }
+
+ public MoveablePolygon(int[] xpoints, int[] ypoints) {
+ super(xpoints, ypoints, xpoints.length);
+ }
+
+ public void moveTo(int x, int y) {
+ if (x != this.xOffset || y != this.yOffset) {
+ int xdelta = x - this.xOffset;
+ int ydelta = y - this.yOffset;
+ this.xOffset = x;
+ this.yOffset = y;
+
+ for (int i = 0; i < this.npoints; i++) {
+ this.xpoints[i] = this.xpoints[i] + xdelta;
+ this.ypoints[i] = this.ypoints[i] + ydelta;
+ }
+ }
+ }
+
+ public void drawFilled(Graphics g, int x, int y) {
+ this.moveTo(x, y);
+ g.fillPolygon(this);
+ }
+
+ @Override
+ public Rectangle getBoundingBox() {
+ int boundsMinX = Integer.MAX_VALUE;
+ int boundsMinY = Integer.MAX_VALUE;
+ int boundsMaxX = Integer.MIN_VALUE;
+ int boundsMaxY = Integer.MIN_VALUE;
+
+ for (int i = 0; i < this.npoints; i++) {
+ int x = this.xpoints[i];
+ boundsMinX = Math.min(boundsMinX, x);
+ boundsMaxX = Math.max(boundsMaxX, x);
+ int y = this.ypoints[i];
+ boundsMinY = Math.min(boundsMinY, y);
+ boundsMaxY = Math.max(boundsMaxY, y);
+ }
+
+ this.boundingBox.reshape(boundsMinX, boundsMinY, boundsMaxX - boundsMinX, boundsMaxY - boundsMinY);
+ return this.boundingBox;
+ }
+}