add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / spatial / src / java / org / apache / lucene / spatial / geometry / shape / Point2D.java
1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package org.apache.lucene.spatial.geometry.shape;
19
20
21 /**
22  * Point class.  This type is mutable.
23  *
24  * <p><font color="red"><b>NOTE:</b> This API is still in
25  * flux and might change in incompatible ways in the next
26  * release.</font>
27  */
28 public class Point2D {
29   private double x;
30   private double y;
31
32   public Point2D(double x, double y) {
33     this.x=x;
34     this.y=y;
35   }
36   
37   public Point2D() {
38     this.x=0;
39     this.y=0;
40   }
41   
42   public Point2D(Point2D other) {
43     this.x=other.x;
44     this.y=other.y;
45   }
46   
47   @Override
48   public String toString() {
49     return "(" + x + "," + y + ")";
50   }
51   
52   public double getX() {
53     return x;
54   }
55   
56   public double getY() {
57     return y;
58   }
59   
60   public double x() {
61     return x;
62   }
63
64   public double y() {
65     return y;
66   }
67
68   public void x(double x) {
69     this.x=x;
70   }
71
72   public void y(double y) {
73     this.y=y;
74   }
75
76   public void setX(double x) {
77     this.x = x;
78   }
79   
80   public void setY(double y) {
81     this.y = y;
82   }
83   
84   public void set(double x, double y) {
85     this.x=x;
86     this.y=y;
87   }
88
89   public void add(Vector2D v) {
90     this.x+=v.getX();
91     this.y+=v.getY();
92   }
93
94   public void set(Point2D p1) {
95     this.x=p1.getX();
96     this.y=p1.getY();
97   }
98
99   public void add(Point2D a) {
100     this.x+=a.getX();
101     this.y+=a.getY();
102   }
103
104   public void set(Vector2D v) {
105     this.x=v.getX();
106     this.y=v.getY();
107   }
108   
109   @Override
110   public int hashCode() {
111     final int prime = 31;
112     int result = 1;
113     long temp;
114     temp = Double.doubleToLongBits(x);
115     result = prime * result + (int) (temp ^ (temp >>> 32));
116     temp = Double.doubleToLongBits(y);
117     result = prime * result + (int) (temp ^ (temp >>> 32));
118     return result;
119   }
120
121   @Override
122   public boolean equals(Object obj) {
123     if (this == obj)
124       return true;
125     if (obj == null)
126       return false;
127     if (getClass() != obj.getClass())
128       return false;
129     Point2D other = (Point2D) obj;
130     if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x))
131       return false;
132     if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y))
133       return false;
134     return true;
135   }
136   
137 }