/** This scales all the x values to be between 0 and 1. */
  private void scaleByMax() {
    // ammendment to what i may have commented before
    // this takes the lowest x and highest x  and uses that as the scaling
    // factor
    double l_x = 5000, h_x = -5000;
    for (int noa = 0; noa < m_groupNum; noa++) {
      if (l_x > m_groups[noa].m_left) {
        l_x = m_groups[noa].m_left;
      }

      if (h_x < m_groups[noa].m_right) {
        h_x = m_groups[noa].m_right;
      }
    }

    Edge e;
    Node r, s;
    double m_scale = h_x - l_x + 1;
    if (m_groupNum > 0) {
      r = m_groups[0].m_p;
      r.setCenter((r.getCenter() - l_x) / m_scale);
      // System.out.println("from scaler " + l_x + " " + m_scale);
      for (int noa = 0; noa < m_groupNum; noa++) {
        r = m_groups[noa].m_p;
        for (int nob = 0; (e = r.getChild(nob)) != null; nob++) {
          s = e.getTarget();
          if (s.getParent(0) == e) {
            s.setCenter((s.getCenter() - l_x) / m_scale);
          }
        }
      }
    }
  }
  /**
   * This scales the x values to between 0 and 1 for each individual line rather than doing them all
   * at once.
   */
  private void scaleByInd() {
    // ammendment to what i may have commented before
    // this takes the lowest x and highest x  on each line and uses that for
    // the line in question
    double l_x, h_x;

    Edge e;
    Node r, s;
    r = m_groups[0].m_p;
    r.setCenter(.5);
    double m_scale;
    for (int noa = 0; noa < m_levelNum; noa++) {
      l_x = m_groups[m_levels[noa].m_start].m_left;
      h_x = m_groups[m_levels[noa].m_end].m_right;
      m_scale = h_x - l_x + 1;
      for (int nob = m_levels[noa].m_start; nob <= m_levels[noa].m_end; nob++) {
        r = m_groups[nob].m_p;
        for (int noc = 0; (e = r.getChild(noc)) != null; noc++) {
          s = e.getTarget();
          if (s.getParent(0) == e) {
            s.setCenter((s.getCenter() - l_x) / m_scale);
          }
        }
      }
    }
  }
  /**
   * This will set initial places for the x coord of the nodes.
   *
   * @param start The `number for the first group to start on (I think).
   */
  private void xPlacer(int start) {
    // this can be one of a few x_placers (the first)
    // it will work by placing 1 space inbetween each node
    // ie the first at 0 the second at 1 and so on
    // then it will add to this value the place of the parent
    // node - half of the size
    // i will break this up into several functions
    // first the gap setter;
    // then the shifter
    // it will require a vector shift function added to the node class
    // i will write an additional shifter for the untangler
    // for its particular situation

    Node r;
    Edge e;
    if (m_groupNum > 0) {
      m_groups[0].m_p.setCenter(0);
      for (int noa = start; noa < m_groupNum; noa++) {
        int nob, alter = 0;
        double c = m_groups[noa].m_gap;
        r = m_groups[noa].m_p;
        for (nob = 0; (e = r.getChild(nob)) != null; nob++) {
          if (e.getTarget().getParent(0) == e) {
            e.getTarget().setCenter(nob * c);
          } else {
            alter++;
          }
        }
        m_groups[noa].m_size = (nob - 1 - alter) * c;
        xShift(noa);
      }
    }
  }
 /**
  * This will set all of the children node of a particular node to their height.
  *
  * @param r The parent node of the children to set their height.
  */
 private void nodeY(Node r) {
   Edge e;
   double h = r.getTop() + m_yRatio;
   for (int noa = 0; (e = r.getChild(noa)) != null; noa++) {
     if (e.getTarget().getParent(0) == e) {
       e.getTarget().setTop(h);
       if (!e.getTarget().getVisible()) {
         // System.out.println("oh bugger");
       }
     }
   }
 }
  /**
   * This will untangle the nodes in the tree so that they fall on the correct side of each other.
   */
  private void untangle() {
    Ease a;
    Edge e;
    Node r, nf = null, ns = null, mark;
    int l = 0, times = 0;
    int f, s, tf = 0, ts = 0, pf, ps;
    while ((a = overlap(l)) != null) {
      times++;
      // System.out.println(group_num);
      f = a.m_place;
      s = a.m_place + 1;
      while (f != s) {
        a.m_lev--;
        tf = f;
        ts = s;
        f = m_groups[f].m_pg;
        s = m_groups[s].m_pg;
      }
      l = a.m_lev;
      pf = 0;
      ps = 0;
      r = m_groups[f].m_p;
      mark = m_groups[tf].m_p;
      nf = null;
      ns = null;
      for (int noa = 0; nf != mark; noa++) {
        pf++;
        nf = r.getChild(noa).getTarget();
      }
      mark = m_groups[ts].m_p;
      for (int noa = pf; ns != mark; noa++) {
        ps++; // the number of gaps between the two nodes
        ns = r.getChild(noa).getTarget();
      }
      m_groups[f].m_gap = Math.ceil((a.m_amount / (double) ps) + m_groups[f].m_gap);

      xPlacer(f);
    }
  }
