Changeset 2982 in josm for trunk/test


Ignore:
Timestamp:
2010-02-14T15:01:00+01:00 (10 years ago)
Author:
jttt
Message:

Calculate bbox for relations, use it in mappaint.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/osm/RelationTest.java

    r1806 r2982  
    22package org.openstreetmap.josm.data.osm;
    33
     4import static org.junit.Assert.assertFalse;
     5
     6import org.junit.Assert;
    47import org.junit.Test;
    5 
    6 import static org.junit.Assert.*;
     8import org.openstreetmap.josm.data.coor.LatLon;
    79
    810public class RelationTest {
     11
    912    @Test(expected=NullPointerException.class)
    1013    public void createNewRelation() {
     
    1821    }
    1922
     23    @Test
     24    public void testBBox() {
     25        DataSet ds = new DataSet();
     26
     27        Node n1 = new Node(new LatLon(10, 10));
     28        Node n2 = new Node(new LatLon(20, 20));
     29        Node n3 = new Node(new LatLon(30, 30));
     30        Way w1 = new Way();
     31        w1.addNode(n1);
     32        w1.addNode(n2);
     33        Relation r1 = new Relation();
     34        Relation r2 = new Relation();
     35        ds.addPrimitive(r1);
     36        ds.addPrimitive(r2);
     37        ds.addPrimitive(n1);
     38        ds.addPrimitive(n2);
     39        ds.addPrimitive(n3);
     40        ds.addPrimitive(w1);
     41        r1.addMember(new RelationMember("", n1));
     42        r1.addMember(new RelationMember("", w1));
     43        r1.addMember(new RelationMember("", r1));
     44        r1.addMember(new RelationMember("", r2));
     45        r2.addMember(new RelationMember("", r1));
     46        r2.addMember(new RelationMember("", n3));
     47
     48        BBox bbox = new BBox(w1);
     49        bbox.add(n3.getBBox());
     50        Assert.assertEquals(bbox, r1.getBBox());
     51        Assert.assertEquals(bbox, r2.getBBox());
     52
     53        n3.setCoor(new LatLon(40, 40));
     54        bbox.add(n3.getBBox());
     55        Assert.assertEquals(bbox, r1.getBBox());
     56        Assert.assertEquals(bbox, r2.getBBox());
     57
     58        r1.removeMembersFor(r2);
     59        Assert.assertEquals(w1.getBBox(), r1.getBBox());
     60        Assert.assertEquals(bbox, r2.getBBox());
     61
     62        w1.addNode(n3);
     63        Assert.assertEquals(w1.getBBox(), r1.getBBox());
     64        Assert.assertEquals(w1.getBBox(), r2.getBBox());
     65    }
     66
    2067}
Note: See TracChangeset for help on using the changeset viewer.