Changeset 13805 in josm
 Timestamp:
 20180521T17:23:10+02:00 (3 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/org/openstreetmap/josm/tools/Geometry.java
r13712 r13805 26 26 import org.openstreetmap.josm.data.osm.BBox; 27 27 import org.openstreetmap.josm.data.osm.DataSet; 28 import org.openstreetmap.josm.data.osm.INode; 28 29 import org.openstreetmap.josm.data.osm.IPrimitive; 29 30 import org.openstreetmap.josm.data.osm.MultipolygonBuilder; … … 252 253 * lineP1, lineP2, lineP3.) 253 254 * 255 * @param <N> type of node 254 256 * @param lineP1 first point in path 255 257 * @param lineP2 second point in path … … 258 260 * @return true if to the right side, false otherwise 259 261 */ 260 public static boolean isToTheRightSideOfLine(Node lineP1, Node lineP2, Node lineP3, NodetestPoint) {262 public static <N extends INode> boolean isToTheRightSideOfLine(N lineP1, N lineP2, N lineP3, N testPoint) { 261 263 boolean pathBendToRight = angleIsClockwise(lineP1, lineP2, lineP3); 262 264 boolean rightOfSeg1 = angleIsClockwise(lineP1, lineP2, testPoint); … … 271 273 /** 272 274 * This method tests if secondNode is clockwise to first node. 275 * @param <N> type of node 273 276 * @param commonNode starting point for both vectors 274 277 * @param firstNode first vector end node … … 276 279 * @return true if first vector is clockwise before second vector. 277 280 */ 278 public static boolean angleIsClockwise(Node commonNode, Node firstNode, NodesecondNode) {281 public static <N extends INode> boolean angleIsClockwise(N commonNode, N firstNode, N secondNode) { 279 282 return angleIsClockwise(commonNode.getEastNorth(), firstNode.getEastNorth(), secondNode.getEastNorth()); 280 283 } … … 502 505 * @since 6841 503 506 */ 504 public static Area getArea(List< Node> polygon) {507 public static Area getArea(List<? extends INode> polygon) { 505 508 Path2D path = new Path2D.Double(); 506 509 507 510 boolean begin = true; 508 for ( Node n : polygon) {511 for (INode n : polygon) { 509 512 EastNorth en = n.getEastNorth(); 510 513 if (en != null) { … … 568 571 /** 569 572 * Tests if two polygons intersect. 573 * @param <N> type of node 570 574 * @param first List of nodes forming first polygon 571 575 * @param second List of nodes forming second polygon 572 576 * @return intersection kind 573 577 */ 574 public static PolygonIntersection polygonIntersection(List<Node> first, List<Node> second) {578 public static <N extends INode> PolygonIntersection polygonIntersection(List<N> first, List<N> second) { 575 579 Area a1 = getArea(first); 576 580 Area a2 = getArea(second); … … 616 620 /** 617 621 * Tests if point is inside a polygon. The polygon can be selfintersecting. In such case the contains function works in xorlike manner. 622 * @param <N> type of node 618 623 * @param polygonNodes list of nodes from polygon path. 619 624 * @param point the point to test 620 625 * @return true if the point is inside polygon. 621 626 */ 622 public static boolean nodeInsidePolygon(Node point, List<Node> polygonNodes) {627 public static <N extends INode> boolean nodeInsidePolygon(N point, List<N> polygonNodes) { 623 628 if (polygonNodes.size() < 2) 624 629 return false; 625 630 626 631 //iterate each side of the polygon, start with the last segment 627 N odeoldPoint = polygonNodes.get(polygonNodes.size()  1);632 N oldPoint = polygonNodes.get(polygonNodes.size()  1); 628 633 629 634 if (!oldPoint.isLatLonKnown()) { … … 632 637 633 638 boolean inside = false; 634 N odep1, p2;635 636 for (N odenewPoint : polygonNodes) {639 N p1, p2; 640 641 for (N newPoint : polygonNodes) { 637 642 //skip duplicate points 638 643 if (newPoint.equals(oldPoint)) { … … 740 745 * @see #isClockwise(Way) 741 746 */ 742 public static boolean isClockwise(List< Node> nodes) {747 public static boolean isClockwise(List<? extends INode> nodes) { 743 748 int nodesCount = nodes.size(); 744 749 if (nodesCount < 3  nodes.get(0) != nodes.get(nodesCount  1)) { … … 748 753 749 754 for (int node = 1; node <= /*sic! consider lastfirst as well*/ nodesCount; node++) { 750 Node coorPrev = nodes.get(node  1);751 Node coorCurr = nodes.get(node % nodesCount);755 INode coorPrev = nodes.get(node  1); 756 INode coorCurr = nodes.get(node % nodesCount); 752 757 area2 += coorPrev.lon() * coorCurr.lat(); 753 758 area2 = coorCurr.lon() * coorPrev.lat(); … … 814 819 * @see Geometry#getCenter 815 820 */ 816 public static EastNorth getCentroid(List< Node> nodes) {817 return getCentroidEN(nodes.stream().map( Node::getEastNorth).collect(Collectors.toList()));821 public static EastNorth getCentroid(List<? extends INode> nodes) { 822 return getCentroidEN(nodes.stream().map(INode::getEastNorth).collect(Collectors.toList())); 818 823 } 819 824 … … 884 889 * @since 6934 885 890 */ 886 public static EastNorth getCenter(List< Node> nodes) {891 public static EastNorth getCenter(List<? extends INode> nodes) { 887 892 int nc = nodes.size(); 888 893 if (nc < 3) return null; … … 1034 1039 * @return area and perimeter 1035 1040 */ 1036 public static AreaAndPerimeter getAreaAndPerimeter(List< Node> nodes) {1041 public static AreaAndPerimeter getAreaAndPerimeter(List<? extends ILatLon> nodes) { 1037 1042 return getAreaAndPerimeter(nodes, null); 1038 1043 }
Note: See TracChangeset
for help on using the changeset viewer.