示例#6
0
 public void add(String str) {
   Node n = root, t;
   char arr[] = str.toCharArray();
   for (int i = 0; i < arr.length; i++) {
     t = n.getChild(arr[i]);
     if (t == null) {
       t = n.addChild(arr[i]);
       if (i == arr.length - 1) {
         t.value = str;
       }
     }
     n = t;
   }
 }
  /**
   * This will shift a group of nodes to be aligned under their parent.
   *
   * @param n The group number to shift
   */
  private void xShift(int n) {
    Edge e;
    Node r = m_groups[n].m_p;
    double h = m_groups[n].m_size / 2;
    double c = m_groups[n].m_p.getCenter();
    double m = c - h;
    m_groups[n].m_left = m;
    m_groups[n].m_right = c + h;

    for (int noa = 0; (e = r.getChild(noa)) != null; noa++) {
      if (e.getTarget().getParent(0) == e) {
        e.getTarget().adjustCenter(m);
      }
    }
  }
 /**
  * This will recursively shift a sub there to be centered about a particular value.
  *
  * @param n The first group in the sub tree.
  * @param o The point to start shifting the subtree.
  */
 private void moveSubtree(int n, double o) {
   Edge e;
   Node r = m_groups[n].m_p;
   for (int noa = 0; (e = r.getChild(noa)) != null; noa++) {
     if (e.getTarget().getParent(0) == e) {
       e.getTarget().adjustCenter(o);
     }
   }
   m_groups[n].m_left += o;
   m_groups[n].m_right += o;
   if (m_groups[n].m_start != -1) {
     for (int noa = m_groups[n].m_start; noa <= m_groups[n].m_end; noa++) {
       moveSubtree(noa, o);
     }
   }
 }
  // Methods
  public void dehoist() {
    // Shorthand
    JoeTree tree = hoistedNode.getTree();
    tree.setRootNodeCommentState(oldTreeCommentState);

    hoistedNode.setHoisted(false);

    // Prune things
    tree.setRootNode(oldNodeSet);
    tree.getVisibleNodes().clear();
    hoistedNodeParent.insertChild(hoistedNode, hoistedNodeIndex);
    hoistedNode.setDepthRecursively(hoistedNodeDepth);
    for (int i = 0; i < oldNodeSet.numOfChildren(); i++) {
      Node node = oldNodeSet.getChild(i);
      tree.insertNode(node);
    }

    return;
  }
 /**
  * This is called to build the rest of the grouping information.
  *
  * @param r The parent of the group.
  * @param pg The number for the parents group.
  */
 private void groupFind(Node r, int pg) {
   Edge e;
   boolean first = true;
   for (int noa = 0; (e = r.getChild(noa)) != null; noa++) {
     if (e.getTarget().getParent(0) == e) {
       if (e.getTarget().getChild(0) != null && e.getTarget().getCVisible()) {
         if (first) {
           m_groups[pg].m_start = m_groupNum;
           first = false;
         }
         m_groups[pg].m_end = m_groupNum;
         m_groups[m_groupNum].m_p = e.getTarget();
         m_groups[m_groupNum].m_pg = pg;
         m_groups[m_groupNum].m_id = m_groupNum; // just in case I ever need
         // this info
         m_groupNum++;
       }
     }
   }
 }
  public void hoist() {

    // Shorthand
    JoeTree tree = hoistedNode.getTree();
    tree.setRootNodeCommentState(newTreeCommentState);

    hoistedNode.setHoisted(true);

    // Prune things
    hoistedNode.getParent().removeChild(hoistedNode);
    hoistedNode.setDepthRecursively(-1);
    tree.setRootNode(hoistedNode);
    tree.getVisibleNodes().clear();
    for (int i = 0; i < hoistedNode.numOfChildren(); i++) {
      Node node = hoistedNode.getChild(i);
      tree.insertNode(node);
    }

    return;
  }
