예제 #1
0
 @Override
 public boolean isInBounds(Bounds bounds) {
   // TODO there is no float polygon, so I have to think about s.th. else (or leave it the way it
   // is now)
   int x[] = new int[nodes.length];
   int y[] = new int[nodes.length];
   int i = 0;
   for (Node node : nodes) {
     x[i] = (int) (node.getPos().getLongitude() * 1000); // 1000 is a random factor, can be changed
     i++;
   }
   i = 0;
   for (Node node : nodes) {
     y[i] = (int) (node.getPos().getLatitude() * 1000);
     i++;
   }
   Polygon area = new Polygon(x, y, nodes.length);
   Rectangle2D.Double box =
       new Rectangle2D.Double(
           bounds.getLeft() * 1000 - 1,
           bounds.getTop() * 1000 - 1,
           bounds.getWidth() * 1000 + 1,
           bounds.getHeight() * 1000 + 1);
   boolean inside = false;
   for (Node node : nodes) {
     if (node.isInBounds(bounds)) {
       inside = true;
     }
   }
   return inside || area.contains(box) || area.intersects(box);
 }
 public void createChildren() {
   children = new DividerTree[4];
   float width = bounds.getWidth() / 2;
   float height = bounds.getHeight() / 2;
   for (int i = 0; i < 4; i++) {
     Coordinates topLeft = bounds.getTopLeft().add(height * (i % 2), width * (i / 2));
     children[i] = new DividerTree(new Bounds(topLeft, topLeft.clone().add(height, width)));
   }
 };
예제 #3
0
 @Override
 public MapElement getReduced(int detail, float range) {
   // draw everything on detail 0
   if (detail == 0) {
     return this;
   }
   // determine bounding box, discard too small areas
   Bounds bounds = new Bounds(nodes[0].getPos(), 0);
   for (Node node : nodes) {
     bounds.extend(node.getLatitude(), node.getLongitude());
   }
   if (bounds.getHeight() + bounds.getWidth() < range) {
     return null;
   }
   // return simplified area
   Area result = new Area(name, wayInfo);
   result.setNodes(Street.simplifyNodes(nodes, range / 2));
   if (result.nodes.length <= MIN_REDUCTION_NODES && nodes.length > MIN_REDUCTION_NODES) {
     return null;
   }
   return (result.nodes.length == nodes.length) ? this : result;
 }
 public DividerTree(Bounds bounds) {
   this.bounds = bounds.clone();
 }