@@ -44,8 +44,8 @@ public class StreetAddressTest extends Test {
4444 public static final double BBOX_EXPANSION = 0.002 ;
4545 private static final String ADDR_STREET = "addr:street" ;
4646 private final Set <OsmPrimitive > namePrimitiveMap = new HashSet <>();
47- private final Map <Point2D , Set <String >> nameMap = new HashMap <>();
48- private final Map <Point2D , List <OsmPrimitive >> primitiveCellMap = new HashMap <>();
47+ private final Map <Point , Set <String >> nameMap = new HashMap <>();
48+ private final Map <Point , List <OsmPrimitive >> primitiveCellMap = new HashMap <>();
4949 /**
5050 * Classified highways. This uses a {@link Set} instead of a {@link List} since
5151 * the MapWithAI code doesn't care about order.
@@ -146,7 +146,8 @@ private void realVisit(OsmPrimitive primitive) {
146146 final var n1 = nodes .get (i );
147147 final var n2 = nodes .get (i + 1 );
148148 for (Point2D cell : ValUtil .getSegmentCells (n1 , n2 , gridDetail )) {
149- this .nameMap .computeIfAbsent (cell , k -> new HashSet <>()).addAll (names );
149+ this .nameMap .computeIfAbsent (new Point (cell .getX (), cell .getY ()), k -> new HashSet <>())
150+ .addAll (names );
150151 }
151152 }
152153 } else if (hasStreetAddressTags (primitive ) && !primitive .isOutsideDownloadArea ()) {
@@ -159,7 +160,7 @@ private void realVisit(OsmPrimitive primitive) {
159160 if (en != null ) {
160161 long x = (long ) Math .floor (en .getX () * gridDetail );
161162 long y = (long ) Math .floor (en .getY () * gridDetail );
162- final var point = new Point2D . Double (x , y );
163+ final var point = new Point (x , y );
163164 primitiveCellMap .computeIfAbsent (point , p -> new ArrayList <>()).add (primitive );
164165 }
165166 }
@@ -174,7 +175,7 @@ private static Collection<String> getWayNames(IPrimitive way) {
174175 .filter (s -> !s .isEmpty ()).collect (Collectors .toSet ());
175176 }
176177
177- private Collection <String > getSurroundingHighwayNames (Point2D point2D ) {
178+ private Collection <String > getSurroundingHighwayNames (Point point2D ) {
178179 if (this .nameMap .isEmpty ()) {
179180 return Collections .emptySet ();
180181 }
@@ -183,8 +184,9 @@ private Collection<String> getSurroundingHighwayNames(Point2D point2D) {
183184 while (surroundingWays .isEmpty ()) {
184185 for (int x = -surrounding ; x <= surrounding ; x ++) {
185186 for (int y = -surrounding ; y <= surrounding ; y ++) {
186- final var key = new Point2D .Double ((long ) Math .floor (point2D .getX () + x ),
187- (long ) Math .floor (point2D .getY () + y ));
187+ final var xPoint = (long ) Math .floor (point2D .x () + x );
188+ final var yPoint = (long ) Math .floor (point2D .y () + y );
189+ final var key = new Point (xPoint , yPoint );
188190 if (this .nameMap .containsKey (key )) {
189191 surroundingWays .addAll (this .nameMap .get (key ));
190192 }
@@ -303,4 +305,20 @@ public static BBox expandBBox(BBox bbox, double degree) {
303305 bbox .add (bbox .getTopLeftLon () - degree , bbox .getTopLeftLat () + degree );
304306 return bbox ;
305307 }
306- }
308+
309+ private record Point (double x , double y ) implements Comparable <Point > {
310+
311+ @ Override
312+ public int compareTo (Point other ) {
313+ if (other .x == this .x && other .y == this .y ) {
314+ return 0 ;
315+ }
316+ if (other .x < this .x ) {
317+ return -1 ;
318+ }
319+ if (other .x > this .x ) {
320+ return 1 ;
321+ }
322+ return Double .compare (other .y , this .y );
323+ }
324+ }}
0 commit comments