@@ -252,43 +252,43 @@ public static Point decode(
252252 }
253253
254254 /**
255- * Is coordinate within a given territory?
255+ * Is coordinate near multiple territory borders ?
256256 *
257257 * @param point Latitude/Longitude in degrees
258258 * @param territory Territory
259- * @return true iff the coordinate is inside the specified territory.
259+ * @return true iff the coordinate is near more than one territory border
260+ * (and thus encode(decode(M)) may not produce M)
260261 */
261- public static boolean isInsideTerritory (@ Nonnull final Point point , @ Nonnull final Territory territory ) {
262- final int ccode = territory .getNumber ();
263- final int from = DataAccess .dataFirstRecord (ccode );
264- final int upto = DataAccess .dataLastRecord (ccode );
265- if (Data .getBoundaries (upto ).containsPoint (point )) {
266- for (int m = upto ; m >= from ; m --) {
267- if (!Data .isRestricted (m )) {
268- if (Data .getBoundaries (m ).containsPoint (point )) {
269- return true ;
262+
263+ public static boolean multipleBordersNearby (@ Nonnull final Point point , @ Nonnull final Territory territory ) {
264+ if (territory != territory .AAA ) {
265+ final int ccode = territory .getNumber ();
266+ if (territory .getParentTerritory () != null ) {
267+ // there is a parent! check its borders as well...
268+ if (multipleBordersNearby (point , territory .getParentTerritory ())) {
269+ return true ;
270+ }
271+ }
272+ {
273+ int nrFound = 0 ;
274+ final int from = DataAccess .dataFirstRecord (ccode );
275+ final int upto = DataAccess .dataLastRecord (ccode );
276+ for (int m = upto ; m >= from ; m --) {
277+ if (!Data .isRestricted (m )) {
278+ final SubArea boundaries = Data .getBoundaries (m );
279+ final int xdiv8 = Common .xDivider (boundaries .getMinY (),boundaries .getMaxY ()) / 4 ; // @@@
280+ if (boundaries .extendBounds (xdiv8 , 60 ).containsPoint (point )) {
281+ if (!boundaries .extendBounds (-xdiv8 , -60 ).containsPoint (point )) {
282+ nrFound ++;
283+ if (nrFound > 1 ) {
284+ return true ;
285+ }
286+ }
287+ }
270288 }
271289 }
272290 }
273291 }
274292 return false ;
275293 }
276-
277- /**
278- * Is coordinate "fully within" a given territory?
279- *
280- * @param point Latitude/Longitude in degrees
281- * @param territory Territory
282- * @return true iff the coordinate is inside the specified territory, and furthermore,
283- * IF the territory has a perent territory: inside the parent territory.
284- *
285- * Note that for the mapcode system, the following should hold: IF a point p has a
286- * mapcode M, THEN decode(M) delivers a point q within maxErrorInMeters() of p.
287- * Furthermore, encode(q) must yield back M *unless* point q is not "fully inside"
288- * the mapcode territory.
289- */
290- public static boolean isFullyInsideTerritory (@ Nonnull final Point point , @ Nonnull final Territory territory ) {
291- final Territory parentTerritory = territory .getParentTerritory ();
292- return isInsideTerritory (point , territory ) && ((parentTerritory == null ) || isInsideTerritory (point , parentTerritory ));
293- }
294294}
0 commit comments