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;
21 * <p><font color="red"><b>NOTE:</b> This API is still in
22 * flux and might change in incompatible ways in the next
25 public class FloatLatLng extends LatLng {
28 private boolean normalized;
30 public FloatLatLng(double lat, double lng) {
31 if (lat>90.0 || lat<-90.0) throw new IllegalArgumentException("Illegal latitude value " + lat);
36 public FloatLatLng(LatLng ll) {
42 public LatLng copy() {
43 return new FloatLatLng(this);
47 public int getFixedLat() {
48 return FixedLatLng.doubleToFixed(this.lat);
52 public int getFixedLng() {
53 return FixedLatLng.doubleToFixed(this.lng);
57 public double getLat() {
62 public double getLng() {
67 public boolean isFixedPoint() {
72 public FixedLatLng toFixed() {
73 return new FixedLatLng(this);
77 public FloatLatLng toFloat() {
82 public boolean isNormalized() {
91 public LatLng normalize() {
92 if (isNormalized()) return this;
96 if (lng>=0) delta=-360;
99 while (newLng<=-180 || newLng>=180) {
103 FloatLatLng ret=new FloatLatLng(lat, newLng);
109 public LatLng calculateMidpoint(LatLng other) {
110 return new FloatLatLng(
111 (lat+other.getLat())/2.0,
112 (lng+other.getLng())/2.0);
116 public int hashCode() {
117 final int prime = 31;
119 temp = Double.doubleToLongBits(lat);
120 int result = prime + (int) (temp ^ (temp >>> 32));
121 temp = Double.doubleToLongBits(lng);
122 result = prime * result + (int) (temp ^ (temp >>> 32));
123 result = prime * result + (normalized ? 1231 : 1237);
128 public boolean equals(Object obj) {
131 if (getClass() != obj.getClass())
133 FloatLatLng other = (FloatLatLng) obj;
134 if (Double.doubleToLongBits(lat) != Double.doubleToLongBits(other.lat))
136 if (Double.doubleToLongBits(lng) != Double.doubleToLongBits(other.lng))
138 if (normalized != other.normalized)