public void remRoad(int pos) throws InfraException { if (pos > 3 || pos < 0) throw new InfraException("Position out of range"); Road road = allRoads[pos]; if (road == null) throw new InfraException("Road at position " + pos + " does not exist"); allRoads[pos] = null; alphaRoads = (Road[]) Arrayutils.remElement(alphaRoads, road); updateLanes(); calculateWidth(); }
public void addRoad(Road r, int pos) throws InfraException { if (r == null) throw new InfraException("Parameter r is null"); if (pos > 3 || pos < 0) throw new InfraException("Position out of range"); if (allRoads[pos] != null) throw new InfraException("Road already connected to position " + pos); allRoads[pos] = r; Node other = r.getOtherNode(this); if (other == null || !other.isAlphaRoad(r)) alphaRoads = (Road[]) Arrayutils.addElement(alphaRoads, r); updateLanes(); calculateWidth(); }
public void remRoad(Road r) throws InfraException { if (r == null) throw new InfraException("Parameter r is null"); alphaRoads = (Road[]) Arrayutils.remElement(alphaRoads, r); for (int i = 0; i < 4; i++) { if (allRoads[i] == r) { allRoads[i] = null; updateLanes(); calculateWidth(); return; } } throw new InfraException("Road not found in this node"); }
/** * Returns an array of all lanes connected to this node, in clock-wise order, starting at the * given lane */ public Drivelane[] getAllLanesCW(Drivelane lane) throws InfraException { Drivelane[] lanes = getAllLanes(); // in clockwise order starting at road 0, lane 0 // find the starting-lane int i = Arrayutils.findElement(lanes, lane); if (i == -1) throw new InfraException("Lane is not on this node"); // shift all the lanes i places and remove the i-th element Drivelane[] result = new Drivelane[lanes.length - 1]; System.arraycopy(lanes, i + 1, result, 0, lanes.length - i - 1); System.arraycopy(lanes, 0, result, lanes.length - i - 1, i); return result; }
/** * Extracts all the primitive types (2^n) from a given type-integer * * @param type The type-integer to extract. * @param returns The array of primitive integer types. */ public static int[] getTypes(int type) { // System.out.println("To Type: "+type); if (type == 0) return new int[0]; int log = (int) Math.floor(Math.log(type) / Math.log(2)); // System.out.println("Log: "+log); int checktype = (int) Math.pow(2, log); int[] types = new int[log + 1]; int c = 0; for (; type > 0; checktype /= 2) { // System.out.println("Checktype = "+checktype); if (checktype > type) continue; types[c] = checktype; type -= checktype; c++; } return (int[]) Arrayutils.cropArray(types, c); }
/** Removes a sign configuration */ public void remSignconfig(Sign[] conf) throws InfraException { if (conf == null) throw new InfraException("Parameter conf is null"); int i = Arrayutils.findElement(signconfigs, conf); if (i == -1) throw new InfraException("Sign configuration is not in the list"); signconfigs = (Sign[][]) Arrayutils.remElement(signconfigs, i); }
/** Adds a sign configuration */ public void addSignconfig(Sign[] conf) throws InfraException { if (conf == null) throw new InfraException("Parameter conf is null"); signconfigs = (Sign[][]) Arrayutils.addElement(signconfigs, conf); }
public void setAlphaRoad(int pos) throws InfraException { if (pos > 3 || pos < 0) throw new InfraException("Position out of range"); if (allRoads[pos] == null) throw new InfraException("No road is conencted at position " + pos); alphaRoads = (Road[]) Arrayutils.addElementUnique(alphaRoads, allRoads[pos]); updateLanes(); }