2015-02-27 15:29:33 -05:00
|
|
|
package bwta;
|
|
|
|
|
|
|
|
import bwta.*;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.List;
|
|
|
|
import bwapi.Position;
|
|
|
|
import bwapi.TilePosition;
|
|
|
|
import bwapi.Player;
|
|
|
|
import bwapi.Unit;
|
2015-03-22 13:44:15 -04:00
|
|
|
import bwapi.Pair;
|
2015-02-27 15:29:33 -05:00
|
|
|
|
2015-07-12 09:35:38 -04:00
|
|
|
/**
|
|
|
|
A Polygon is a geometric representation of <a href="Region.html">Region</a>
|
|
|
|
|
|
|
|
*/
|
2015-02-27 15:29:33 -05:00
|
|
|
public class Polygon {
|
|
|
|
|
2015-07-12 09:35:38 -04:00
|
|
|
/**
|
|
|
|
Returns the area of the polygon.
|
|
|
|
|
|
|
|
*/
|
2015-02-27 15:29:33 -05:00
|
|
|
public double getArea() {
|
|
|
|
return getArea_native(pointer);
|
|
|
|
}
|
|
|
|
|
2015-07-12 09:35:38 -04:00
|
|
|
/**
|
|
|
|
Returns the perimeter of the polygon.
|
|
|
|
|
|
|
|
*/
|
2015-02-27 15:29:33 -05:00
|
|
|
public double getPerimeter() {
|
|
|
|
return getPerimeter_native(pointer);
|
|
|
|
}
|
|
|
|
|
2015-07-12 09:35:38 -04:00
|
|
|
/**
|
|
|
|
Returns the centroid of the polygon.
|
|
|
|
|
|
|
|
*/
|
2015-02-27 15:29:33 -05:00
|
|
|
public Position getCenter() {
|
|
|
|
return getCenter_native(pointer);
|
|
|
|
}
|
|
|
|
|
2015-07-12 09:35:38 -04:00
|
|
|
/**
|
|
|
|
Returns true if the given point is inside the polygon.
|
|
|
|
|
|
|
|
*/
|
2015-02-27 15:29:33 -05:00
|
|
|
public boolean isInside(Position p) {
|
|
|
|
return isInside_native(pointer, p);
|
|
|
|
}
|
|
|
|
|
2015-07-12 09:35:38 -04:00
|
|
|
/**
|
|
|
|
Returns the point on the boundary of the polygon that is nearest to the given point.
|
|
|
|
|
|
|
|
*/
|
2015-02-27 15:29:33 -05:00
|
|
|
public Position getNearestPoint(Position p) {
|
|
|
|
return getNearestPoint_native(pointer, p);
|
|
|
|
}
|
|
|
|
|
2015-04-19 12:13:03 -04:00
|
|
|
public List<Polygon> getHoles() {
|
|
|
|
return getHoles_native(pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<Position> getPoints() {
|
|
|
|
return getPoints_native(pointer);
|
|
|
|
}
|
|
|
|
|
2015-02-27 15:29:33 -05:00
|
|
|
|
|
|
|
private static Map<Long, Polygon> instances = new HashMap<Long, Polygon>();
|
|
|
|
|
|
|
|
private Polygon(long pointer) {
|
|
|
|
this.pointer = pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Polygon get(long pointer) {
|
|
|
|
if (pointer == 0 ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
Polygon instance = instances.get(pointer);
|
|
|
|
if (instance == null ) {
|
|
|
|
instance = new Polygon(pointer);
|
|
|
|
instances.put(pointer, instance);
|
|
|
|
}
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
private long pointer;
|
|
|
|
|
|
|
|
private native double getArea_native(long pointer);
|
|
|
|
|
|
|
|
private native double getPerimeter_native(long pointer);
|
|
|
|
|
|
|
|
private native Position getCenter_native(long pointer);
|
|
|
|
|
|
|
|
private native boolean isInside_native(long pointer, Position p);
|
|
|
|
|
|
|
|
private native Position getNearestPoint_native(long pointer, Position p);
|
|
|
|
|
2015-04-19 12:13:03 -04:00
|
|
|
private native List<Polygon> getHoles_native(long pointer);
|
|
|
|
|
|
|
|
private native List<Position> getPoints_native(long pointer);
|
|
|
|
|
2015-02-27 15:29:33 -05:00
|
|
|
|
|
|
|
}
|