Example #1
0
  private ImageData writeImageTOBEMOVED(
      FileFormatOption fileFormatOption, OutputStream os, Animation affineTransforms)
      throws IOException {
    final LimitFinder limitFinder = new LimitFinder(TextBlockUtils.getDummyStringBounder(), true);
    udrawable.drawU(limitFinder);
    Dimension2D dim =
        new Dimension2DDouble(
            limitFinder.getMaxX() + 1 + margin1 + margin2,
            limitFinder.getMaxY() + 1 + margin1 + margin2);
    double dx = 0;
    double dy = 0;
    if (affineTransforms != null) {
      final MinMax minmax = affineTransformations.getMinMax(dim);
      affineTransforms.setDimension(dim);
      dim = minmax.getDimension();
      dx = -minmax.getMinX();
      dy = -minmax.getMinY();
    }

    final UGraphic2 ug = createUGraphic(fileFormatOption, dim, affineTransforms, dx, dy);
    udrawable.drawU(handwritten(ug.apply(new UTranslate(margin1, margin1))));
    ug.flushUg();
    ug.writeImageTOBEMOVED(os, metadata, 96);
    os.flush();

    if (ug instanceof UGraphicG2d) {
      final Set<Url> urls = ((UGraphicG2d) ug).getAllUrlsEncountered();
      if (urls.size() > 0) {
        final CMapData cmap = CMapData.cmapString(urls, dpiFactor);
        return new ImageDataComplex(dim, cmap, warningOrError);
      }
    }

    return new ImageDataSimple(dim);
  }
Example #2
0
 public MinMax getMinMax() {
   final MinMax result = new MinMax();
   for (CubicCurve2D.Double c : beziers) {
     result.manage(c.x1, c.y1);
     result.manage(c.x2, c.y2);
     result.manage(c.ctrlx1, c.ctrly1);
     result.manage(c.ctrlx2, c.ctrly2);
   }
   return result;
 }
 @Override
 public MinMax getRangeMinMax() {
   if (isstacked) {
     return new MinMax(0, getStackedMaxRange());
   } else {
     MinMax minmax = super.getRangeMinMax();
     if (minmax.min > 0) {
       minmax.min = 0;
     }
     return minmax;
   }
 }
Example #4
0
 private void addInternal(USegment segment) {
   segments.add(segment);
   final double coord[] = segment.getCoord();
   if (segment.getSegmentType() == USegmentType.SEG_ARCTO) {
     minmax = minmax.addPoint(coord[5], coord[6]);
     // minmax = minmax.addPoint(coord[5] + coord[0], coord[6] + coord[1]);
     // minmax = minmax.addPoint(coord[5] - coord[0], coord[6] - coord[1]);
   } else {
     for (int i = 0; i < coord.length; i += 2) {
       minmax = minmax.addPoint(coord[i], coord[i + 1]);
     }
   }
 }
Example #5
0
  public static MinMax getMinMax(double[] values) {
    MinMax res = new MinMax(values[0], 0, values[0], 0);
    for (int i = 1; i < values.length; i++) {
      if (res.min > values[i]) {
        res.min = values[i];
        res.iMin = i;
      }
      if (res.max < values[i]) {
        res.max = values[i];
        res.iMax = i;
      }
    }

    return res;
  }
