/** * Create an instance of {@link Coordinate } * */ public Coordinate createCoordinate() { return new Coordinate(); }
private static List<Coordinate> checkAndcreateCoordinates(final Object container, int... shape) { if ((container == null) || (shape == null)) { throw new WebLabUncheckedException("Argument was null."); } if (shape.length % 2 != 0) { throw new WebLabUncheckedException("Coordinate array not valid (should be of an even length)."); } if (shape.length < 4) { throw new WebLabUncheckedException("Not enought coordinates in the shape array (at least two points should be described, i.e. 4 int)."); } final List<Coordinate> coordinates = new LinkedList<Coordinate>(); for (int i = 0; i < shape.length / 2; i++) { final Coordinate coordoI = new Coordinate(); coordoI.setX(shape[2 * i]); coordoI.setY(shape[2 * i + 1]); coordinates.add(coordoI); } return coordinates; }
/** * Both coordinates lists are equals if (and only if) coordinates are one by one equals, i.e. same X, same Y. * * @param coordinate * The left one * @param coordinate2 * The right one * @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second * @warning The code is not safe against on the coordinates ordering. */ private int compareCoordinates(final List<Coordinate> coordinate1, final List<Coordinate> coordinate2) { final int sizeDifference = Integer.signum(coordinate1.size() - coordinate2.size()); if ((sizeDifference == 0) && (!coordinate2.isEmpty())) { // Both are of the same size and are not empty int cpt = 0; final int size = coordinate1.size(); int coordinateDifference; do { coordinateDifference = Float.compare(coordinate1.get(cpt).getX(), coordinate2.get(cpt).getX()); if (coordinateDifference == 0) { coordinateDifference = Float.compare(coordinate1.get(cpt).getY(), coordinate2.get(cpt).getY()); } cpt++; } while ((coordinateDifference == 0) && (cpt < size)); // Return the signum of the first difference between two coordinates. return coordinateDifference; } return sizeDifference; }