Changeset 20084 in osm


Ignore:
Timestamp:
2010-02-20T17:43:55+01:00 (15 years ago)
Author:
bastik
Message:

'josm terracer plugin: minor bug (Broken test, whether two sements are next to each other for a closed way.)'

Location:
applications/editors/josm/plugins/terracer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/terracer/build.xml

    r19678 r20084  
    3232
    3333
    34     <property name="commit.message" value="josm terracer plugin: fixed reverse terrace, minor updates" />
     34    <property name="commit.message" value="josm terracer plugin: minor bug (Broken test, whether two sements are next to each other for a closed way.)" />
    3535    <property name="plugin.main.version" value="2830" />
    3636
  • applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java

    r19678 r20084  
    191191        // create intermediate nodes by interpolating.
    192192        for (int i = 0; i <= nb; ++i) {
    193             new_nodes[0][i] = interpolateAlong(interp.a, frontLength * (i)
    194                     / (nb));
    195             new_nodes[1][i] = interpolateAlong(interp.b, backLength * (i)
    196                     / (nb));
     193            new_nodes[0][i] = interpolateAlong(interp.a, frontLength * i / nb);
     194            new_nodes[1][i] = interpolateAlong(interp.b, backLength * i / nb);
    197195            commands.add(new AddCommand(new_nodes[0][i]));
    198196            commands.add(new AddCommand(new_nodes[1][i]));
     
    323321        // than a quadrilateral would have been rejected at an earlier
    324322        // stage.
    325         if (Math.abs(side1 - side2) < 2) {
     323        if (indexDistance(side1, side2, indexes.length) < 2) {
    326324            side2 = indexes[2];
    327325        }
    328         if (Math.abs(side1 - side2) < 2) {
     326        if (indexDistance(side1, side2, indexes.length) < 2) {
    329327            side2 = indexes[3];
    330328        }
     
    366364
    367365    /**
     366     * returns the distance of two segments of a closed polygon
     367     */
     368    private int indexDistance(int i1, int i2, int n) {
     369        return Math.min(positiveModulus(i1 - i2, n), positiveModulus(i2 - i1, n));
     370    }
     371   
     372    /**
     373     * return the modulus in the range [0, n)
     374     */
     375    private int positiveModulus(int a, int n) {
     376        if (n <=0)
     377            throw new IllegalArgumentException();
     378        int res = a % n;
     379        if (res < 0) {
     380            res += n;
     381        }
     382        return res;
     383    }
     384   
     385    /**
    368386     * Calculate the length of a side (from node i to i+1) in a way. This assumes that
    369387     * the way is closed, but I only ever call it for buildings.
Note: See TracChangeset for help on using the changeset viewer.