Ticket #21646: 21646.equality.patch
| File 21646.equality.patch, 2.9 KB (added by , 4 years ago) |
|---|
-
src/org/openstreetmap/josm/data/imagery/Shape.java
diff --git a/src/org/openstreetmap/josm/data/imagery/Shape.java b/src/org/openstreetmap/josm/data/imagery/Shape.java index 9e7fa16076..81783e87b7 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.data.imagery; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 4 6 import java.awt.Polygon; 5 7 import java.text.MessageFormat; 6 8 import java.util.AbstractList; … … import org.openstreetmap.gui.jmapviewer.Coordinate; 13 15 import org.openstreetmap.josm.data.coor.LatLon; 14 16 import org.openstreetmap.josm.tools.CheckParameterUtil; 15 17 16 import static org.openstreetmap.josm.tools.I18n.tr;17 18 18 /** 19 19 * Data class to store the outline for background imagery coverage. 20 20 * … … public class Shape { 85 85 }; 86 86 } 87 87 88 /** 89 * Check if the coordinates are inside this shape. 90 * @see Polygon#contains(int, int) 91 * @param latlon The latlon to look for 92 * @return {@code true} if the LatLon is inside the shape. 93 */ 88 94 public boolean contains(LatLon latlon) { 89 95 return coords.contains( 90 96 latlon.getX() * LatLon.MAX_SERVER_INV_PRECISION, … … public class Shape { 128 134 if (this == obj) return true; 129 135 if (obj == null || getClass() != obj.getClass()) return false; 130 136 Shape shape = (Shape) obj; 131 return Objects.equals(getPoints(), shape.getPoints()); 137 return Objects.equals(getPoints(), shape.getPoints()) || checkPointsEqualEpsilon(getPoints(), shape.getPoints()); 138 } 139 140 /** 141 * Check if two point lists are equal to OSM precision 142 * @param pointsOne The first list of points 143 * @param pointsTwo The second list of points 144 * @return {@code true} if they are equal within OSM precision 145 */ 146 private static boolean checkPointsEqualEpsilon(List<Coordinate> pointsOne, List<Coordinate> pointsTwo) { 147 if (pointsOne.size() == pointsTwo.size()) { 148 for (int i = 0; i < pointsOne.size(); i++) { 149 final Coordinate one = pointsOne.get(i); 150 final Coordinate two = pointsTwo.get(i); 151 if (!one.equals(two) && 152 !equalsEpsilon(one.getLat(), two.getLat()) && !equalsEpsilon(one.getLon(), two.getLon())) { 153 return false; 154 } 155 } 156 return true; 157 } 158 return false; 159 } 160 161 /** 162 * Check if two doubles are equal based off of {@link LatLon#MAX_SERVER_PRECISION} 163 * @param first The first double 164 * @param second The second double 165 * @return {@code true} if they are equal to OSM precision 166 */ 167 private static boolean equalsEpsilon(final double first, final double second) { 168 return Math.abs(first - second) < LatLon.MAX_SERVER_PRECISION; 132 169 } 133 170 134 171 @Override