示例#12
0
  /** Computes this Spatial's world bounding volume in the most efficient manner possible. */
  void checkDoBoundUpdate() {
    if ((refreshFlags & RF_BOUND) == 0) {
      return;
    }

    checkDoTransformUpdate();

    // Go to children recursively and update their bound
    if (this instanceof Node) {
      Node node = (Node) this;
      int len = node.getQuantity();
      for (int i = 0; i < len; i++) {
        Spatial child = node.getChild(i);
        child.checkDoBoundUpdate();
      }
    }

    // All children's bounds have been updated. Update my own now.
    updateWorldBound();
  }
  /**
   * This untangles the nodes so that they will will fall on the correct side of the other nodes
   * along their row.
   */
  private void untangle2() {
    Ease a;
    Edge e;
    Node r, nf = null, ns = null, mark;
    int l = 0, times = 0;
    int f, s, tf = 0, ts = 0, pf, ps;
    while ((a = overlap(l)) != null) {
      times++;
      // System.out.println("from untang 2 " + group_num);
      f = a.m_place;
      s = a.m_place + 1;
      while (f != s) {
        a.m_lev--;
        tf = f;
        ts = s;
        f = m_groups[f].m_pg;
        s = m_groups[s].m_pg;
      }
      l = a.m_lev;
      pf = 0;
      ps = 0;
      r = m_groups[f].m_p;
      mark = m_groups[tf].m_p;
      nf = null;
      ns = null;
      for (int noa = 0; nf != mark; noa++) {
        pf++;
        nf = r.getChild(noa).getTarget();
      }
      mark = m_groups[ts].m_p;
      for (int noa = pf; ns != mark; noa++) {
        ps++; // the number of gaps between the two nodes
        ns = r.getChild(noa).getTarget();
      }
      // m_groups[f].gap =
      //              Math.ceil((a.amount / (double)ps) + m_groups[f].gap);
      // note for this method i do not need the group gap ,but i will leave
      // it for the other methods;
      Vector o_pos = new Vector(20, 10);
      for (int noa = 0; (e = r.getChild(noa)) != null; noa++) {
        if (e.getTarget().getParent(0) == e) {
          Double tem = new Double(e.getTarget().getCenter());
          o_pos.addElement(tem);
        }
      }

      pf--;
      double inc = a.m_amount / (double) ps;
      for (int noa = 0; (e = r.getChild(noa)) != null; noa++) {
        ns = e.getTarget();
        if (ns.getParent(0) == e) {
          if (noa > pf + ps) {
            ns.adjustCenter(a.m_amount);
          } else if (noa > pf) {
            ns.adjustCenter(inc * (double) (noa - pf));
          }
        }
      }

      nf = r.getChild(0).getTarget();
      inc = ns.getCenter() - nf.getCenter();
      m_groups[f].m_size = inc;
      m_groups[f].m_left = r.getCenter() - inc / 2;
      m_groups[f].m_right = m_groups[f].m_left + inc;
      inc = m_groups[f].m_left - nf.getCenter();

      double shift;
      int g_num = 0;
      for (int noa = 0; (e = r.getChild(noa)) != null; noa++) {
        ns = e.getTarget();
        if (ns.getParent(0) == e) {
          ns.adjustCenter(inc);
          shift = ns.getCenter() - ((Double) o_pos.elementAt(noa)).doubleValue();
          if (ns.getChild(0) != null) {
            moveSubtree(m_groups[f].m_start + g_num, shift);
            g_num++;
          }
        }
        // ns.adjustCenter(-shift);
      }
      // zero_offset(r);

      // x_placer(f);
    }
  }