1 package com.github.davidmoten.rtree.geometry.internal; 2 3 import com.github.davidmoten.rtree.geometry.Geometries; 4 import com.github.davidmoten.rtree.geometry.Geometry; 5 import com.github.davidmoten.rtree.geometry.Point; 6 import com.github.davidmoten.rtree.geometry.Rectangle; 7 8 public final class PointDouble implements Point { 9 10 private final double x; 11 private final double y; 12 13 private PointDouble(double x, double y) { 14 this.x = x; 15 this.y = y; 16 } 17 18 public static PointDouble create(double x, double y) { 19 return new PointDouble(x, y); 20 } 21 22 @Override 23 public Rectangle mbr() { 24 return this; 25 } 26 27 @Override 28 public double distance(Rectangle r) { 29 return GeometryUtil.distance(x, y, r); 30 } 31 32 @Override 33 public boolean intersects(Rectangle r) { 34 return r.x1() <= x && x <= r.x2() && r.y1() <= y && y <= r.y2(); 35 } 36 37 @Override 38 public double x() { 39 return x; 40 } 41 42 @Override 43 public double y() { 44 return y; 45 } 46 47 @Override 48 public String toString() { 49 return "Point [x=" + x() + ", y=" + y() + "]"; 50 } 51 52 @Override 53 public Geometry geometry() { 54 return this; 55 } 56 57 @Override 58 public double x1() { 59 return x; 60 } 61 62 @Override 63 public double y1() { 64 return y; 65 } 66 67 @Override 68 public double x2() { 69 return x; 70 } 71 72 @Override 73 public double y2() { 74 return y; 75 } 76 77 @Override 78 public double area() { 79 return 0; 80 } 81 82 @Override 83 public Rectangle add(Rectangle r) { 84 return Geometries.rectangle(Math.min(x, r.x1()), Math.min(y, r.y1()), Math.max(x, r.x2()), 85 Math.max(y, r.y2())); 86 } 87 88 @Override 89 public boolean contains(double x, double y) { 90 return this.x == x && this.y == y; 91 } 92 93 @Override 94 public double intersectionArea(Rectangle r) { 95 return 0; 96 } 97 98 @Override 99 public double perimeter() { 100 return 0; 101 } 102 103 @Override 104 public boolean isDoublePrecision() { 105 return true; 106 } 107 108 @Override 109 public int hashCode() { 110 final int prime = 31; 111 int result = 1; 112 long temp; 113 temp = Double.doubleToLongBits(x); 114 result = prime * result + (int) (temp ^ (temp >>> 32)); 115 temp = Double.doubleToLongBits(y); 116 result = prime * result + (int) (temp ^ (temp >>> 32)); 117 return result; 118 } 119 120 @Override 121 public boolean equals(Object obj) { 122 if (this == obj) 123 return true; 124 if (obj == null) 125 return false; 126 if (getClass() != obj.getClass()) 127 return false; 128 PointDouble other = (PointDouble) obj; 129 if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x)) 130 return false; 131 if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y)) 132 return false; 133 return true; 134 } 135 136 }