This is what I use for my Polygon areas, it has some extra methods that prove to be useful at times.
package tools;
import org.osbot.script.rs2.map.Position;
import org.osbot.script.rs2.model.Entity;
import java.awt.*;
/**
* Created with IntelliJ IDEA.
* User: NotoriousPP
* Date: 2/6/14
* Time: 8:53 PM
*/
public class Area {
private Polygon polyArea;
public Area(Position... cords){
polyArea = new Polygon();
addPositions(cords);
}
public Area(int xL, int yL, int xH, int yH){
polyArea = new Polygon();
polyArea.addPoint(xL, yL);
polyArea.addPoint(xH, yH);
}
public boolean contains(Entity e){
return polyArea.contains(e.getX(), e.getY());
}
public boolean contains(Position p){
return polyArea.contains(p.getX(), p.getY());
}
public Position getCenterTile(){
int lowX = 0, lowY = 0;
int highX = 0, highY = 0;
for(int i : polyArea.xpoints){
if(lowX == 0 || i < lowX){
lowX = i;
}
if(highX == 0 || i > highX){
highX = i;
}
}
for(int i : polyArea.ypoints){
if(lowY == 0 || i < lowY){
lowY = i;
}
if(highY == 0 || i > highY){
highY = i;
}
}
int x = ((highX + lowX)/2), y = ((highY + lowY)/2);
return new Position(x,y,0);
}
public int getLowestX(){
int lowX = 0;
for(int i : polyArea.xpoints){
if(lowX == 0 || i < lowX){
lowX = i;
}
}
if(lowX != 0){
return lowX;
}
return -1;
}
public int getLowestY(){
int lowY = 0;
for(int i : polyArea.ypoints){
if(lowY == 0 || i < lowY){
lowY = i;
}
}
if(lowY != 0){
return lowY;
}
return -1;
}
public int getHighestX(){
int highX = 0;
for(int i : polyArea.xpoints){
if(highX == 0 || i > highX){
highX = i;
}
}
if(highX != 0){
return highX;
}
return -1;
}
public org.osbot.script.rs2.utility.Area getOSArea(){
return new org.osbot.script.rs2.utility.Area(getLowestX(), getLowestY(), getHighestX(), getHighestY());
}
public int getHighestY(){
int highY = 0;
for(int i : polyArea.ypoints){
if(highY == 0 || i > highY){
highY = i;
}
}
if(highY != 0){
return highY;
}
return -1;
}
private void addPositions(Position... positions){
for (Position pos : positions){
polyArea.addPoint(pos.getX(), pos.getY());
}
}
}