protected void applyOffsetAmount(Point p1, Point p2, int offset, Point res) {
    // slope of the line we're finding the normal to
    // is slope, and the normal is the negative reciprocal
    // slope is (p1.y - p2.y) / (p1.x - p2.x)
    // so recip is - (p1.x - p2.x) / (p1.y - p2.y)
    int recipnumerator = (p1.x - p2.x) * -1;
    int recipdenominator = (p1.y - p2.y);

    if (recipdenominator == 0 && recipnumerator == 0) return;

    // find the point offset on the line that gives a
    // correct offset

    double len = Math.sqrt(recipnumerator * recipnumerator + recipdenominator * recipdenominator);
    int dx = (int) ((recipdenominator * offset) / len);
    int dy = (int) ((recipnumerator * offset) / len);

    res.x += Math.abs(dx);
    res.y -= Math.abs(dy);

    int width = itemFig.getWidth() / 2;

    if (recipnumerator != 0) {
      double slope = (double) recipdenominator / (double) recipnumerator;

      double factor = tanh(slope);
      res.x += (Math.abs(factor) * width);
    } else {
      res.x += width;
    }
  }
Beispiel #2
0
  private String getDescr(Fig f) {
    if (f == null) {
      return null;
    }
    String className = f.getClass().getName();
    StringBuffer descr = new StringBuffer(className.substring(className.lastIndexOf(".") + 1));
    //        descr.append(" - paints=").append(f.getPaintCount());
    //        descr.append(" - damages=").append(f.getDamageCount());
    descr.append(
        " - bounds=[" + f.getX() + "," + f.getY() + "," + f.getWidth() + "," + f.getHeight() + "]");
    if (!f.isVisible()) {
      descr.append(" - INVISIBLE");
    }
    if (f.isFilled()) {
      descr.append(" - FILLED");
    }
    descr.append(
        " - fill=["
            + f.getFillColor().getRed()
            + ","
            + f.getFillColor().getGreen()
            + ","
            + f.getFillColor().getBlue()
            + "]");
    if (f.getOwner() != null) {
      descr.append(" - owner=").append(f.getOwner());
    }
    if (f instanceof FigText) {
      descr.append(" \"").append(((FigText) f).getText()).append("\"");
    }

    descr.append(" - lay=").append(toString(f.getLayer()));
    descr.append(" - grp=").append(toString(f.getGroup()));
    return descr.toString();
  }