/** * Creates a new PRectangle object. The points are automatically normalized by the constructor. * These two coordinates represent the diagonal corners of the rectangle. * * @param p1 first point of diagonal, in the Cartesian coordinate space * @param p2 second point of diagonal, in the Cartesian coordinate space */ public PRectangle(Point2D.Float p1, Point2D.Float p2) { super(); normalizeCoordinates(p1.x, p1.y, p2.x, p2.y); // assign original data p1x = p1.x; p1y = p1.y; p2x = p2.x; p2y = p2.y; }
/** * Creates a new PRectangle object. The points are automatically normalized by the constructor. * * @param coordinates a vector containing four elements where the first and second elements * represent the x and y coordinates of one point and the third and fourth elements represent * the x and y cooordinates of the second point. These two coordinates represent the diagonal * corners of the rectangle. * @throws IllegalArgumentException thrown if coordinates is null or does not have four elements */ public PRectangle(List coordinates) throws IllegalArgumentException { if (coordinates == null || coordinates.size() < 4) throw new IllegalArgumentException(); float x1 = ((Number) coordinates.get(0)).floatValue(); float y1 = ((Number) coordinates.get(1)).floatValue(); float x2 = ((Number) coordinates.get(2)).floatValue(); float y2 = ((Number) coordinates.get(3)).floatValue(); // assign original data p1x = x1; p1y = y1; p2x = x2; p2y = y2; // System.out.println(x1 + " : " + y1 + " : " + x2 + " : " + y2 ); normalizeCoordinates(x1, y1, x2, y2); }