int (Rectangle aRectangle, Line2D aSegment) { Point northWest = new OrientedPoint(aRectangle.getX(), aRectangle.getY(), NORTH_WEST); Point northEast = new OrientedPoint(aRectangle.getMaxX(), aRectangle.getY(), NORTH_EAST); Point southEast = new OrientedPoint(aRectangle.getMaxX(), aRectangle.getMaxY(), SOUTH_EAST); Point southWest = new OrientedPoint(aRectangle.getX(), aRectangle.getMaxY(), SOUTH_WEST); TreeMap sorter = new TreeMap(); sorter.put(getDistance(aSegment, northWest), northWest); sorter.put(getDistance(aSegment, southWest), southWest); sorter.put(getDistance(aSegment, southEast), southEast); sorter.put(getDistance(aSegment, northEast), northEast); return ((OrientedPoint) sorter.get(sorter.firstKey())).getOrientation(); }