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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org.apache.lucene.spatial.geometry.shape;
24 * <p><font color="red"><b>NOTE:</b> This API is still in
25 * flux and might change in incompatible ways in the next
28 public class Vector2D {
33 * Create a vector from the origin of the coordinate system to the given
39 public Vector2D(double x, double y) {
45 * Create a vector from the origin of the coordinate system to the given
48 public Vector2D(Point2D p) {
49 this(p.getX(), p.getY());
53 * Create a vector from one point to another
58 public Vector2D(Point2D from, Point2D to) {
59 this(to.getX() - from.getX(), to.getY() - from.getY());
67 public Vector2D(Vector2D other) {
72 public double getX() {
76 public double getY() {
80 public void setX(double x) {
84 public void setY(double y) {
88 public void set(double x, double y) {
93 public boolean equals(Vector2D other) {
94 return other != null && x == other.x && y == other.y;
97 public double dot(Vector2D in) {
98 return ((x) * in.x) + (y * in.y);
102 * Vector length (magnitude) squared
104 public double normSqr() {
105 // Cast to F to prevent overflows
106 return (x * x) + (y * y);
109 public double norm() {
110 return Math.sqrt(normSqr());
113 public Vector2D mult(double d) {
114 return new Vector2D(x*d, y*d);
118 public int hashCode() {
119 final int prime = 31;
122 temp = Double.doubleToLongBits(x);
123 result = prime * result + (int) (temp ^ (temp >>> 32));
124 temp = Double.doubleToLongBits(y);
125 result = prime * result + (int) (temp ^ (temp >>> 32));
130 public boolean equals(Object obj) {
135 if (getClass() != obj.getClass())
137 Vector2D other = (Vector2D) obj;
138 if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x))
140 if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y))