2 * Copyright (C) 2009 The Android Open Source Project
4 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.eclipse.org/org/documents/epl-v10.php
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.ide.eclipse.adt.editors.layout.gscripts;
21 * Mutable rectangle bounds.
23 * To be valid, w >= 1 and h >= 1.
25 * - right side = x + w - 1.
26 * - bottom side = y + h - 1.
29 public int x, y, w, h;
31 /** Initialize an invalid rectangle. */
35 /** Initialize rectangle to the given values. They can be invalid. */
36 public Rect(int x, int y, int w, int h) {
40 /** Initialize rectangle to the given values. They can be invalid. */
41 public void set(int x, int y, int w, int h) {
48 /** Initialize rectangle to match the given one. */
49 public void set(Rect r) {
56 /** Returns a new instance of a rectangle with the same values. */
58 return new Rect(x, y, w, h);
61 /** Returns true if the rectangle has valid bounds, i.e. w>0 and h>0. */
62 public boolean isValid() {
63 return w > 0 && h > 0;
66 /** Returns true if the rectangle contains the x,y coordinates, borders included. */
67 public boolean contains(int x, int y) {
71 x < (this.x + this.w) &&
72 y < (this.y + this.h);
76 public String toString() {
77 return String.format("Rect [%dx%d - %dx%d]", x, y, w, h);