Ejemplo n.º 1
0
 /**
  * Select the primitive if one of its virtual point is in the specified rectangular region (given
  * in logical coordinates).
  *
  * @param px the x coordinate of the top left point.
  * @param py the y coordinate of the top left point.
  * @param w the width of the region
  * @param h the height of the region
  * @return true if at least a primitive has been selected
  */
 public boolean selectRect(int px, int py, int w, int h) {
   // Here is a trick: if there is at least one active layer,
   // distancePrimitive will return a value less than the maximum.
   SelectionActions sa = new SelectionActions(macro);
   EditorActions edt = new EditorActions(macro, sa, null);
   if (edt.distancePrimitive(0, 0) < Integer.MAX_VALUE) {
     return super.selectRect(px, py, w, h);
   } else {
     return false;
   }
 }
Ejemplo n.º 2
0
  /**
   * Gets the distance (in primitive's coordinates space) between a given point and the primitive.
   * When it is reasonable, the behaviour can be binary (polygons, ovals...). In other cases (lines,
   * points), it can be proportional.
   *
   * @param px the x coordinate of the given point.
   * @param py the y coordinate of the given point.
   * @return the distance in logical units.
   */
  public int getDistanceToPoint(int px, int py) {
    /* in the macro primitive, the the first virtual point represents
    the position of the reference point of the macro to be drawn. */

    int x1 = virtualPoint[0].x;
    int y1 = virtualPoint[0].y;
    int dt = Integer.MAX_VALUE;

    // Here we check if the given point lies inside the text areas

    if (checkText(px, py)) return 0;

    // If not, we need to see more throughly about the inners of the macro

    int vx = px - x1 + 100;
    int vy = py - y1 + 100;

    // This is a sort of inelegant code: we need to translate the position
    // given in the macro's coordinate system.

    if (m) {
      switch (o) {
        case 1:
          vx = py - y1 + 100;
          vy = px - x1 + 100;
          break;

        case 2:
          vx = px - x1 + 100;
          vy = -(py - y1) + 100;
          break;

        case 3:
          vx = -(py - y1) + 100;
          vy = -(px - x1) + 100;
          break;

        case 0:
          vx = -(px - x1) + 100;
          vy = py - y1 + 100;
          break;

        default:
          vx = 0;
          vy = 0;
          break;
      }
    } else {
      switch (o) {
        case 1:
          vx = py - y1 + 100;
          vy = -(px - x1) + 100;
          break;

        case 2:
          vx = -(px - x1) + 100;
          vy = -(py - y1) + 100;
          break;

        case 3:
          vx = -(py - y1) + 100;
          vy = px - x1 + 100;
          break;

        case 0:
          vx = px - x1 + 100;
          vy = py - y1 + 100;
          break;

        default:
          vx = 0;
          vy = 0;
          break;
      }
    }

    if (macroDesc == null)
      System.out.println("1-Unrecognized macro " + "WARNING this can be a programming problem...");
    else {
      SelectionActions sa = new SelectionActions(macro);
      EditorActions edt = new EditorActions(macro, sa, null);
      return Math.min(edt.distancePrimitive(vx, vy), dt);
    }
    return Integer.MAX_VALUE;
  }