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