< prev index next >

## src/java.desktop/share/classes/java/awt/Rectangle.java

 ``` `````` 905 * to the bounds of this {@code Rectangle}. 906 *

907 * If this {@code Rectangle} has any dimension less than zero, 908 * the rules for non-existent 909 * rectangles apply. 910 * In that case, the new bounds of this {@code Rectangle} will 911 * have a location equal to the specified coordinates and 912 * width and height equal to zero. 913 *

914 * After adding a point, a call to {@code contains} with the 915 * added point as an argument does not necessarily return 916 * {@code true}. The {@code contains} method does not 917 * return {@code true} for points on the right or bottom 918 * edges of a {@code Rectangle}. Therefore, if the added point 919 * falls on the right or bottom edge of the enlarged 920 * {@code Rectangle}, {@code contains} returns 921 * {@code false} for that point. 922 * If the specified point must be contained within the new 923 * {@code Rectangle}, a 1x1 rectangle should be added instead: 924 *

925      *     r.add(newx, newy, 1, 1);  926      *
927 * @param newx the X coordinate of the new point 928 * @param newy the Y coordinate of the new point 929 */ 930 public void add(int newx, int newy) { 931 if ((width | height) < 0) { 932 this.x = newx; 933 this.y = newy; 934 this.width = this.height = 0; 935 return; 936 } 937 int x1 = this.x; 938 int y1 = this.y; 939 long x2 = this.width; 940 long y2 = this.height; 941 x2 += x1; 942 y2 += y1; 943 if (x1 > newx) x1 = newx; 944 if (y1 > newy) y1 = newy; 945 if (x2 < newx) x2 = newx; `````` 956 * {@code Rectangle}. 957 *

958 * If this {@code Rectangle} has any dimension less than zero, 959 * the rules for non-existent 960 * rectangles apply. 961 * In that case, the new bounds of this {@code Rectangle} will 962 * have a location equal to the coordinates of the specified 963 * {@code Point} and width and height equal to zero. 964 *

965 * After adding a {@code Point}, a call to {@code contains} 966 * with the added {@code Point} as an argument does not 967 * necessarily return {@code true}. The {@code contains} 968 * method does not return {@code true} for points on the right 969 * or bottom edges of a {@code Rectangle}. Therefore if the added 970 * {@code Point} falls on the right or bottom edge of the 971 * enlarged {@code Rectangle}, {@code contains} returns 972 * {@code false} for that {@code Point}. 973 * If the specified point must be contained within the new 974 * {@code Rectangle}, a 1x1 rectangle should be added instead: 975 *

976      *     r.add(pt.x, pt.y, 1, 1);  977      *
978 * @param pt the new {@code Point} to add to this 979 * {@code Rectangle} 980 */ 981 public void add(Point pt) { 982 add(pt.x, pt.y); 983 } 984 985 /** 986 * Adds a {@code Rectangle} to this {@code Rectangle}. 987 * The resulting {@code Rectangle} is the union of the two 988 * rectangles. 989 *

990 * If either {@code Rectangle} has any dimension less than 0, the 991 * result will have the dimensions of the other {@code Rectangle}. 992 * If both {@code Rectangle}s have at least one dimension less 993 * than 0, the result will have at least one dimension less than 0. 994 *

995 * If either {@code Rectangle} has one or both dimensions equal 996 * to 0, the result along those axes with 0 dimensions will be ``` ``` `````` 905 * to the bounds of this {@code Rectangle}. 906 *

907 * If this {@code Rectangle} has any dimension less than zero, 908 * the rules for non-existent 909 * rectangles apply. 910 * In that case, the new bounds of this {@code Rectangle} will 911 * have a location equal to the specified coordinates and 912 * width and height equal to zero. 913 *

914 * After adding a point, a call to {@code contains} with the 915 * added point as an argument does not necessarily return 916 * {@code true}. The {@code contains} method does not 917 * return {@code true} for points on the right or bottom 918 * edges of a {@code Rectangle}. Therefore, if the added point 919 * falls on the right or bottom edge of the enlarged 920 * {@code Rectangle}, {@code contains} returns 921 * {@code false} for that point. 922 * If the specified point must be contained within the new 923 * {@code Rectangle}, a 1x1 rectangle should be added instead: 924 *

925      *     r.add(new Rectangle(newx, newy, 1, 1));  926      *
927 * @param newx the X coordinate of the new point 928 * @param newy the Y coordinate of the new point 929 */ 930 public void add(int newx, int newy) { 931 if ((width | height) < 0) { 932 this.x = newx; 933 this.y = newy; 934 this.width = this.height = 0; 935 return; 936 } 937 int x1 = this.x; 938 int y1 = this.y; 939 long x2 = this.width; 940 long y2 = this.height; 941 x2 += x1; 942 y2 += y1; 943 if (x1 > newx) x1 = newx; 944 if (y1 > newy) y1 = newy; 945 if (x2 < newx) x2 = newx; `````` 956 * {@code Rectangle}. 957 *

958 * If this {@code Rectangle} has any dimension less than zero, 959 * the rules for non-existent 960 * rectangles apply. 961 * In that case, the new bounds of this {@code Rectangle} will 962 * have a location equal to the coordinates of the specified 963 * {@code Point} and width and height equal to zero. 964 *

965 * After adding a {@code Point}, a call to {@code contains} 966 * with the added {@code Point} as an argument does not 967 * necessarily return {@code true}. The {@code contains} 968 * method does not return {@code true} for points on the right 969 * or bottom edges of a {@code Rectangle}. Therefore if the added 970 * {@code Point} falls on the right or bottom edge of the 971 * enlarged {@code Rectangle}, {@code contains} returns 972 * {@code false} for that {@code Point}. 973 * If the specified point must be contained within the new 974 * {@code Rectangle}, a 1x1 rectangle should be added instead: 975 *

976      *     r.add(new Rectangle(pt.x, pt.y, 1, 1));  977      *
978 * @param pt the new {@code Point} to add to this 979 * {@code Rectangle} 980 */ 981 public void add(Point pt) { 982 add(pt.x, pt.y); 983 } 984 985 /** 986 * Adds a {@code Rectangle} to this {@code Rectangle}. 987 * The resulting {@code Rectangle} is the union of the two 988 * rectangles. 989 *

990 * If either {@code Rectangle} has any dimension less than 0, the 991 * result will have the dimensions of the other {@code Rectangle}. 992 * If both {@code Rectangle}s have at least one dimension less 993 * than 0, the result will have at least one dimension less than 0. 994 *

995 * If either {@code Rectangle} has one or both dimensions equal 996 * to 0, the result along those axes with 0 dimensions will be ```

< prev index next >