Changeset 7109 in josm
- Timestamp:
- 2014-05-12T00:40:09+02:00 (11 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r7108 r7109 25 25 import java.awt.geom.Point2D; 26 26 import java.awt.geom.Rectangle2D; 27 import java.util.AbstractList;28 27 import java.util.ArrayList; 29 28 import java.util.Collection; … … 71 70 import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList; 72 71 import org.openstreetmap.josm.gui.mappaint.TextElement; 72 import org.openstreetmap.josm.tools.CompositeList; 73 73 import org.openstreetmap.josm.tools.ImageProvider; 74 74 import org.openstreetmap.josm.tools.Utils; … … 237 237 238 238 return Float.compare(this.style.object_z_index, other.style.object_z_index); 239 }240 }241 242 /**243 * Joined List build from two Lists (read-only).244 *245 * Extremely simple single-purpose implementation.246 * @param <T>247 */248 public static class CompositeList<T> extends AbstractList<T> {249 List<? extends T> a,b;250 251 /**252 * Constructs a new {@code CompositeList} from two lists.253 * @param a First list254 * @param b Second list255 */256 public CompositeList(List<? extends T> a, List<? extends T> b) {257 this.a = a;258 this.b = b;259 }260 261 @Override262 public T get(int index) {263 return index < a.size() ? a.get(index) : b.get(index - a.size());264 }265 266 @Override267 public int size() {268 return a.size() + b.size();269 239 } 270 240 } … … 1360 1330 1361 1331 /** 1362 * Construct or for CreateStyleRecordsWorker.1332 * Constructs a new {@code ComputeStyleListWorker}. 1363 1333 * @param input the primitives to process 1364 1334 * @param from first index of <code>input</code> to use 1365 1335 * @param to last index + 1 1336 * @param output the list of styles to which styles will be added 1337 * @param data the data set 1366 1338 */ 1367 1339 public ComputeStyleListWorker(final List<? extends OsmPrimitive> input, int from, int to, List<StyleRecord> output, DataSet data) { … … 1516 1488 List<Way> ways = data.searchWays(bbox); 1517 1489 List<Relation> relations = data.searchRelations(bbox); 1518 1490 1519 1491 final List<StyleRecord> allStyleElems = new ArrayList<>(nodes.size()+ways.size()+relations.size()); 1520 1492 1521 1493 ConcurrentTasksHelper helper = new ConcurrentTasksHelper(allStyleElems, data); 1522 1494 … … 1545 1517 ); 1546 1518 } 1547 1519 1548 1520 if (Main.isTraceEnabled()) { 1549 1521 timeFinished = System.currentTimeMillis(); 1550 1522 System.err.println("; phase 2 (draw): " + (timeFinished - timePhase1) + " ms; total: " + (timeFinished - timeStart) + " ms"); 1551 1523 } 1552 1524 1553 1525 drawVirtualNodes(data, bbox); 1554 1526 } finally { -
trunk/test/performance/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRendererPerformanceTest.java
r7093 r7109 4 4 import java.awt.Graphics2D; 5 5 import java.awt.image.BufferedImage; 6 import java.io.File; 6 7 import java.io.FileInputStream; 7 8 import java.io.InputStream; 8 import java.io.File;9 9 10 10 import org.junit.BeforeClass; 11 11 import org.junit.Test; 12 import org.openstreetmap.josm. Main;12 import org.openstreetmap.josm.JOSMFixture; 13 13 import org.openstreetmap.josm.data.Bounds; 14 14 import org.openstreetmap.josm.data.osm.DataSet; 15 import org.openstreetmap.josm.data.projection.Projections;16 15 import org.openstreetmap.josm.gui.NavigatableComponent; 17 16 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 18 17 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 18 import org.openstreetmap.josm.io.Compression; 19 19 import org.openstreetmap.josm.io.OsmReader; 20 import org.openstreetmap.josm.io.Compression;21 20 22 21 public class StyledMapRendererPerformanceTest { … … 34 33 @BeforeClass 35 34 public static void load() throws Exception { 36 Main.initApplicationPreferences(); 37 Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator 35 JOSMFixture.createPerformanceTestFixture().init(); 38 36 img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_3BYTE_BGR); 39 37 g = (Graphics2D)img.getGraphics(); … … 53 51 dsCity = OsmReader.parseDataSet(fisC, NullProgressMonitor.INSTANCE); 54 52 } 55 56 // Warm up57 new StyledMapRendererPerformanceTest().testRestrictionSmall();58 new StyledMapRendererPerformanceTest().testCity();59 53 } 60 54 -
trunk/test/performance/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSPerformanceTest.groovy
r7068 r7109 111 111 def mv = Main.map.mapView 112 112 113 BufferedImage img = mv.createImage(mv.getWidth(), mv.getHeight())113 BufferedImage img = new BufferedImage(mv.getWidth(), mv.getHeight(), BufferedImage.TYPE_3BYTE_BGR) 114 114 Graphics2D g = img.createGraphics() 115 115 g.setClip(0,0, mv.getWidth(), mv.getHeight()) -
trunk/test/unit/org/openstreetmap/josm/TestUtils.java
r7068 r7109 5 5 import static org.junit.Assert.assertThat; 6 6 import static org.junit.Assert.assertTrue; 7 import static org.junit.Assert.fail; 7 8 9 import java.util.Arrays; 10 import java.util.Comparator; 8 11 import java.util.Map; 9 12 10 13 import org.junit.Test; 11 import org.openstreetmap.josm.Main;12 14 import org.openstreetmap.josm.data.osm.Node; 13 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 65 67 } 66 68 69 /** 70 * Checks that the given Comparator respects its contract on the given table. 71 * @param comparator The comparator to test 72 * @param array The array sorted for test purpose 73 */ 74 public static <T> void checkComparableContract(Comparator<T> comparator, T[] array) { 75 System.out.println("Validating Comparable contract on array of "+array.length+" elements"); 76 // Check each compare possibility 77 for (int i=0; i<array.length; i++) { 78 T r1 = array[i]; 79 for (int j=i; j<array.length; j++) { 80 T r2 = array[j]; 81 int a = comparator.compare(r1, r2); 82 int b = comparator.compare(r2, r1); 83 if (i==j || a==b) { 84 if (a != 0 || b != 0) { 85 fail(getFailMessage(r1, r2, a, b)); 86 } 87 } else { 88 if (a != -b) { 89 fail(getFailMessage(r1, r2, a, b)); 90 } 91 } 92 for (int k=j; k<array.length; k++) { 93 T r3 = array[k]; 94 int c = comparator.compare(r1, r3); 95 int d = comparator.compare(r2, r3); 96 if (a > 0 && d > 0) { 97 if (c <= 0) { 98 fail(getFailMessage(r1, r2, r3, a, b, c, d)); 99 } 100 } else if (a == 0 && d == 0) { 101 if (c != 0) { 102 fail(getFailMessage(r1, r2, r3, a, b, c, d)); 103 } 104 } else if (a < 0 && d < 0) { 105 if (c >= 0) { 106 fail(getFailMessage(r1, r2, r3, a, b, c, d)); 107 } 108 } 109 } 110 } 111 } 112 // Sort relation array 113 Arrays.sort(array, comparator); 114 } 115 116 private static <T> String getFailMessage(T o1, T o2, int a, int b) { 117 return new StringBuilder("Compared\no1: ").append(o1).append("\no2: ") 118 .append(o2).append("\ngave: ").append(a).append("/").append(b) 119 .toString(); 120 } 121 122 private static <T> String getFailMessage(T o1, T o2, T o3, int a, int b, int c, int d) { 123 return new StringBuilder(getFailMessage(o1, o2, a, b)) 124 .append("\nCompared\no1: ").append(o1).append("\no3: ").append(o3).append("\ngave: ").append(c) 125 .append("\nCompared\no2: ").append(o2).append("\no3: ").append(o3).append("\ngave: ").append(d) 126 .toString(); 127 } 67 128 } -
trunk/test/unit/org/openstreetmap/josm/gui/DefaultNameFormatterTest.java
r7100 r7109 3 3 4 4 import static org.junit.Assert.assertTrue; 5 import static org.junit.Assert.fail;6 5 7 6 import java.io.FileInputStream; … … 9 8 import java.io.InputStream; 10 9 import java.util.ArrayList; 11 import java.util.Arrays;12 10 import java.util.Comparator; 13 11 … … 75 73 Relation[] relations = new ArrayList<>(ds.getRelations()).toArray(new Relation[0]); 76 74 77 // Check each compare possibility 78 for (int i=0; i<relations.length; i++) { 79 Relation r1 = relations[i]; 80 for (int j=i; j<relations.length; j++) { 81 Relation r2 = relations[j]; 82 int a = comparator.compare(r1, r2); 83 int b = comparator.compare(r2, r1); 84 if (i==j || a==b) { 85 if (a != 0 || b != 0) { 86 fail(getFailMessage(r1, r2, a, b)); 87 } 88 } else { 89 if (a != -b) { 90 fail(getFailMessage(r1, r2, a, b)); 91 } 92 } 93 for (int k=j; k<relations.length; k++) { 94 Relation r3 = relations[k]; 95 int c = comparator.compare(r1, r3); 96 int d = comparator.compare(r2, r3); 97 if (a > 0 && d > 0) { 98 if (c <= 0) { 99 fail(getFailMessage(r1, r2, r3, a, b, c, d)); 100 } 101 } else if (a == 0 && d == 0) { 102 if (c != 0) { 103 fail(getFailMessage(r1, r2, r3, a, b, c, d)); 104 } 105 } else if (a < 0 && d < 0) { 106 if (c >= 0) { 107 fail(getFailMessage(r1, r2, r3, a, b, c, d)); 108 } 109 } 110 } 111 } 112 } 113 // Sort relation array 114 Arrays.sort(relations, comparator); 75 TestUtils.checkComparableContract(comparator, relations); 115 76 } 116 77 } 117 118 private static String getFailMessage(Relation r1, Relation r2, int a, int b) {119 return new StringBuilder("Compared\nr1: ").append(r1).append("\nr2: ")120 .append(r2).append("\ngave: ").append(a).append("/").append(b)121 .toString();122 }123 124 private static String getFailMessage(Relation r1, Relation r2, Relation r3, int a, int b, int c, int d) {125 return new StringBuilder(getFailMessage(r1, r2, a, b))126 .append("\nCompared\nr1: ").append(r1).append("\nr3: ").append(r3).append("\ngave: ").append(c)127 .append("\nCompared\nr2: ").append(r2).append("\nr3: ").append(r3).append("\ngave: ").append(d)128 .toString();129 }130 78 }
Note:
See TracChangeset
for help on using the changeset viewer.