org.opencv.core.Point Maven / Gradle / Ivy
Show all versions of sikulixapi Show documentation
package org.opencv.core; /** *
* *template
* *class CV_EXPORTS Point_ // C++ code:
* * *public:
* *typedef _Tp value_type;
* *// various constructors
* *Point_();
* *Point_(_Tp _x, _Tp _y);
* *Point_(const Point_& pt);
* *Point_(const CvPoint& pt);
* *Point_(const CvPoint2D32f& pt);
* *Point_(const Size_<_Tp>& sz);
* *Point_(const Vec<_Tp, 2>& v);
* *Point_& operator = (const Point_& pt);
* *//! conversion to another data type
* *template
* *operator Point_<_Tp2>() const; //! conversion to the old-style C structures
* *operator CvPoint() const;
* *operator CvPoint2D32f() const;
* *operator Vec<_Tp, 2>() const;
* *//! dot product
* *_Tp dot(const Point_& pt) const;
* *//! dot product computed in double-precision arithmetics
* *double ddot(const Point_& pt) const;
* *//! cross-product
* *double cross(const Point_& pt) const;
* *//! checks whether the point is inside the specified rectangle
* *bool inside(const Rect_<_Tp>& r) const;
* *_Tp x, y; //< the point coordinates
* *};
* *Template class for 2D points specified by its coordinates
x and y. * An instance of the class is interchangeable with C structures, *
* *CvPoint
andCvPoint2D32f
. There is also a cast * operator to convert point coordinates to the specified type. The conversion * from floating-point coordinates to integer coordinates is done by rounding. * Commonly, the conversion uses thisoperation for each of the coordinates. * Besides the class members listed in the declaration above, the following * operations on points are implemented:// C++ code:
* *pt1 = pt2 + pt3;
* *pt1 = pt2 - pt3;
* *pt1 = pt2 * a;
* *pt1 = a * pt2;
* *pt1 += pt2;
* *pt1 -= pt2;
* *pt1 *= a;
* *double value = norm(pt); // L2 norm
* *pt1 == pt2;
* *pt1 != pt2;
* *For your convenience, the following type aliases are defined:
* *typedef Point_
* *Point2i; typedef Point2i Point;
* *typedef Point_
* *Point2f; typedef Point_
* *Point2d; Example:
* *Point2f a(0.3f, 0.f), b(0.f, 0.4f);
* *Point pt = (a + b)*10.f;
* *cout << pt.x << ", " << pt.y << endl;
* * @see org.opencv.core.Point_ */ public class Point { public double x, y; public Point(double x, double y) { this.x = x; this.y = y; } public Point() { this(0, 0); } public Point(double[] vals) { this(); set(vals); } public void set(double[] vals) { if (vals != null) { x = vals.length > 0 ? vals[0] : 0; y = vals.length > 1 ? vals[1] : 0; } else { x = 0; y = 0; } } public Point clone() { return new Point(x, y); } public double dot(Point p) { return x * p.x + y * p.y; } @Override public int hashCode() { final int prime = 31; int result = 1; long temp; temp = Double.doubleToLongBits(x); result = prime * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(y); result = prime * result + (int) (temp ^ (temp >>> 32)); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof Point)) return false; Point it = (Point) obj; return x == it.x && y == it.y; } public boolean inside(Rect r) { return r.contains(this); } @Override public String toString() { return "{" + x + ", " + y + "}"; } }