/** Convert array of polygon GeoPoints to an Area object */
  private Area getArea(GeoPoint[] points) {

    double[] coords = new double[2];
    GeneralPathClipped gp = new GeneralPathClipped(ev);

    // first point
    points[0].getInhomCoords(coords);
    gp.moveTo(coords[0], coords[1]);

    for (int i = 1; i < points.length; i++) {
      points[i].getInhomCoords(coords);
      gp.lineTo(coords[0], coords[1]);
    }
    gp.closePath();

    return new Area(gp);
  }
Beispiel #2
0
 /** Returns the bounding box of this Drawable in screen coordinates. */
 public final Rectangle getBounds() {
   if (!geo.isDefined() || !geo.isEuclidianVisible()) return null;
   else return gp.getBounds();
 }
Beispiel #3
0
  public final void update() {
    isVisible = geo.isEuclidianVisible();
    if (isVisible) {
      if (!geo.getDrawAlgorithm().equals(geo.getParentAlgorithm())) init();
      int slopeTriangleSize = slope.getSlopeTriangleSize();
      double rwHeight = slope.getValue() * slopeTriangleSize;
      double height = view.yscale * rwHeight;
      if (Math.abs(height) > Float.MAX_VALUE) {
        isVisible = false;
        return;
      }

      // get point on line g
      g.getInhomPointOnLine(coords);
      if (g.getStartPoint() == null) {
        // get point on y-axis and line g
        coords[0] = 0.0d;
        coords[1] = -g.z / g.y;
      }
      view.toScreenCoords(coords);

      // draw slope triangle
      double x = coords[0];
      double y = coords[1];
      double xright = x + view.xscale * slopeTriangleSize;
      if (gp == null) gp = new GeneralPathClipped(view);
      gp.reset();
      gp.moveTo(x, y);
      gp.lineTo(xright, y);
      gp.lineTo(xright, y - height);

      // gp on screen?
      if (!gp.intersects(0, 0, view.width, view.height)) {
        isVisible = false;
        // don't return here to make sure that getBounds() works for offscreen points too
      }

      // label position
      labelVisible = geo.isLabelVisible();
      if (labelVisible) {
        if (slopeTriangleSize > 1) {
          StringBuilder sb = new StringBuilder();
          switch (slope.getLabelMode()) {
            case GeoElement.LABEL_NAME_VALUE:
              sb.append(slopeTriangleSize);
              sb.append(' ');
              sb.append(geo.getLabel());
              sb.append(" = ");
              sb.append(kernel.format(rwHeight));
              break;

            case GeoElement.LABEL_VALUE:
              sb.append(kernel.format(rwHeight));
              break;

            default: // case GeoElement.LABEL_NAME:
              sb.append(slopeTriangleSize);
              sb.append(' ');
              sb.append(geo.getLabel());
              break;
          }
          labelDesc = sb.toString();
        } else {
          labelDesc = geo.getLabelDescription();
        }
        yLabel = (int) (y - height / 2.0f + 6);
        xLabel = (int) (xright) + 5;
        addLabelOffset();

        // position off horizontal label (i.e. slopeTriangleSize)
        xLabelHor = (int) ((x + xright) / 2.0);
        yLabelHor = (int) (y + view.fontSize + 2);
        StringBuilder sb = new StringBuilder();
        sb.append(slopeTriangleSize);
        horLabel = sb.toString();
      }
      updateStrokes(slope);
    }
  }
Beispiel #4
0
 public final boolean hit(int x, int y) {
   return gp != null && (gp.contains(x, y) || gp.intersects(x - 3, y - 3, 6, 6));
 }