001package org.opencv.core;
002
003//javadoc:Size_
004public class Size {
005
006    public double width, height;
007
008    public Size(double width, double height) {
009        this.width = width;
010        this.height = height;
011    }
012
013    public Size() {
014        this(0, 0);
015    }
016
017    public Size(Point p) {
018        width = p.x;
019        height = p.y;
020    }
021
022    public Size(double[] vals) {
023        set(vals);
024    }
025
026    public void set(double[] vals) {
027        if (vals != null) {
028            width = vals.length > 0 ? vals[0] : 0;
029            height = vals.length > 1 ? vals[1] : 0;
030        } else {
031            width = 0;
032            height = 0;
033        }
034    }
035
036    public double area() {
037        return width * height;
038    }
039
040    public boolean empty() {
041        return width <= 0 || height <= 0;
042    }
043
044    public Size clone() {
045        return new Size(width, height);
046    }
047
048    @Override
049    public int hashCode() {
050        final int prime = 31;
051        int result = 1;
052        long temp;
053        temp = Double.doubleToLongBits(height);
054        result = prime * result + (int) (temp ^ (temp >>> 32));
055        temp = Double.doubleToLongBits(width);
056        result = prime * result + (int) (temp ^ (temp >>> 32));
057        return result;
058    }
059
060    @Override
061    public boolean equals(Object obj) {
062        if (this == obj) return true;
063        if (!(obj instanceof Size)) return false;
064        Size it = (Size) obj;
065        return width == it.width && height == it.height;
066    }
067
068    @Override
069    public String toString() {
070        return (int)width + "x" + (int)height;
071    }
072
073}