1 /* 2 * Hunt - A redis client library for D programming language. 3 * 4 * Copyright (C) 2018-2019 HuntLabs 5 * 6 * Website: https://www.huntlabs.net/ 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 12 module hunt.redis.GeoCoordinate; 13 14 import hunt.Double; 15 import hunt.util.Comparator; 16 17 import std.conv; 18 19 class GeoCoordinate { 20 private double longitude; 21 private double latitude; 22 23 this(double longitude, double latitude) { 24 this.longitude = longitude; 25 this.latitude = latitude; 26 } 27 28 double getLongitude() { 29 return longitude; 30 } 31 32 double getLatitude() { 33 return latitude; 34 } 35 36 override 37 bool opEquals(Object o) { 38 if (o is null) return false; 39 if (o is this) return true; 40 41 GeoCoordinate that = cast(GeoCoordinate) o; 42 if(that is null) 43 return false; 44 45 if (compare(that.longitude, longitude) != 0) return false; 46 return compare(that.latitude, latitude) == 0; 47 } 48 49 override 50 size_t toHash() @trusted nothrow { 51 // follows IntelliJ default hashCode implementation 52 int result; 53 long temp; 54 temp = cast(long)longitude; // Double.doubleToLongBits(longitude); 55 result = cast(int) (temp ^ (temp >>> 32)); 56 temp = cast(long)latitude; // Double.doubleToLongBits(latitude); 57 result = 31 * result + cast(int) (temp ^ (temp >>> 32)); 58 return result; 59 } 60 61 override 62 string toString() { 63 return "(" ~ longitude.to!string() ~ "," ~ latitude.to!string() ~ ")"; 64 } 65 }