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 FixedLatLng extends LatLng {
26 public static final double SCALE_FACTOR=1000000;
27 public static final int SCALE_FACTOR_INT=1000000;
30 private boolean normalized;
32 public FixedLatLng(int lat, int lng) {
37 public FixedLatLng(LatLng ll) {
38 this.lat=ll.getFixedLat();
39 this.lng=ll.getFixedLng();
42 protected void setLat(int lat) {
43 if (lat>90*SCALE_FACTOR || lat<-90*SCALE_FACTOR) {
44 throw new IllegalArgumentException("Illegal lattitude");
49 protected void setLng(int lng) {
53 public static double fixedToDouble(int fixed) {
54 return (fixed)/SCALE_FACTOR;
57 public static int doubleToFixed(double d) {
58 return (int)(d*SCALE_FACTOR);
62 public LatLng copy() {
63 return new FixedLatLng(this);
67 public int getFixedLat() {
72 public int getFixedLng() {
77 public double getLat() {
78 return fixedToDouble(lat);
82 public double getLng() {
83 return fixedToDouble(lng);
87 public boolean isFixedPoint() {
92 public FixedLatLng toFixed() {
97 public FloatLatLng toFloat() {
98 return new FloatLatLng(this);
102 public boolean isNormalized() {
105 (lng>=-180*SCALE_FACTOR_INT) &&
106 (lng<=180*SCALE_FACTOR_INT)
111 public LatLng normalize() {
112 if (isNormalized()) return this;
115 if (lng<0) delta=360*SCALE_FACTOR_INT;
116 if (lng>=0) delta=-360*SCALE_FACTOR_INT;
119 while (newLng<=-180*SCALE_FACTOR_INT || newLng>=180*SCALE_FACTOR_INT) {
123 FixedLatLng ret=new FixedLatLng(lat, newLng);
129 public LatLng calculateMidpoint(LatLng other) {
130 return new FixedLatLng(
131 (lat+other.getFixedLat())/2,
132 (lng+other.getFixedLng())/2);
136 public int hashCode() {
137 final int prime = 31;
138 int result = prime + lat;
139 result = prime * result + lng;
140 result = prime * result + (normalized ? 1231 : 1237);
145 public boolean equals(Object obj) {
148 if (getClass() != obj.getClass())
150 FixedLatLng other = (FixedLatLng) obj;
151 if (lat != other.lat)
153 if (lng != other.lng)
155 if (normalized != other.normalized)