Example #6
0
  /**
   * Makes this player's moves until the referee says the game is over or one of the players has
   * won.
   */
  public static void makeMoves() {
    Move move;
    while (true) {
      if (currentGameState.getTurn() == Player.MAX) {
        move =
            MinMax.getInstance()
                .getNextBestMove(currentGameState, timelimit, Heuristic.getInstance());
        Communicator.getInstance().sendCmd(Main.getMoveAsCommand(move));
        logger.log(Level.INFO, "Player " + playerNumber + " move: " + move.toString());
      } else {
        String command = Communicator.getInstance().getCmd();
        if (Main.gameIsOver(command)) {
          break;
        }

        String args[] = command.split(" ");
        int col = Integer.parseInt(args[0]);
        int moveType = Integer.parseInt(args[1]);

        move = new Move((moveType == 0) ? MoveType.POP : MoveType.DROP, col);
      }

      currentGameState.move(move);
    }
  }
  @Override
  public RoofHookPoint[] getRoofHookPoints(int pNumber, DormerRow dormerRow, int dormerRowNum) {
    Vector2d v = new Vector2d(this.v1);

    MinMax polygonMinMaxY = findMinMaxY(this.polygon);
    if (polygonMinMaxY == null) {
      // XXX
      polygonMinMaxY = new MinMax(0, 1d);
    }

    v.scale(1d / (pNumber + 1d));

    Point2d p = new Point2d(this.p1);

    RoofHookPoint[] ret = new RoofHookPoint[pNumber];
    for (int i = 0; i < pNumber; i++) {
      p.add(v);

      MinMax minMaxY = limitZToPolygon(p.x);

      double z = calcRowPosition(minMaxY, dormerRow, dormerRowNum);

      //            double z = minMaxY.getMin();

      double y = this.plane.calcYOfPlane(p.x, -z);

      Point3d pp = new Point3d(p.x, y, -z);

      double b = minMaxY.getMax() - z; // (minMaxY.getMax() - minMaxY.getMin()) - z;

      RoofHookPoint hook = new RoofHookPoint(pp, Math.toRadians(0), b, Math.toRadians(0));

      ret[i] = hook;
    }

    return ret;
  }
  /**
   * TODO: chunkNumericPK definition.
   *
   * @param table
   * @param columns
   * @param chunkSize
   * @throws ReplicatorException
   * @throws InterruptedException
   */
  private void chunkNumericPK(Table table, String[] columns, long chunkSize)
      throws ReplicatorException, InterruptedException {
    // Retrieve PK range
    MinMax minmax = retrieveMinMaxCountPK(connection, table);

    if (minmax != null) {
      if (logger.isDebugEnabled())
        logger.debug(
            "Min = "
                + minmax.getMin()
                + " -- Max = "
                + minmax.getMax()
                + " -- Count = "
                + minmax.getCount());

      if (minmax.getCount() <= chunkSize)
        // Get the whole table at once
        chunks.put(new NumericChunk(table, columns));
      else {
        // Share the joy among threads,
        // if primary key is evenly distributed
        if (!minmax.isDecimal()) {
          long gap = (Long) minmax.getMax() - (Long) minmax.getMin();
          long blockSize = chunkSize * gap / minmax.getCount();

          long nbBlocks = gap / blockSize;
          if (gap % blockSize > 0) nbBlocks++;

          long start = (Long) minmax.getMin() - 1;
          long end;
          do {
            end = start + blockSize;
            if (end > (Long) minmax.getMax()) end = (Long) minmax.getMax();
            NumericChunk e = new NumericChunk(table, start, end, columns, nbBlocks);
            chunks.put(e);
            start = end;
          } while (start < (Long) minmax.getMax());
        } else {
          BigInteger start =
              ((BigDecimal) minmax.getMin())
                  .setScale(0, RoundingMode.FLOOR)
                  .toBigInteger()
                  .subtract(BigInteger.valueOf(1));

          BigInteger max =
              ((BigDecimal) minmax.getMax()).setScale(0, RoundingMode.CEILING).toBigInteger();

          BigInteger gap = max.subtract(start);

          BigInteger blockSize =
              gap.multiply(BigInteger.valueOf(chunkSize))
                  .divide(BigInteger.valueOf(minmax.getCount()));

          long nbBlocks = gap.divide(blockSize).longValue();

          if (!gap.remainder(blockSize).equals(BigInteger.ZERO)) {
            nbBlocks++;
            blockSize =
                gap.divide(BigInteger.valueOf(nbBlocks))
                    .add(
                        gap.remainder(blockSize).equals(BigInteger.ZERO)
                            ? BigInteger.ZERO
                            : BigInteger.ONE);
          }
          BigInteger end;
          do {
            end = start.add(blockSize);
            if (end.compareTo(
                    (((BigDecimal) minmax.getMax()).setScale(0, RoundingMode.CEILING))
                        .toBigInteger())
                == 1)
              end =
                  (((BigDecimal) minmax.getMax()).setScale(0, RoundingMode.CEILING)).toBigInteger();

            NumericChunk e = new NumericChunk(table, start, end, columns, nbBlocks);
            chunks.put(e);
            start = end;
          } while (start.compareTo(
                  (((BigDecimal) minmax.getMax()).setScale(0, RoundingMode.CEILING)).toBigInteger())
              == -1);
        }
      }
    } else {
      // table is empty or does not have a
      // good candidate as a PK for chunking.
      // Fall back to limit method
      chunks.put(new NumericChunk(table, columns));
    }
  }
