1 package org.opencv.core;
6 public int x, y, width, height;
8 public Rect(int x, int y, int width, int height) {
19 public Rect(Point p1, Point p2) {
20 x = (int) (p1.x < p2.x ? p1.x : p2.x);
21 y = (int) (p1.y < p2.y ? p1.y : p2.y);
22 width = (int) (p1.x > p2.x ? p1.x : p2.x) - x;
23 height = (int) (p1.y > p2.y ? p1.y : p2.y) - y;
26 public Rect(Point p, Size s) {
27 this((int) p.x, (int) p.y, (int) s.width, (int) s.height);
30 public Rect(double[] vals) {
34 public void set(double[] vals) {
36 x = vals.length > 0 ? (int) vals[0] : 0;
37 y = vals.length > 1 ? (int) vals[1] : 0;
38 width = vals.length > 2 ? (int) vals[2] : 0;
39 height = vals.length > 3 ? (int) vals[3] : 0;
49 return new Rect(x, y, width, height);
53 return new Point(x, y);
57 return new Point(x + width, y + height);
61 return new Size(width, height);
64 public double area() {
65 return width * height;
68 public boolean empty() {
69 return width <= 0 || height <= 0;
72 public boolean contains(Point p) {
73 return x <= p.x && p.x < x + width && y <= p.y && p.y < y + height;
77 public int hashCode() {
81 temp = Double.doubleToLongBits(height);
82 result = prime * result + (int) (temp ^ (temp >>> 32));
83 temp = Double.doubleToLongBits(width);
84 result = prime * result + (int) (temp ^ (temp >>> 32));
85 temp = Double.doubleToLongBits(x);
86 result = prime * result + (int) (temp ^ (temp >>> 32));
87 temp = Double.doubleToLongBits(y);
88 result = prime * result + (int) (temp ^ (temp >>> 32));
93 public boolean equals(Object obj) {
94 if (this == obj) return true;
95 if (!(obj instanceof Rect)) return false;
97 return x == it.x && y == it.y && width == it.width && height == it.height;
101 public String toString() {
102 return "{" + x + ", " + y + ", " + width + "x" + height + "}";