Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static final int LOCATION_X = 0;
- static final int LOCATION_Z = 1;
- /**
- * fはflagのf (0はダミーエリアでfalse,1はtrue)
- */
- public boolean inArea(Location l, ArraySet<location> locs) {
- return inArea(l, locs, 0)
- }
- public boolean inArea(Location l, ArraySet<Location> locs, int f) {
- if (isSquare(locs)) { // 実際はフィールドではないことに留意(SWは南西、NEは北東)
- return locs.SW.getX < l.getX && locs.SW.getZ < l.getZ && locs.NE.getX > l.getX && locs.NE.getZ > l;
- } elseif (isTriangle(locs)) {
- return ws(locs[0], locs[1], locs[2], l);
- } else { // 多角形
- Location nwst = new Location (min(locs,LOCATION_X),-114514,min(loc,LOCATION_Z)
- Location nest = new Location (max(locs,LOCATION_X),-114514,min(loc,LOCATION_Z)
- Location swst = new Location (min(locs,LOCATION_X),-114514,max(loc,LOCATION_Z)
- Location sest = new Location (man(locs,LOCATION_X),-114514,man(loc,LOCATION_Z)
- boolean inDummyArea = false;
- //ダミーエリアの生成
- ArrayList<Location> dummysNW = new ArrayList<>()
- ArrayList<Location> dummysNE = new ArrayList<>()
- ArrayList<Location> dummysSW = new ArrayList<>()
- ArrayList<Location> dummysSE = new ArrayList<>()
- for (Location lc : locs.values) {
- if (lc.getX > nwst.getX || lc.getZ > nwst.getZ) {
- dummysNW.add(lc);
- }
- if (lc.getX < nest.getX || lc.getZ > nwst.getZ) {
- dummysNE.add(lc);
- }
- if (lc.getX < sest.getX || lc.getZ < sest.getZ) {
- dummysSE.add(lc);
- }
- if (lc.getX > swst.getX || lc.getZ < swst.getZ) {
- dummysSW.add(lc);
- }
- }
- //ダミーエリアの中にいるか?
- if (inArea(l, dummysNW, !f) || inArea(l, dummysNE, !f) || inArea(l, dummysSE, !f) || inArea(l, dummysSW, !f)) { // ここでダミーエリアのダミーエリアは判定したいエリア
- inDummyArea = true;
- }
- if (inDummyArea) {
- return f;
- } else {
- return !f;
- }
- }
- }
- public double min(ArraySet<Location> locs,int flag) {
- switch (flag) {
- case LOCATION_X:
- double x;
- for (Location l : locs.values) {
- if (x > l.getX) x = l.getX
- }
- return x;
- case LOCATION_Z:
- double z;
- for (Location l : locs.values) {
- if (z > l.getZ) z = l.getZ
- }
- return z;
- default:
- throw new IllegalArgumentException();
- return null;
- }
- }
- public double max(ArraySet<Location> locs,int flag) {
- switch (flag) {
- case LOCATION_X:
- double x;
- for (Location l : locs.values) {
- if (x < l.getX) x = l.getX
- }
- return x;
- case LOCATION_Z:
- double z;
- for (Location l : locs.values) {
- if (z < l.getZ) z = l.getZ
- }
- return z;
- default:
- throw new IllegalArgumentException();
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement