src/main/java/de/blau/android/osm/StorageDelegator.java
/**
     * Arrange way nodes in a circle
     * 
     * FIXME use w,h,v parameters instead of map for testing
     * 
     * @param map current map view
     * @param way way to circulize
     */
Arrange way nodes in a circle



@param map current map view
@param way way to circulize
Arrange way nodes in a circle @param map current map view @param way way to circulize
public void circulizeWay(@NonNull de.blau.android.Map map, @NonNull Way way) {
        final List<Node> wayNodes = way.getNodes();
        if (wayNodes.size() < 3) {
            Log.d(DEBUG_TAG, "circulize way " + way.getOsmId() + " has no nodes or less than 3!");
            return;
        }
        dirty = true;
        try {
            Set<Node> nodes = new LinkedHashSet<>(wayNodes); 
            invalidateWayBoundingBox(nodes);
            int width = map.getWidth();
            int height = map.getHeight();
            ViewBox box = map.getViewBox();
            Coordinates[] coords = Coordinates.nodeListToCoordinateArray(width, height, box, new ArrayList<>(nodes));
            for (Node nd : nodes) {
                undo.save(nd);
            }
            Coordinates center = Geometry.centroidXY(coords, true);
            double r = 0.0f;
            for (Coordinates p : coords) {
                r = r + Math.sqrt((p.x - center.x) * (p.x - center.x) + (p.y - center.y) * (p.y - center.y));
            }
            r = r / coords.length;
            for (Coordinates p : coords) {
                double ratio = r / Math.sqrt((p.x - center.x) * (p.x - center.x) + (p.y - center.y) * (p.y - center.y));
                p.x = ((p.x - center.x) * ratio) + center.x;
                p.y = ((p.y - center.y) * ratio) + center.y;
            }
            int i = 0;
            for (Node nd : nodes) {
                updateLatLon(nd, GeoMath.yToLatE7(height, width, box, (float) coords[i].y), GeoMath.xToLonE7(width, box, (float) coords[i].x));
                i++;
            }
        } catch (StorageException e) {
            Log.e(DEBUG_TAG, "circulizeWay got " + e.getMessage());
        }
    }
public void circulizeWay ( @ NonNull de . blau . android . Map map , @ NonNull Way way ) { final List < Node > wayNodes = way . getNodes ( ) ; if ( wayNodes . size ( ) < 3 ) { Log . d ( DEBUG_TAG , "circulize way " + way . getOsmId ( ) + " has no nodes or less than 3!" ) ; return ; } dirty = true ; try { Set < Node > nodes = new LinkedHashSet < > ( wayNodes ) ; invalidateWayBoundingBox ( nodes ) ; int width = map . getWidth ( ) ; int height = map . getHeight ( ) ; ViewBox box = map . getViewBox ( ) ; Coordinates [ ] coords = Coordinates . nodeListToCoordinateArray ( width , height , box , new ArrayList < > ( nodes ) ) ; for ( Node nd : nodes ) { undo . save ( nd ) ; } Coordinates center = Geometry . centroidXY ( coords , true ) ; double r = 0.0f ; for ( Coordinates p : coords ) { r = r + Math . sqrt ( ( p . x - center . x ) * ( p . x - center . x ) + ( p . y - center . y ) * ( p . y - center . y ) ) ; } r = r / coords . length ; for ( Coordinates p : coords ) { double ratio = r / Math . sqrt ( ( p . x - center . x ) * ( p . x - center . x ) + ( p . y - center . y ) * ( p . y - center . y ) ) ; p . x = ( ( p . x - center . x ) * ratio ) + center . x ; p . y = ( ( p . y - center . y ) * ratio ) + center . y ; } int i = 0 ; for ( Node nd : nodes ) { updateLatLon ( nd , GeoMath . yToLatE7 ( height , width , box , ( float ) coords [ i ] . y ) , GeoMath . xToLonE7 ( width , box , ( float ) coords [ i ] . x ) ) ; i ++ ; } } catch ( StorageException e ) { Log . e ( DEBUG_TAG , "circulizeWay got " + e . getMessage ( ) ) ; } }
Arrange way nodes in a circle
Arrange way nodes in a circle
// Guarantee uniqueness // save nodes for undo // caclulate average radius // Don't call onElementChanged // TODO handle OOM