source: josm/trunk/src/org/openstreetmap/josm/tools/DefaultGeoProperty.java@ 11299

Last change on this file since 11299 was 11277, checked in by Don-vip, 7 years ago

sonar - fix recently added warnings

  • Property svn:eol-style set to native
File size: 1.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import java.awt.geom.Area;
5import java.util.Collection;
6
7import org.openstreetmap.josm.data.coor.LatLon;
8import org.openstreetmap.josm.data.osm.BBox;
9import org.openstreetmap.josm.data.osm.Way;
10
11/**
12 * Implementation of simple boolean {@link GeoProperty}.
13 */
14public class DefaultGeoProperty implements GeoProperty<Boolean> {
15
16 private Area area;
17
18 /**
19 * Create DefaultGeoProperty based on a collection of closed ways.
20 *
21 * @param ways the ways forming the area
22 */
23 public DefaultGeoProperty(Collection<Way> ways) {
24 for (Way w : ways) {
25 Area tmp = Geometry.getAreaLatLon(w.getNodes());
26 if (area == null) {
27 area = tmp;
28 } else {
29 area.add(tmp);
30 }
31 }
32 }
33
34 @Override
35 public Boolean get(LatLon ll) {
36 return area.contains(ll.lon(), ll.lat());
37 }
38
39 @Override
40 public Boolean get(BBox box) {
41 Area abox = new Area(box.toRectangle());
42 Geometry.PolygonIntersection is = Geometry.polygonIntersection(abox, area, 1e-10 /* using deg and not meters */);
43 switch (is) {
44 case FIRST_INSIDE_SECOND:
45 return Boolean.TRUE;
46 case OUTSIDE:
47 return Boolean.FALSE;
48 default:
49 return null;
50 }
51 }
52
53}
Note: See TracBrowser for help on using the repository browser.