Changeset 24046 in osm for applications/editors/josm
- Timestamp:
- 2010-11-03T17:01:05+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pdfimport/src/pdfimport/PathOptimizer.java
r23991 r24046 13 13 public class PathOptimizer { 14 14 15 public List<Point2D> uniquePoints; 15 16 public Map<Point2D, Point2D> uniquePointMap; 16 17 private final Map<LayerInfo, LayerContents> layerMap; 17 18 private List<LayerContents> layers; 18 19 public Rectangle2D bounds; 20 private final double POINT_TOLERANCE = 1e-6; 19 21 20 22 public PathOptimizer() 21 23 { 22 24 uniquePointMap = new HashMap<Point2D, Point2D>(); 25 uniquePoints = new ArrayList<Point2D>(); 23 26 layerMap = new HashMap<LayerInfo, LayerContents>(); 24 27 layers = new ArrayList<LayerContents>(); … … 27 30 public Point2D getUniquePoint(Point2D point) { 28 31 29 if ( this.uniquePointMap.containsKey(point)){30 return this.uniquePointMap.get(point);32 if (uniquePointMap.containsKey(point)){ 33 return uniquePointMap.get(point); 31 34 } 32 35 else { 33 this.uniquePointMap.put(point, point); 36 uniquePointMap.put(point, point); 37 uniquePoints.add(point); 34 38 return point; 35 39 } … … 69 73 public void optimize() 70 74 { 75 //fix points 76 Map<Point2D, Point2D> pointMap = DuplicateNodesFinder.findDuplicateNodes(uniquePoints, POINT_TOLERANCE); 77 71 78 72 79 for(LayerContents layer: this.layers) { 80 this.fixPoints(layer, pointMap); 73 81 this.concatenatePaths(layer); 74 82 } … … 106 114 } 107 115 116 108 117 private void finalizeLayer(LayerContents layer){ 109 118 Set<Point2D> points = new HashSet<Point2D>(); … … 134 143 } 135 144 } 145 } 146 147 private void fixPoints(LayerContents layer, Map<Point2D, Point2D> pointMap) { 148 149 List<PdfPath> newPaths = new ArrayList<PdfPath>(layer.paths.size()); 150 151 for(PdfPath path: layer.paths) { 152 List<Point2D> points = fixPoints(path.points, pointMap); 153 path.points = points; 154 if (points.size() > 2 || (!path.isClosed() && points.size() > 1)){ 155 156 newPaths.add(path); 157 } 158 } 159 160 layer.paths = newPaths; 161 162 for (PdfMultiPath mp: layer.multiPaths){ 163 for(PdfPath path: mp.paths) { 164 path.points = fixPoints(path.points, pointMap); 165 } 166 } 167 } 168 169 170 private List<Point2D> fixPoints(List<Point2D> points, Map<Point2D, Point2D> pointMap) { 171 172 List<Point2D> newPoints = new ArrayList<Point2D>(points.size()); 173 Point2D prevPoint = null; 174 175 for(Point2D p: points){ 176 Point2D pp = p; 177 178 if (pointMap.containsKey(p)){ 179 pp = pointMap.get(p); 180 } 181 182 if (prevPoint != pp){ 183 newPoints.add(pp); 184 } 185 186 prevPoint = pp; 187 } 188 189 return newPoints; 136 190 } 137 191
Note:
See TracChangeset
for help on using the changeset viewer.