Changeset 13805 in josm for trunk


Ignore:
Timestamp:
2018-05-21T17:23:10+02:00 (13 months ago)
Author:
Don-vip
Message:

use INode interface in Geometry class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r13712 r13805  
    2626import org.openstreetmap.josm.data.osm.BBox;
    2727import org.openstreetmap.josm.data.osm.DataSet;
     28import org.openstreetmap.josm.data.osm.INode;
    2829import org.openstreetmap.josm.data.osm.IPrimitive;
    2930import org.openstreetmap.josm.data.osm.MultipolygonBuilder;
     
    252253     * lineP1, lineP2, lineP3.)
    253254     *
     255     * @param <N> type of node
    254256     * @param lineP1 first point in path
    255257     * @param lineP2 second point in path
     
    258260     * @return true if to the right side, false otherwise
    259261     */
    260     public static boolean isToTheRightSideOfLine(Node lineP1, Node lineP2, Node lineP3, Node testPoint) {
     262    public static <N extends INode> boolean isToTheRightSideOfLine(N lineP1, N lineP2, N lineP3, N testPoint) {
    261263        boolean pathBendToRight = angleIsClockwise(lineP1, lineP2, lineP3);
    262264        boolean rightOfSeg1 = angleIsClockwise(lineP1, lineP2, testPoint);
     
    271273    /**
    272274     * This method tests if secondNode is clockwise to first node.
     275     * @param <N> type of node
    273276     * @param commonNode starting point for both vectors
    274277     * @param firstNode first vector end node
     
    276279     * @return true if first vector is clockwise before second vector.
    277280     */
    278     public static boolean angleIsClockwise(Node commonNode, Node firstNode, Node secondNode) {
     281    public static <N extends INode> boolean angleIsClockwise(N commonNode, N firstNode, N secondNode) {
    279282        return angleIsClockwise(commonNode.getEastNorth(), firstNode.getEastNorth(), secondNode.getEastNorth());
    280283    }
     
    502505     * @since 6841
    503506     */
    504     public static Area getArea(List<Node> polygon) {
     507    public static Area getArea(List<? extends INode> polygon) {
    505508        Path2D path = new Path2D.Double();
    506509
    507510        boolean begin = true;
    508         for (Node n : polygon) {
     511        for (INode n : polygon) {
    509512            EastNorth en = n.getEastNorth();
    510513            if (en != null) {
     
    568571    /**
    569572     * Tests if two polygons intersect.
     573     * @param <N> type of node
    570574     * @param first List of nodes forming first polygon
    571575     * @param second List of nodes forming second polygon
    572576     * @return intersection kind
    573577     */
    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) {
    575579        Area a1 = getArea(first);
    576580        Area a2 = getArea(second);
     
    616620    /**
    617621     * Tests if point is inside a polygon. The polygon can be self-intersecting. In such case the contains function works in xor-like manner.
     622     * @param <N> type of node
    618623     * @param polygonNodes list of nodes from polygon path.
    619624     * @param point the point to test
    620625     * @return true if the point is inside polygon.
    621626     */
    622     public static boolean nodeInsidePolygon(Node point, List<Node> polygonNodes) {
     627    public static <N extends INode> boolean nodeInsidePolygon(N point, List<N> polygonNodes) {
    623628        if (polygonNodes.size() < 2)
    624629            return false;
    625630
    626631        //iterate each side of the polygon, start with the last segment
    627         Node oldPoint = polygonNodes.get(polygonNodes.size() - 1);
     632        N oldPoint = polygonNodes.get(polygonNodes.size() - 1);
    628633
    629634        if (!oldPoint.isLatLonKnown()) {
     
    632637
    633638        boolean inside = false;
    634         Node p1, p2;
    635 
    636         for (Node newPoint : polygonNodes) {
     639        N p1, p2;
     640
     641        for (N newPoint : polygonNodes) {
    637642            //skip duplicate points
    638643            if (newPoint.equals(oldPoint)) {
     
    740745     * @see #isClockwise(Way)
    741746     */
    742     public static boolean isClockwise(List<Node> nodes) {
     747    public static boolean isClockwise(List<? extends INode> nodes) {
    743748        int nodesCount = nodes.size();
    744749        if (nodesCount < 3 || nodes.get(0) != nodes.get(nodesCount - 1)) {
     
    748753
    749754        for (int node = 1; node <= /*sic! consider last-first 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);
    752757            area2 += coorPrev.lon() * coorCurr.lat();
    753758            area2 -= coorCurr.lon() * coorPrev.lat();
     
    814819     * @see Geometry#getCenter
    815820     */
    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()));
    818823    }
    819824
     
    884889     * @since 6934
    885890     */
    886     public static EastNorth getCenter(List<Node> nodes) {
     891    public static EastNorth getCenter(List<? extends INode> nodes) {
    887892        int nc = nodes.size();
    888893        if (nc < 3) return null;
     
    10341039     * @return area and perimeter
    10351040     */
    1036     public static AreaAndPerimeter getAreaAndPerimeter(List<Node> nodes) {
     1041    public static AreaAndPerimeter getAreaAndPerimeter(List<? extends ILatLon> nodes) {
    10371042        return getAreaAndPerimeter(nodes, null);
    10381043    }
Note: See TracChangeset for help on using the changeset viewer.