Example #9
0
public class UPath extends AbstractShadowable implements Iterable<USegment> {

  private final List<USegment> segments = new ArrayList<USegment>();
  private MinMax minmax = MinMax.getEmpty(false);

  private boolean isOpenIconic;

  public void add(double[] coord, USegmentType pathType) {
    addInternal(new USegment(coord, pathType));
  }

  private void addInternal(USegment segment) {
    segments.add(segment);
    final double coord[] = segment.getCoord();
    if (segment.getSegmentType() == USegmentType.SEG_ARCTO) {
      minmax = minmax.addPoint(coord[5], coord[6]);
      // minmax = minmax.addPoint(coord[5] + coord[0], coord[6] + coord[1]);
      // minmax = minmax.addPoint(coord[5] - coord[0], coord[6] - coord[1]);
    } else {
      for (int i = 0; i < coord.length; i += 2) {
        minmax = minmax.addPoint(coord[i], coord[i + 1]);
      }
    }
  }

  public UPath translate(double dx, double dy) {
    final UPath result = new UPath();
    for (USegment seg : segments) {
      result.addInternal(seg.translate(dx, dy));
    }
    return result;
  }

  public UPath rotate(double theta) {
    final UPath result = new UPath();
    for (USegment seg : segments) {
      result.addInternal(seg.rotate(theta));
    }
    return result;
  }

  public void moveTo(Point2D pt) {
    moveTo(pt.getX(), pt.getY());
  }

  public void lineTo(Point2D pt) {
    lineTo(pt.getX(), pt.getY());
  }

  public void moveTo(double x, double y) {
    add(new double[] {x, y}, USegmentType.SEG_MOVETO);
  }

  public void lineTo(double x, double y) {
    add(new double[] {x, y}, USegmentType.SEG_LINETO);
  }

  public void cubicTo(
      double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2) {
    add(new double[] {ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2}, USegmentType.SEG_CUBICTO);
  }

  public void quadTo(double ctrlx, double ctrly, double x2, double y2) {
    add(new double[] {ctrlx, ctrly, ctrlx, ctrly, x2, y2}, USegmentType.SEG_CUBICTO);
  }

  public void quadTo(Point2D ctrl, Point2D pt) {
    quadTo(ctrl.getX(), ctrl.getY(), pt.getX(), pt.getY());
  }

  public void arcTo(
      double rx,
      double ry,
      double x_axis_rotation,
      double large_arc_flag,
      double sweep_flag,
      double x,
      double y) {
    add(
        new double[] {rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y},
        USegmentType.SEG_ARCTO);
    // lineTo(x, y);
  }

  public void arcTo(Point2D pt, double radius, double large_arc_flag, double sweep_flag) {
    add(
        new double[] {radius, radius, 0, large_arc_flag, sweep_flag, pt.getX(), pt.getY()},
        USegmentType.SEG_ARCTO);
    // lineTo(x, y);
  }

  public void closePath() {
    // System.err.println("CLOSE_PATH");
  }

  public double getMaxX() {
    return minmax.getMaxX();
  }

  public double getMaxY() {
    return minmax.getMaxY();
  }

  public double getMinX() {
    return minmax.getMinX();
  }

  public double getMinY() {
    return minmax.getMinY();
  }

  @Override
  public String toString() {
    return segments.toString();
  }

  public Iterator<USegment> iterator() {
    return segments.iterator();
  }

  public boolean isOpenIconic() {
    return isOpenIconic;
  }

  public void setOpenIconic(boolean isOpenIconic) {
    this.isOpenIconic = isOpenIconic;
  }

  // public boolean isEmpty() {
  // return segments.size() == 0;
  // }

}
Example #10
0
 public double getMinY() {
   return minmax.getMinY();
 }
Example #11
0
 public double getMaxX() {
   return minmax.getMaxX();
 }
 private double calcRowPosition(MinMax minMaxY, DormerRow dormerRow, int dormerRowNum) {
   double row = (dormerRow.getRowNum() - 1) / (double) dormerRowNum;
   return minMaxY.getMin() + (minMaxY.getMax() - minMaxY.getMin()) * row;
 }