Package geom

Examples of geom.Position


    g.setColor(Color.BLACK);
    g.fillRect(0, 0, getWidth(), getHeight());
    Font font = new Font("Times New Roman", Font.PLAIN, 32);
    g.setFont(font);
    for (Box.Pair p : pairs) {
      Position q = new Position((p.position.x-minX)*scaleX, (p.position.y-minY)*scaleY);
      Argument a = p.argument;
      int depth = a!=null ? a.getDepth()+2 : 1;
      Color c = ColourScheme.BLACKBOARD.getArgColour(depth);
      g.setColor(c);
      g.drawOval((int)q.x-depth, (int)q.y-depth, 2*depth+1, 2*depth+1);
 
View Full Code Here


    // Note: this retains width but word wrap extends its depth.
    equationRectangle = box.getOuterRectangle();

    double panelHeightOfNextBox = getPanelHeightOfNextBox(height, panelRectangle.height, boxIndex, equationRectangle);

    Position actualEquationTopLeft = new Position(KetPanel.LEFT_BORDER_SIZE, panelHeightOfNextBox);

    if (height<=panelRectangle.height) {
      BoxEquation boxEquation = new BoxEquation(box, labelBox, actualEquationTopLeft);
      set.add(boxEquation);
      return equationRectangle.height;
View Full Code Here

      // Find the centre of the equation's box
      for (Box b : boxToEquation.keySet()) {
        if (boxToEquation.get(b)!=e) continue;
        Offset inner = b.getInnerRectangle();
        if (inner==null) continue;
        Position q = p.minus(inner.getCentre());
        equationToPosition.put(e, q);
        return;
      }
    }
    equationToPosition.put(e, p);
View Full Code Here

    double cx = KetPanel.LEFT_BORDER_SIZE;
    double cy = KetPanel.TOP_BORDER_SIZE;
    for (Box b : boxSet) { // Move boxes away from edges.
      Equation e = boxToEquation.get(b);
      if (e==null) continue;
      Position p = equationToPosition.get(e);
      if (p==null) continue;
      Offset inner = b.getInnerRectangle();
      double mx = panelRectangle.width-KetPanel.LEFT_BORDER_SIZE-KetPanel.RIGHT_BORDER_SIZE - inner.width;
      double my = panelRectangle.height-KetPanel.TOP_BORDER_SIZE-KetPanel.BOTTOM_BORDER_SIZE - inner.height - panelDecoration.getModeBoxHeight();
      //- p.x = bound(p.x, KetPanel.LEFT_BORDER_SIZE, mx);
      if (p.x<KetPanel.LEFT_BORDER_SIZE) {
        return true;
      } else if (p.x>mx) {
        return true;
      }
      //- p.y = bound(p.y, KetPanel.TOP_BORDER_SIZE, my);
      if (p.y<KetPanel.TOP_BORDER_SIZE) {
        return true;
      } else if (p.y>my) {
        return true;
      }
    }

    Vector<Box> bs = new Vector<Box>(boxSet);
    for (int i=0; i<bs.size(); i++) { // Move boxses apart.
      Box bA = bs.get(i);
      Equation eA = boxToEquation.get(bA);
      if (eA==null) continue;
      Position pA = equationToPosition.get(eA);
      if (pA==null) continue;
      Offset innerA = bA.getInnerRectangle();
      for (int j=i+1; j<bs.size(); j++) { // Move boxses apart.
        Box bB = bs.get(j);
        Equation eB = boxToEquation.get(bB);
        if (eB==null) continue;
        Position pB = equationToPosition.get(eB);
        if (pB==null) continue;
        Offset innerB = bB.getInnerRectangle();

        Position rA = bA.getPosition(pA);
        Position rB = bB.getPosition(pB);
        Offset iA = bA.getInnerRectangle();
        Offset iB = bB.getInnerRectangle();

        // Positive overlap values are errors.
        boolean overlap1 = rB.x + iB.width + ADDITIONAL_EQUATION_GAP > rA.x;
View Full Code Here

    double x0 = KetPanel.LEFT_BORDER_SIZE;
    double y0 = KetPanel.TOP_BORDER_SIZE;
    // BUG? Why isn't RIGHT_BORDER_SIZE and BOTTOM_BORDER_SIZE not used here:
    double dx = panelRectangle.width - KetPanel.LEFT_BORDER_SIZE - KetPanel.RIGHT_BORDER_SIZE;
    double dy = panelRectangle.height - KetPanel.TOP_BORDER_SIZE - KetPanel.BOTTOM_BORDER_SIZE - panelDecoration.getModeBoxHeight();
    Position centre = new Position(x0+dx/2.0, y0+dy/2.0);
    EquationList el = getMathCollection().getSelection().getEquationList();
    Vector<Map.Entry<Box,Equation>> es = getEs();
    if (es==null) return;
    Vector<Position> ends = calcEnds(es, el);
    Vector<Box> theBoxes = new Vector<Box>();
    Vector<Equation> theEquations = new Vector<Equation>();
    Vector<Position> thePositions = new Vector<Position>();
    for (Map.Entry<Box,Equation> entry : es) {
      Box box = entry.getKey();
      Equation e = entry.getValue();
      if (e==null) {
        System.out.print("null");
        boxToEquation.remove(box);
        continue;
      }
      if (e.getEquationList()!=el) {
        System.out.print("e");
        boxToEquation.remove(box);
        continue;
      }
      Position p = equationToPosition.get(e);
      if (p==null) {
        System.out.print("p");
        boxToEquation.remove(box);
        continue;
      }
      theBoxes.add(box);
      theEquations.add(e);
      thePositions.add(p);
    }
    for (int loop=0; loop<n; loop++) {
      Vector<Position> allPs = new Vector<Position>();
      Vector<Position> allQs = new Vector<Position>();
      for (int i=0; i<theBoxes.size(); i++) {
        Box box = theBoxes.get(i);
        Equation e = theEquations.get(i);
        Position p = thePositions.get(i);
        Offset inner = box.getInnerRectangle();
        Position q = shift(p, scale);
        double costQ = calcCost(q, centre, ends, dx, dy, inner);
        double costP = calcCost(p, centre, ends, dx, dy, inner);
        if (costQ <= costP) {
          allPs.add(p);
          allQs.add(q);
        }
      }
      for (int i=0; i<allPs.size(); i++) {
        Position p = allPs.get(i);
        Position q = allQs.get(i);
        p.x = (1.0*q.x+2.0*p.x) / 3.0;
        p.y = (1.0*q.y+2.0*p.y) / 3.0;
      }
    }

    if (true) { //D
    for (Map.Entry<Box,Equation> entry : es) {
      Box box = entry.getKey();
      Equation e = entry.getValue();
      if (e==null) continue;
      Position p = equationToPosition.get(e);
      if (p==null) continue;
      Vector<Position> ps = e2ps.get(e);
      if (ps==null) {
        ps = new Vector<Position>();
        e2ps.put(e, ps);
      }
      ps.add(new Position(p));
      if (ps.size()>HISTORY) {
        ps.removeElementAt(0);
      }

      //D System.out.println(e.getEquationIndex() + "\t" + p.x + "\t" + p.y); //D
View Full Code Here

    for (Map.Entry<Box,Equation> entry : es) {
      Box box = entry.getKey();
      Equation e = entry.getValue();
      if (e==null) continue;
      if (e.getEquationList()!=el) continue;
      Position p = equationToPosition.get(e);
      if (p==null) continue;
      Offset inner = box.getInnerRectangle();
      ends.add(new Position(p.x + inner.width/2.0, p.y + inner.height/2.0));
    }
    return ends;
  }
View Full Code Here

  }

  public Position shift(Position p, double scale) {
    double deltaX = scale * (Math.random()-0.5);
    double deltaY = scale * (Math.random()-0.5);
    return new Position(p.x+deltaX, p.y+deltaY);
  }
View Full Code Here

    double deltaY = scale * (Math.random()-0.5);
    return new Position(p.x+deltaX, p.y+deltaY);
  }

  public double calcCost(Position p, Position centre, Vector<Position> ends, double dx, double dy, Offset inner) {
    Position pMid = new Position(p.x+inner.width/2.0, p.y+inner.height/2.0);
    double costP = sq(Position.length(centre, pMid)) / 100000.0;
    double fpX = (p.x-KetPanel.LEFT_BORDER_SIZE)/(dx-inner.width - KetPanel.LEFT_BORDER_SIZE - KetPanel.RIGHT_BORDER_SIZE);
    double fpY = (p.y-KetPanel.TOP_BORDER_SIZE)/(dy-inner.height - KetPanel.TOP_BORDER_SIZE - KetPanel.BOTTOM_BORDER_SIZE);
    if (fpX<0.0 || fpX>1.0) costP += 1.0e4 * sq(Math.abs(fpX-0.5));
    if (fpY<0.0 || fpY>1.0) costP += 1.0e4 * sq(Math.abs(fpY-0.5));
 
View Full Code Here

      Offset equationRectangle = box.getInnerRectangle();
      box.setupOuterRectangle(equationRectangle);
      set.add(box);
      if (box==null) continue;
      if (!equationToPosition.containsKey(equation)) {
        Position p = suitableVoid(box, boxIndex, panelRectangle, set);
        equationToPosition.put(equation,  p);
      }
      boxToEquation.put(box, equation);
    }
    return Collections.unmodifiableSet(set);
View Full Code Here

    //- double cy = KetPanel.TOP_BORDER_SIZE + inner.height;
    double cy = KetPanel.TOP_BORDER_SIZE;
    double my = panelRectangle.height-KetPanel.TOP_BORDER_SIZE-KetPanel.BOTTOM_BORDER_SIZE-inner.height - panelDecoration.getModeBoxHeight();
    //! double dy = panelRectangle.height - KetPanel.TOP_BORDER_SIZE - KetPanel.BOTTOM_BORDER_SIZE - panelDecoration.getModeBoxHeight();
    if (set==null) {
      return new Position(mx/2.0+cx, my/2.0+cy); // fail
    }
    Vector<Box> oldAndNewBoxes = new Vector<Box>();
    if (boxSet!=null) {
      oldAndNewBoxes.addAll(boxSet);
    }
    oldAndNewBoxes.addAll(set);
    double bestDistance = 0.0;
    Position bestPosition = new Position(Math.random()*mx+cx, Math.random()*my+cy);
    Equation equation = boxToEquation.get(box);
    Position topLeft = equationToPosition.get(equation);
    for (int i=0; i<20; i++) { // Filter for non-overlapping locations, returning the one furthest from existing boxes.
      Position p = new Position(Math.random()*mx+cx, Math.random()*my+cy);
      boolean outside = true;
      // For the given position and box, find the nearest existing box.
      double distance = 0.0;
      for (Box b : oldAndNewBoxes) {
        if (b==box) continue;
        if (b.innerBoxesOverlap(box)) {
          outside = false;
          break;
        }
        Equation e = boxToEquation.get(b);
        Position tl = equationToPosition.get(e);
        double d = Position.length(box.getCentre(topLeft), b.getCentre(tl));
        distance = Math.min(distance, d);
      }
      if (outside && distance > bestDistance) {
        bestDistance = distance;
View Full Code Here

TOP

Related Classes of geom.Position

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.