Exemple #1
0
  public Bounds getBounds() {
    Bounds bounds = new Bounds();

    Iterator<LW2DVertex> i = vertices.iterator();

    if (i.hasNext()) {
      LW2DVertex last;
      LW2DVertex first;
      LW2DVertex v = null;

      last = first = i.next();
      bounds.addToBounds(last.getX(), last.getY(), 0.0);

      while (i.hasNext()) {
        v = i.next();
        addToBounds(last, v, bounds);
        last = v;
      }

      if ((v != null) && (v.getBulge() != 0.0)) {
        addToBounds(v, first, bounds);
      }
    } else {
      bounds.setValid(false);
    }

    return bounds;
  }
Exemple #2
0
  public Bounds getBounds() {
    Bounds bounds = new Bounds();
    bounds.setValid(false);

    return bounds;
  }
Exemple #3
0
  protected void addToBounds(LW2DVertex start, LW2DVertex end, Bounds bounds) {
    if (start.getBulge() != 0) {
      // calculte the height

      double l = MathUtils.distance(start.getPoint(), end.getPoint());

      // double h = Math.abs(last.getBulge()) * l / 2;
      double r = this.getRadius(start.getBulge(), l);

      double s = l / 2;
      Vector edgeDirection = MathUtils.getVector(start.getPoint(), end.getPoint());
      edgeDirection = MathUtils.normalize(edgeDirection);

      Point3D centerPoint = MathUtils.getPointOfStraightLine(start.getPoint(), edgeDirection, s);

      Vector centerPointDirection =
          MathUtils.crossProduct(edgeDirection, this.getExtrusion().getNormal());
      centerPointDirection = MathUtils.normalize(centerPointDirection);

      // double t = Math.sqrt(Math.pow(r, 2) - Math.pow(s, 2));
      // double t = 0;
      double h = Math.abs(start.getBulge() * l) / 2;

      // if(Math.abs(start.getBulge())>=1.0){
      // t = h-r;
      // }else{
      // //t = Math.sqrt(Math.pow(r, 2) - Math.pow(s, 2));
      // t=r-h;
      // }
      // the center point of the arc
      int startQ = 0;
      int endQ = 0;

      double bulge = start.getBulge();

      if (bulge > 0) {
        // the arc goes over the right side, but where is the center
        // point?
        if (bulge > 1.0) {
          double t = h - r;
          centerPoint = MathUtils.getPointOfStraightLine(centerPoint, centerPointDirection, t);
        } else {
          double t = r - h;
          centerPoint =
              MathUtils.getPointOfStraightLine(centerPoint, centerPointDirection, (-1 * t));
        }

        endQ = MathUtils.getQuadrant(end.getPoint(), centerPoint);
        startQ = MathUtils.getQuadrant(start.getPoint(), centerPoint);
      } else {
        // the arc goes over the left side, but where is the center
        // point?
        if (bulge < -1.0) {
          double t = h - r;
          centerPoint =
              MathUtils.getPointOfStraightLine(centerPoint, centerPointDirection, (-1 * t));
        } else {
          double t = r - h;
          centerPoint = MathUtils.getPointOfStraightLine(centerPoint, centerPointDirection, t);
        }

        startQ = MathUtils.getQuadrant(end.getPoint(), centerPoint);
        endQ = MathUtils.getQuadrant(start.getPoint(), centerPoint);
      }

      if (endQ < startQ) {
        endQ += 4;
      } else if ((endQ == startQ) && (Math.abs(start.getBulge()) > QUARTER_CIRCLE_ANGLE)) {
        endQ += 4;
      }

      while (endQ > startQ) {
        switch (startQ) {
          case 0:
            bounds.addToBounds(centerPoint.getX(), centerPoint.getY() + r, centerPoint.getZ());

            break;

          case 1:
            bounds.addToBounds(centerPoint.getX() - r, centerPoint.getY(), centerPoint.getZ());

            break;

          case 2:
            bounds.addToBounds(centerPoint.getX(), centerPoint.getY() - r, centerPoint.getZ());

            break;

          case 3:
            bounds.addToBounds(centerPoint.getX() + r, centerPoint.getY(), centerPoint.getZ());
            endQ -= 4;
            startQ -= 4;

            break;
        }

        startQ++;
      }
    }

    bounds.addToBounds(start.getPoint());
    bounds.addToBounds(end.getPoint());
  }