public Element(Poynt s, Poynt e) throws IllegalCircuitException { // Check that element is not of zero length if (s.equals(e)) throw new IllegalCircuitException("Elements may not be of zero length."); start = Poynt.minimum(s, e); end = start.equals(s) ? e : s; try { isHorizontal = Dir.getDirection(s, e).isHorizontal(); } catch (DirException ex) { throw new IllegalCircuitException( "Element must be positioned either horizontally or vertically."); } if (isHorizontal) length = e.x - s.x; else length = e.y - s.y; assert length >= 0; poynts = new LinkedList<Poynt>(); poynts.add(start); Poynt prev, next; prev = next = start; start.setIsOnCircuit(); start.addLoop(); start.addElement(this); while (!next.equals(end)) { try { if (isHorizontal) next = prev.get(Dir.EAST); else next = prev.get(Dir.SOUTH); } catch (IndexOutOfBoundsException ex) { System.out.println("THE ERROR OCCURED DURING THE CONSTRUCTION OF ELEMENT " + this + "."); throw ex; } poynts.add(next); next.setIsOnCircuit(); next.addLoop(); next.addElement(this); prev.addNeighbor(next); next.addNeighbor(prev); prev = next; assert length == poynts.size(); directions = new DirTable(); } }