|
| 1 | +package trn.duke; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import org.apache.commons.lang3.tuple.ImmutablePair; |
| 7 | +import org.apache.commons.lang3.tuple.Pair; |
| 8 | + |
| 9 | +import trn.Map; |
| 10 | +import trn.Wall; |
| 11 | + |
| 12 | +public class Util { |
| 13 | + |
| 14 | + /** |
| 15 | + * |
| 16 | + * @param map |
| 17 | + * @param sector0 |
| 18 | + * @param sector1 |
| 19 | + * @return wall indexes in each sector that match (by x,y coords) a wall in the other sector |
| 20 | + */ |
| 21 | + public static Pair<List<Integer>, List<Integer>> filterOverlappingPoints(trn.Map map, int sector0, int sector1){ |
| 22 | + |
| 23 | + List<Integer> sector0walls = map.getSectorWallIndexes(sector0); |
| 24 | + List<Integer> sector1walls = map.getSectorWallIndexes(sector1); |
| 25 | + |
| 26 | + List<Integer> sector0wallsOut = new ArrayList<Integer>(sector0walls.size()); |
| 27 | + List<Integer> sector1wallsOut = new ArrayList<Integer>(sector1walls.size()); |
| 28 | + |
| 29 | + |
| 30 | + for(int w0i : sector0walls){ |
| 31 | + for(int w1i : sector1walls){ |
| 32 | + |
| 33 | + if(map.getWall(w0i).sameXY(map.getWall(w1i))){ |
| 34 | + sector0wallsOut.add(w0i); |
| 35 | + sector1wallsOut.add(w1i); |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + return new ImmutablePair<List<Integer>, List<Integer>>(sector0wallsOut, sector1wallsOut); |
| 41 | + } |
| 42 | + |
| 43 | + |
| 44 | + /** |
| 45 | + * orders the walls so that wall 0 points to wall 1 |
| 46 | + * @param map |
| 47 | + * @param walls |
| 48 | + */ |
| 49 | + public static void orderWalls(Map map, Integer ... walls){ |
| 50 | + if(walls[0] == null || walls[1] == null) throw new RuntimeException(); |
| 51 | + |
| 52 | + |
| 53 | + Wall w0 = map.getWall(walls[0]); |
| 54 | + Wall w1 = map.getWall(walls[1]); |
| 55 | + |
| 56 | + if(w0.getPoint2() == walls[1]){ |
| 57 | + //ok |
| 58 | + }else if(w1.getPoint2() == walls[0]){ |
| 59 | + Integer tmp = walls[0]; |
| 60 | + walls[0] = walls[1]; |
| 61 | + walls[1] = tmp; |
| 62 | + }else{ |
| 63 | + throw new RuntimeException("walls are not adjacent"); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * orders the walls so that wall 0 points to wall 1 -- list versino |
| 69 | + * @param map |
| 70 | + * @param walls |
| 71 | + */ |
| 72 | + public static void orderWalls(Map map, List<Integer> walls){ |
| 73 | + if(walls == null || walls.size() != 2) throw new IllegalArgumentException(); |
| 74 | + |
| 75 | + |
| 76 | + Wall w0 = map.getWall(walls.get(0)); |
| 77 | + Wall w1 = map.getWall(walls.get(1)); |
| 78 | + |
| 79 | + if(w0.getPoint2() == walls.get(1)){ |
| 80 | + //ok |
| 81 | + }else if(w1.getPoint2() == walls.get(0)){ |
| 82 | + Integer tmp = walls.get(0); |
| 83 | + walls.set(0, walls.get(1)); |
| 84 | + walls.set(1, tmp); |
| 85 | + }else{ |
| 86 | + throw new RuntimeException("walls are not adjacent"); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + /* so....this is completely useless since we are swapping on a fucking copy... |
| 91 | + public static void orderWalls(Map map, List<Integer> walls){ |
| 92 | + orderWalls(map, walls.toArray(new Integer[]{})); |
| 93 | + }*/ |
| 94 | +} |
0 commit comments