diff options
| author | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
| commit | c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch) | |
| tree | df9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/MoveablePolygon.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/console/MoveablePolygon.java')
| -rw-r--r-- | NET/worlds/console/MoveablePolygon.java | 58 |
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; + } +} |