Ignore:
Timestamp:
2013-08-28T03:03:40+02:00 (11 years ago)
Author:
Don-vip
Message:

fix #9024 - bbox/bounds memory optimizations (modified patch by shinigami) + javadoc

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/BBox.java

    r6178 r6203  
    44import java.util.Arrays;
    55
    6 import org.openstreetmap.josm.data.Bounds;
    76import org.openstreetmap.josm.data.coor.LatLon;
    87import org.openstreetmap.josm.data.coor.QuadTiling;
     
    1615    private double ymax = Double.NEGATIVE_INFINITY;
    1716
    18     public BBox(Bounds bounds) {
    19         add(bounds.getMin());
    20         add(bounds.getMax());
    21     }
    22 
     17    /**
     18     * Constructs a new {@code BBox} defined by a single point.
     19     *
     20     * @param x X coordinate
     21     * @param y Y coordinate
     22     * @since 6203
     23     */
     24    public BBox(final double x, final double y) {
     25        xmax = xmin = x;
     26        ymax = ymin = y;
     27        sanity();
     28    }
     29
     30    /**
     31     * Constructs a new {@code BBox} defined by points <code>a</code> and <code>b</code>.
     32     * Result is minimal BBox containing both points.
     33     *
     34     * @param a
     35     * @param b
     36     */
    2337    public BBox(LatLon a, LatLon b) {
    24         add(a);
    25         add(b);
    26     }
    27 
     38        this(a.lon(), a.lat(), b.lon(), b.lat());
     39    }
     40
     41    /**
     42     * Constructs a new {@code BBox} from another one.
     43     *
     44     * @param copy the BBox to copy
     45     */
    2846    public BBox(BBox copy) {
    2947        this.xmin = copy.xmin;
     
    3452
    3553    public BBox(double a_x, double a_y, double b_x, double b_y)  {
    36         xmin = Math.min(a_x, b_x);
    37         xmax = Math.max(a_x, b_x);
    38         ymin = Math.min(a_y, b_y);
    39         ymax = Math.max(a_y, b_y);
     54       
     55        if (a_x > b_x) {
     56            xmax = a_x;
     57            xmin = b_x;
     58        } else {
     59            xmax = b_x;
     60            xmin = a_x;
     61        }
     62       
     63        if (a_y > b_y) {
     64            ymax = a_y;
     65            ymin = b_y;
     66        } else {
     67            ymax = b_y;
     68            ymin = a_y;
     69        }
     70       
    4071        sanity();
    4172    }
     
    84115     */
    85116    public void add(double x, double y) {
    86         xmin = Math.min(xmin, x);
    87         xmax = Math.max(xmax, x);
    88         ymin = Math.min(ymin, y);
    89         ymax = Math.max(ymax, y);
     117       
     118        if (x < xmin) {
     119            xmin = x;
     120        } else if (x > xmax) {
     121            xmax = x;
     122        }
     123       
     124        if (y < ymin) {
     125            ymin = y;
     126        } else if (y > ymax) {
     127            ymax = y;
     128        }
     129
    90130        sanity();
    91131    }
    92132
    93133    public void add(BBox box) {
    94         add(box.getTopLeft());
    95         add(box.getBottomRight());
     134        xmin = Math.min(xmin, box.xmin);
     135        xmax = Math.max(xmax, box.xmax);
     136        ymin = Math.min(ymin, box.ymin);
     137        ymax = Math.max(ymax, box.ymax);
     138        sanity();
    96139    }
    97140
     
    151194    }
    152195
     196    /**
     197     * Returns the top-left point.
     198     * @return The top-left point
     199     */
    153200    public LatLon getTopLeft() {
    154201        return new LatLon(ymax, xmin);
    155202    }
    156203
     204    /**
     205     * Returns the latitude of top-left point.
     206     * @return The latitude of top-left point
     207     * @since 6203
     208     */
     209    public double getTopLeftLat() {
     210        return ymax;
     211    }
     212
     213    /**
     214     * Returns the longitude of top-left point.
     215     * @return The longitude of top-left point
     216     * @since 6203
     217     */
     218    public double getTopLeftLon() {
     219        return xmin;
     220    }
     221
     222    /**
     223     * Returns the bottom-right point.
     224     * @return The bottom-right point
     225     */
    157226    public LatLon getBottomRight() {
    158227        return new LatLon(ymin, xmax);
     228    }
     229
     230    /**
     231     * Returns the latitude of bottom-right point.
     232     * @return The latitude of bottom-right point
     233     * @since 6203
     234     */
     235    public double getBottomRightLat() {
     236        return ymin;
     237    }
     238
     239    /**
     240     * Returns the longitude of bottom-right point.
     241     * @return The longitude of bottom-right point
     242     * @since 6203
     243     */
     244    public double getBottomRightLon() {
     245        return xmax;
    159246    }
    160247
  • trunk/src/org/openstreetmap/josm/data/osm/DatasetConsistencyTest.java

    r5356 r6203  
    8181                LatLon c = n.getCoor();
    8282                if (c != null) {
    83                     BBox box = new BBox(new LatLon(c.lat() - 0.0001, c.lon() - 0.0001), new LatLon(c.lat() + 0.0001, c.lon() + 0.0001));
     83                    BBox box = c.toBBox(0.0001);
    8484                    if (!dataSet.searchNodes(box).contains(n)) {
    8585                        printError("SEARCH NODES", "%s not found using Dataset.searchNodes()", n);
  • trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java

    r6181 r6203  
    117117            double lat = bottom_left.lat() + parent.height() / 2;
    118118            double lon = bottom_left.lon() + parent.width() / 2;
    119             LatLon top_right = new LatLon(lat, lon);
    120             return new BBox(bottom_left, top_right);
     119            return new BBox(bottom_left.lon(), bottom_left.lat(), lon, lat);
    121120        }
    122121
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java

    r6172 r6203  
    14041404    public void render(final DataSet data, boolean renderVirtualNodes, Bounds bounds) {
    14051405        //long start = System.currentTimeMillis();
    1406         BBox bbox = new BBox(bounds);
     1406        BBox bbox = bounds.toBBox();
    14071407        getSettings(renderVirtualNodes);
    14081408
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/WireframeMapRenderer.java

    r6113 r6203  
    157157    @Override
    158158    public void render(DataSet data, boolean virtual, Bounds bounds) {
    159         BBox bbox = new BBox(bounds);
     159        BBox bbox = bounds.toBBox();
    160160        this.ds = data;
    161161        getSettings(virtual);
Note: See TracChangeset for help on using the changeset viewer.