Ejemplo n.º 1
0
  @Override
  public Collection<Element> parse(DXFLayer layer)
      throws NullArgumentException, InvalidArgumentException {

    Collection<Element> archimedesSemilines = new ArrayList<Element>();
    List<DXFRay> dxfSemilines = layer.getDXFEntities(DXFConstants.ENTITY_TYPE_RAY);

    if (dxfSemilines != null) {
      for (DXFRay dxfSemiline : dxfSemilines) {
        org.kabeja.dxf.helpers.Point startPoint = dxfSemiline.getBasePoint();
        Vector direction = dxfSemiline.getDirection();

        double x = startPoint.getX();
        double y = startPoint.getY();

        Point p1 = new Point(x, y);
        Point p2 = new Point(direction.getX() + x, direction.getY() + y);

        Semiline semiline = new Semiline(p1, p2);

        archimedesSemilines.add(semiline);
      }
    }
    return archimedesSemilines;
  }
 /**
  * Add one DXFEntity to the appropriate bucket.
  *
  * @param e the entity
  * @param p the point. Could be the start or the end of the entity
  */
 public void addEntity(DXFBucketEntity e, Point p) {
   Iterator<DXFBucket> ib = buckets.iterator();
   while (ib.hasNext()) {
     DXFBucket b = ib.next();
     if (b.topLeft.getY() <= p.getY()
         && b.topLeft.getX() <= p.getX()
         && b.bottomRight.getY() >= p.getY()
         && b.bottomRight.getX() >= p.getX()) {
       // inside this bucket's region
       b.push(e, p);
       return;
     }
   }
   System.out.println("Not added " + p);
 }
  /**
   * @param cellsWide >0
   * @param cellsHigh >0
   * @param topLeft smallest X and smallest Y value
   * @param bottomRight largest X and largest Y value
   */
  public DXFBucketGrid(int cellsWide, int cellsHigh, Point topLeft, Point bottomRight) {
    int totalCells = cellsWide * cellsHigh;
    assert (totalCells > 0);

    // System.out.println("OUTER BOUNDS
    // ("+topLeft.getX()+","+topLeft.getY()+")-("+bottomRight.getX()+","+bottomRight.getY()+")");
    buckets = new ArrayList<DXFBucket>();
    double dx = bottomRight.getX() - topLeft.getX();
    double dy = bottomRight.getY() - topLeft.getY();

    int x, y;
    for (y = 0; y < cellsHigh; ++y) {
      for (x = 0; x < cellsWide; ++x) {
        DXFBucket b = new DXFBucket(x, y);
        buckets.add(b);
        b.topLeft.setX((x / (double) cellsWide) * dx + topLeft.getX());
        b.topLeft.setY((y / (double) cellsHigh) * dy + topLeft.getY());
        b.bottomRight.setX(((x + 1) / (double) cellsWide) * dx + topLeft.getX());
        b.bottomRight.setY(((y + 1) / (double) cellsHigh) * dy + topLeft.getY());
        // System.out.println(x+","+y+" =
        // ("+b.topLeft.getX()+","+b.topLeft.getY()+")-("+b.bottomRight.getX()+","+b.bottomRight.getY()+")");
      }
    }
  }