Example #1
0
  public Vector2D getScaleFactor(List<GElementFAState> states) {
    double minX, minY, maxX, maxY;
    double scaleX, scaleY;
    Iterator<GElementFAState> iterator = states.iterator();
    if (iterator.hasNext()) {
      GElementFAState node = iterator.next();
      minX = node.getPositionX();
      maxX = minX;
      minY = node.getPositionY();
      maxY = minY;
      while (iterator.hasNext()) {
        node = iterator.next();
        if (node.getPositionX() < minX) {
          minX = node.getPositionX();
        } else if (node.getPositionX() > maxX) {
          maxX = node.getPositionX();
        }

        if (node.getPositionY() < minY) {
          minY = node.getPositionY();
        } else if (node.getPositionY() > maxY) {
          maxY = node.getPositionY();
        }
      }
      this.top = (int) minY;
      this.left = (int) minX;
      this.right = (int) maxX;
      this.bottom = (int) maxY;
      scaleX = ((maxX - minX) / 13);
      scaleY = ((maxY - minY) / 10);
    } else {
      scaleX = 100;
      scaleY = 100;
    }
    return new Vector2D(scaleX, scaleY);
  }
Example #2
0
  /**
   * @param states - List of geometric nodes (GElementFAState) for all nodes in the FA
   * @param scale - Vector2D of X scale and Y scale factors
   * @return The string that contains all of the node declarations and positioning information
   */
  private String nodesToLatex(List<GElementFAState> states, Vector2D scale) {

    List<String> latexNodes = new LinkedList<String>();

    int i = 0;
    for (GElementFAState a : states) {
      String latexOneNode = "";

      String name = a.getState().name;
      String id = "q" + i;
      i += 1;

      FAState state = a.getState();

      latexOneNode += "\\node";

      if (state.isAccepted() && state.isStart()) {
        latexOneNode += " [state, initial, accepting]";
      } else if (state.isStart()) {
        latexOneNode += " [state, initial]";
      } else if (state.isAccepted()) {
        latexOneNode += " [state, accepting]";
      } else {
        latexOneNode += " [state]";
      }

      int x_pos = (int) ((a.getPositionX() - this.left) / scale.getX());
      int y_pos = (int) ((a.getPositionY() - this.top) / scale.getY());
      y_pos *= -1;
      latexOneNode += " (" + id + ")";
      latexOneNode += " at (" + x_pos + "," + y_pos + ")";
      latexOneNode += " {" + name + "};";

      latexNodes.add(latexOneNode);
    }

    String s = "";
    for (String a : latexNodes) s += a + "\n";
    return s;
  }