コード例 #1
1
ファイル: GameProcess.java プロジェクト: koreain/bingo
 static void rand() // 중복되지 않는 랜덤 숫자배열 두개 만들기
     {
   int su = 0; // 난수 발생시 저장할 변수
   boolean bDash = false; // 중복여부 확인
   for (int i = 0; i < 75; i++) {
     bDash = true;
     while (bDash) // 난수발생, 중복 학인
     {
       su = (int) (Math.random() * 75) + 1; // 판 크기+10개(상대가 못맞출 수도 있게)의 난수 입력
       bDash = false;
       for (int j = 0; j < i; j++) {
         if (numArr1[j] == su) {
           bDash = true; // 중복이 있으면 멈추고 while문을 다시 수행(랜덤값을 다시 줌)
           break;
         }
       }
     }
     numArr1[i] = su;
   }
   for (int i = 0; i < 75; i++) {
     bDash = true;
     while (bDash) // 난수발생, 중복 학인
     {
       su = (int) (Math.random() * 75) + 1; // 판 크기+10개(상대가 못맞출 수도 있게)의 난수 입력
       bDash = false;
       for (int j = 0; j < i; j++) {
         if (numArr2[j] == su) {
           bDash = true; // 중복이 있으면 멈추고 while문을 다시 수행(랜덤값을 다시 줌)
           break;
         }
       }
     }
     numArr2[i] = su;
   }
 }
コード例 #2
1
    private void adjustDateLineCrossingPoints() {
      ArrayList<LatLon> corners = new ArrayList<LatLon>(Arrays.asList(sw, se, nw, ne));
      if (!LatLon.locationsCrossDateLine(corners)) return;

      double lonSign = 0;
      for (LatLon corner : corners) {
        if (Math.abs(corner.getLongitude().degrees) != 180)
          lonSign = Math.signum(corner.getLongitude().degrees);
      }

      if (lonSign == 0) return;

      if (Math.abs(sw.getLongitude().degrees) == 180
          && Math.signum(sw.getLongitude().degrees) != lonSign)
        sw = new Position(sw.getLatitude(), sw.getLongitude().multiply(-1), sw.getElevation());
      if (Math.abs(se.getLongitude().degrees) == 180
          && Math.signum(se.getLongitude().degrees) != lonSign)
        se = new Position(se.getLatitude(), se.getLongitude().multiply(-1), se.getElevation());
      if (Math.abs(nw.getLongitude().degrees) == 180
          && Math.signum(nw.getLongitude().degrees) != lonSign)
        nw = new Position(nw.getLatitude(), nw.getLongitude().multiply(-1), nw.getElevation());
      if (Math.abs(ne.getLongitude().degrees) == 180
          && Math.signum(ne.getLongitude().degrees) != lonSign)
        ne = new Position(ne.getLatitude(), ne.getLongitude().multiply(-1), ne.getElevation());
    }
コード例 #3
0
  /**
   * Compute the bounds of the text, if necessary.
   *
   * @param dc the current DrawContext.
   */
  protected void computeBoundsIfNeeded(DrawContext dc) {
    // Do not compute bounds if they are available. Computing text bounds is expensive, so only do
    // this
    // calculation if necessary.
    if (this.bounds != null) return;

    TextRenderer textRenderer =
        OGLTextRenderer.getOrCreateTextRenderer(dc.getTextRendererCache(), this.getFont());

    int width = 0;
    int maxLineHeight = 0;
    this.lineBounds = new Rectangle2D[this.lines.length];

    for (int i = 0; i < this.lines.length; i++) {
      Rectangle2D lineBounds = textRenderer.getBounds(lines[i]);
      width = (int) Math.max(lineBounds.getWidth(), width);

      double thisLineHeight = Math.abs(lineBounds.getY());
      maxLineHeight = (int) Math.max(thisLineHeight, maxLineHeight);

      this.lineBounds[i] = lineBounds;
    }
    this.lineHeight = maxLineHeight;

    // Compute final height using maxLineHeight and number of lines
    this.bounds =
        new Rectangle(
            this.lines.length,
            maxLineHeight,
            width,
            this.lines.length * maxLineHeight + this.lines.length * this.lineSpacing);
  }
コード例 #4
0
  public void paint(Graphics g) {
    level = level_in;
    left_width_factor = (float) Math.pow(2.0, -1 / left_alpha);
    right_width_factor = (float) Math.pow(2.0, -1 / right_alpha);
    left_height_factor = (float) Math.pow(2.0, -2 / (3 * left_alpha));
    right_height_factor = (float) Math.pow(2.0, -2 / (3 * right_alpha));

    x = (float) 600 / 2.0f;
    y = (float) 500 / 10.0f;

    x1 = x;
    y01 = y + height;

    drawbranch(g, width, (int) x, 500 - (int) y, (int) x1, 500 - (int) y01);
    turtle_r = height;
    turtle_theta = point(x, y, x1, y01);
    turtle_x = x;
    turtle_y = y;
    turn(left_angle);
    generate(g, x1, y01, left_width_factor * width, left_height_factor * height, left_angle, level);
    turtle_theta = point(x, y, x1, y01);
    turn(-right_angle);
    generate(g, x1, y01, width, left_height_factor * height, right_angle, level);
    g.drawString("Fractal.java", 10, 10);
  }
コード例 #5
0
ファイル: IdeaTitledBorder.java プロジェクト: ernestp/consulo
 public void acceptMinimumSize(Component c) {
   Dimension minimumSize = getMinimumSize(c);
   c.setMinimumSize(
       new Dimension(
           Math.max(minimumSize.width, c.getMinimumSize().width),
           Math.max(minimumSize.height, c.getMinimumSize().height)));
 }
コード例 #6
0
 /** Frees memory by deleting a few slices from the end of the stack. */
 public void trim() {
   int n = (int) Math.round(Math.log(nSlices) + 1.0);
   for (int i = 0; i < n; i++) {
     deleteLastSlice();
     System.gc();
   }
 }
コード例 #7
0
  @Override
  public void showFeedback() {
    createFeedback();

    myBounds =
        myContext.getTransformedRectangle(
            myComponent.getBounds(myContext.getArea().getFeedbackLayer()));
    myBounds.width = Math.max(myBounds.width, 0);
    myBounds.height = Math.max(myBounds.height, 0);

    int direction = myContext.getResizeDirection();

    if ((direction & Position.EAST) != 0) {
      if (!snapToWidth(myBounds, myWrapSize, SNAP_DELTA)) {
        snapToWidth(myBounds, myFillSize, SNAP_DELTA);
      }
    }
    if ((direction & Position.SOUTH) != 0) {
      if (!snapToHeight(myBounds, myWrapSize, SNAP_DELTA)) {
        snapToHeight(myBounds, myFillSize, SNAP_DELTA);
      }
    }

    myFeedback.setBounds(myBounds);

    myTextFeedback.clear();

    addTextSize(myStaticWidth, myBounds.width, myWrapSize.width, myFillSize.width);
    myTextFeedback.append(" x ", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
    addTextSize(myStaticHeight, myBounds.height, myWrapSize.height, myFillSize.height);

    myTextFeedback.locationTo(myContext.getLocation(), 15);
  }
コード例 #8
0
ファイル: Site.java プロジェクト: pjmichalski/SpringSaLaD
 // Give the string and horizontal and verical offsets so that the label is
 // drawn in the center.
 public void drawLabel(Graphics g, String label, int hoffset, int voffset) {
   g.setColor(Color.black);
   int pixelsPerNm = DrawPanel.PIXELS_PER_NM;
   int xint = (int) Math.round(pixelsPerNm * z);
   int yint = (int) Math.round(pixelsPerNm * y);
   g.drawString(label, xint - hoffset, yint + voffset);
 }
コード例 #9
0
 /**
  * returns random 1 or -1
  *
  * @return random 1 or -1
  */
 private int generateRandomSign() {
   if (Math.round((Math.random() * 2)) == 1) {
     return 1;
   } else {
     return -1;
   }
 }
コード例 #10
0
 private int wrapPositionForTabbedTextWithOptimization(
     @NotNull CharSequence text,
     int tabSize,
     int startLineOffset,
     int endLineOffset,
     int targetRangeEndOffset) {
   int width = 0;
   int symbolWidth;
   int result = Integer.MAX_VALUE;
   boolean wrapLine = false;
   for (int i = startLineOffset; i < Math.min(endLineOffset, targetRangeEndOffset); i++) {
     char c = text.charAt(i);
     switch (c) {
       case '\t':
         symbolWidth = tabSize - (width % tabSize);
         break;
       default:
         symbolWidth = 1;
     }
     if (width + symbolWidth + FormatConstants.RESERVED_LINE_WRAP_WIDTH_IN_COLUMNS
             >= mySettings.RIGHT_MARGIN
         && (Math.min(endLineOffset, targetRangeEndOffset) - i)
             >= FormatConstants.RESERVED_LINE_WRAP_WIDTH_IN_COLUMNS) {
       // Remember preferred position.
       result = i - 1;
     }
     if (width + symbolWidth >= mySettings.RIGHT_MARGIN) {
       wrapLine = true;
       break;
     }
     width += symbolWidth;
   }
   return wrapLine ? result : -1;
 }
コード例 #11
0
 @Override
 public Dimension getPreferredSize() {
   Dimension windowSize = DiffUtil.getDefaultDiffWindowSize();
   Dimension size = super.getPreferredSize();
   return new Dimension(
       Math.max(windowSize.width, size.width), Math.max(windowSize.height, size.height));
 }
コード例 #12
0
ファイル: AquaCaret.java プロジェクト: FauxFaux/jdk9-jdk
  /**
   * Damages the area surrounding the caret to cause it to be repainted in a new location. If
   * paint() is reimplemented, this method should also be reimplemented. This method should update
   * the caret bounds (x, y, width, and height).
   *
   * @param r the current location of the caret
   * @see #paint
   */
  @Override
  protected synchronized void damage(final Rectangle r) {
    if (r == null || fPainting) return;

    x = r.x - 4;
    y = r.y;
    width = 10;
    height = r.height;

    // Don't damage the border area.  We can't paint a partial border, so get the
    // intersection of the caret rectangle and the component less the border, if any.
    final Rectangle caretRect = new Rectangle(x, y, width, height);
    final Border border = getComponent().getBorder();
    if (border != null) {
      final Rectangle alloc = getComponent().getBounds();
      alloc.x = alloc.y = 0;
      final Insets borderInsets = border.getBorderInsets(getComponent());
      alloc.x += borderInsets.left;
      alloc.y += borderInsets.top;
      alloc.width -= borderInsets.left + borderInsets.right;
      alloc.height -= borderInsets.top + borderInsets.bottom;
      Rectangle2D.intersect(caretRect, alloc, caretRect);
    }
    x = caretRect.x;
    y = caretRect.y;
    width = Math.max(caretRect.width, 1);
    height = Math.max(caretRect.height, 1);
    repaint();
  }
コード例 #13
0
 public void update(double prob_slowdown, double prob_create) {
   int i = 0;
   while (i < LENGTH && speed[i] == -1) i++;
   while (i < LENGTH) {
     if (Math.random() <= prob_slowdown && speed[i] > 0) speed[i]--;
     else if (speed[i] < MAXSPEED) speed[i]++;
     int inext = i + 1;
     while (inext < LENGTH && speed[inext] == -1) inext++;
     if (inext < LENGTH) {
       if (speed[i] >= inext - i) speed[i] = inext - i - 1;
     }
     if (speed[i] > 0) {
       if (i + speed[i] < LENGTH) {
         int ni = i + speed[i];
         speed[ni] = speed[i];
         colors[ni] = colors[i];
       }
       speed[i] = -1;
     }
     i = inext;
   }
   if (Math.random() <= prob_create && speed[0] == -1) {
     speed[0] = (int) (5.99 * Math.random());
     colors[0] = ++count % 10 == 0 ? Color.red : Color.black;
   }
 }
コード例 #14
0
ファイル: DISCARD.java プロジェクト: rachmatowicz/JGroups
  public Object down(Message msg) {
    Address dest = msg.getDest();
    boolean multicast = dest == null;

    if (msg.getSrc() == null) msg.setSrc(localAddress());

    if (discard_all) {
      if (dest == null || dest.equals(localAddress())) loopback(msg);
      return null;
    }

    if (!multicast && drop_down_unicasts > 0) {
      drop_down_unicasts = Math.max(0, drop_down_unicasts - 1);
      return null;
    }

    if (multicast && drop_down_multicasts > 0) {
      drop_down_multicasts = Math.max(0, drop_down_multicasts - 1);
      return null;
    }

    if (down > 0) {
      double r = Math.random();
      if (r < down) {
        if (excludeItself && dest != null && dest.equals(localAddress())) {
          if (log.isTraceEnabled()) log.trace("excluding itself");
        } else {
          log.trace("dropping message");
          num_down++;
          return null;
        }
      }
    }
    return down_prot.down(msg);
  }
コード例 #15
0
    /**
     * Calculates the maximum size dimensions for the specified panal given the components in the
     * specified parent container.
     */
    public Dimension maximumLayoutSize(Container target) {
      synchronized (target.getTreeLock()) {
        Dimension dim = new Dimension(0, 0);
        int size = actions.size();
        if ((grip != null) && grip.isVisible()) {
          Dimension d = grip.getPreferredSize();
          dim.width += d.width;
          dim.width += hgap;
        }
        Component last = null;
        for (int i = 0; i < size; i++) {
          Component comp = (Component) actions.elementAt(i);
          if (comp.isVisible()) {
            Dimension d = comp.getPreferredSize();
            dim.width += d.width;
            dim.height = Math.max(dim.height, d.height);
            dim.width += hgap;
            last = comp;
          }
        }
        if (last != null) {
          Dimension prefSize = last.getPreferredSize();
          Dimension maxSize = last.getMaximumSize();
          if (prefSize != maxSize) {
            dim.width = dim.width - prefSize.width + maxSize.width;
            dim.height = Math.max(dim.height, maxSize.height);
          }
        }
        Insets insets = target.getInsets();
        dim.width += insets.left + insets.right;
        dim.height += insets.top + insets.bottom;

        return dim;
      }
    }
コード例 #16
0
ファイル: JEditTextArea.java プロジェクト: zeph/grinder
  /**
   * Ensures that the caret is visible by scrolling the text area if necessary.
   *
   * @return True if scrolling was actually performed, false if the caret was already visible
   */
  public boolean scrollToCaret() {
    int line = getCaretLine();
    int lineStart = getLineStartOffset(line);
    int offset = Math.max(0, Math.min(getLineLength(line) - 1, getCaretPosition() - lineStart));

    return scrollTo(line, offset);
  }
コード例 #17
0
ファイル: JEditTextArea.java プロジェクト: zeph/grinder
  /**
   * Ensures that the specified line and offset is visible by scrolling the text area if necessary.
   *
   * @param line The line to scroll to
   * @param offset The offset in the line to scroll to
   * @return True if scrolling was actually performed, false if the line and offset was already
   *     visible
   */
  public boolean scrollTo(int line, int offset) {
    // visibleLines == 0 before the component is realized
    // we can't do any proper scrolling then, so we have
    // this hack...
    if (visibleLines == 0) {
      setFirstLine(Math.max(0, line - electricScroll));
      return true;
    }

    int newFirstLine = firstLine;
    int newHorizontalOffset = horizontalOffset;

    if (line < firstLine + electricScroll) {
      newFirstLine = Math.max(0, line - electricScroll);
    } else if (line + electricScroll >= firstLine + visibleLines) {
      newFirstLine = (line - visibleLines) + electricScroll + 1;
      if (newFirstLine + visibleLines >= getLineCount())
        newFirstLine = getLineCount() - visibleLines;
      if (newFirstLine < 0) newFirstLine = 0;
    }

    int x = _offsetToX(line, offset);
    int width = painter.getFontMetrics().charWidth('w');

    if (x < 0) {
      newHorizontalOffset = Math.min(0, horizontalOffset - x + width + 5);
    } else if (x + width >= painter.getWidth()) {
      newHorizontalOffset = horizontalOffset + (painter.getWidth() - x) - width - 5;
    }

    return setOrigin(newFirstLine, newHorizontalOffset);
  }
コード例 #18
0
ファイル: Caixeiro.java プロジェクト: rwesz/maxwell
 public double distanciaEuclidiana(int x1, int x2, int y1, int y2) {
   double a, b, c;
   a = Math.pow(x2 - x1, 2);
   b = Math.pow(y2 - y1, 2);
   c = Math.sqrt(a + b);
   return (c);
 }
コード例 #19
0
ファイル: StdDraw.java プロジェクト: ihordey/algorithms-4th
 /**
  * Write the given text string in the current font, centered on (x, y) and rotated by the
  * specified number of degrees
  *
  * @param x the center x-coordinate of the text
  * @param y the center y-coordinate of the text
  * @param s the text
  * @param degrees is the number of degrees to rotate counterclockwise
  */
 public static void text(double x, double y, String s, double degrees) {
   double xs = scaleX(x);
   double ys = scaleY(y);
   offscreen.rotate(Math.toRadians(-degrees), xs, ys);
   text(x, y, s);
   offscreen.rotate(Math.toRadians(+degrees), xs, ys);
 }
コード例 #20
0
 private void setColumnPreferredSize() {
   for (int i = 0; i < getColumnCount(); i++) {
     TableColumn column = getColumnModel().getColumn(i);
     if (i == AbstractVcsLogTableModel.ROOT_COLUMN) { // thin stripe or nothing
       int rootWidth = myUI.getColorManager().isMultipleRoots() ? ROOT_INDICATOR_WIDTH : 0;
       // NB: all further instructions and their order are important, otherwise the minimum size
       // which is less than 15 won't be applied
       column.setMinWidth(rootWidth);
       column.setMaxWidth(rootWidth);
       column.setPreferredWidth(rootWidth);
     } else if (i
         == AbstractVcsLogTableModel
             .COMMIT_COLUMN) { // let commit message occupy as much as possible
       column.setPreferredWidth(Short.MAX_VALUE);
     } else if (i
         == AbstractVcsLogTableModel.AUTHOR_COLUMN) { // detect author with the longest name
       // to avoid querying the last row (it would lead to full graph loading)
       int maxRowsToCheck =
           Math.min(MAX_ROWS_TO_CALC_WIDTH, getRowCount() - MAX_ROWS_TO_CALC_OFFSET);
       if (maxRowsToCheck < 0) { // but if the log is small, check all of them
         maxRowsToCheck = getRowCount();
       }
       int contentWidth = calcMaxContentColumnWidth(i, maxRowsToCheck);
       column.setMinWidth(Math.min(contentWidth, MAX_DEFAULT_AUTHOR_COLUMN_WIDTH));
       column.setWidth(column.getMinWidth());
     } else if (i == AbstractVcsLogTableModel.DATE_COLUMN) { // all dates have nearly equal sizes
       Font tableFont = UIManager.getFont("Table.font");
       column.setMinWidth(
           getFontMetrics(tableFont)
               .stringWidth("mm" + DateFormatUtil.formatDateTime(new Date())));
       column.setWidth(column.getMinWidth());
     }
   }
 }
コード例 #21
0
  /*
   *  Adjust the width of the scrollpane used by the popup
   */
  protected void popupWider(BasicComboPopup popup) {
    JList list = popup.getList();

    //  Determine the maximimum width to use:
    //  a) determine the popup preferred width
    //  b) limit width to the maximum if specified
    //  c) ensure width is not less than the scroll pane width

    int popupWidth =
        list.getPreferredSize().width
            + 5 // make sure horizontal scrollbar doesn't appear
            + getScrollBarWidth(popup, scrollPane);

    if (maximumWidth != -1) {
      popupWidth = Math.min(popupWidth, maximumWidth);
    }

    Dimension scrollPaneSize = scrollPane.getPreferredSize();
    popupWidth = Math.max(popupWidth, scrollPaneSize.width);

    //  Adjust the width

    scrollPaneSize.width = popupWidth;
    scrollPane.setPreferredSize(scrollPaneSize);
    scrollPane.setMaximumSize(scrollPaneSize);
  }
コード例 #22
0
  public void paint(Graphics gg) {
    int faceSize = Math.min(getWidth() - 4, getHeight() - 4);
    if (face == null)
      face =
          new PADFaceMapped(
              Math.max(2, (getWidth() - faceSize) / 2),
              Math.max(2, (getHeight() - faceSize) / 2),
              faceSize);
    if (buffer == null) {
      im = this.createImage(getWidth(), getHeight());
      buffer = im.getGraphics();
    }
    super.paint(buffer);

    buffer.setColor(new Color(255, 255, 255, 0));
    buffer.fillRect(0, 0, im.getWidth(null), im.getHeight(null));

    face.setDimensions(
        Math.max(2, (getWidth() - faceSize) / 2),
        Math.max(2, (getHeight() - faceSize) / 2),
        faceSize);
    face.paint(buffer);

    // draw buffer to screen
    gg.drawImage(im, 0, 0, null, null);
  }
コード例 #23
0
ファイル: Selection.java プロジェクト: dscho/ImageJA
 void createEllipse(ImagePlus imp) {
   IJ.showStatus("Fitting ellipse");
   Roi roi = imp.getRoi();
   if (roi == null) {
     noRoi("Fit Ellipse");
     return;
   }
   if (roi.isLine()) {
     IJ.error("Fit Ellipse", "\"Fit Ellipse\" does not work with line selections");
     return;
   }
   ImageProcessor ip = imp.getProcessor();
   ip.setRoi(roi);
   int options = Measurements.CENTROID + Measurements.ELLIPSE;
   ImageStatistics stats = ImageStatistics.getStatistics(ip, options, null);
   double dx = stats.major * Math.cos(stats.angle / 180.0 * Math.PI) / 2.0;
   double dy = -stats.major * Math.sin(stats.angle / 180.0 * Math.PI) / 2.0;
   double x1 = stats.xCentroid - dx;
   double x2 = stats.xCentroid + dx;
   double y1 = stats.yCentroid - dy;
   double y2 = stats.yCentroid + dy;
   double aspectRatio = stats.minor / stats.major;
   imp.killRoi();
   imp.setRoi(new EllipseRoi(x1, y1, x2, y2, aspectRatio));
 }
コード例 #24
0
 public void enemyPosition(ScannedRobotEvent e, double x, double y) {
   // poll subtargetters for their opinions
   virtualBulletTick++;
   lastEnemyScanTime = owner.getTime();
   // only log it when we actually fire: the enemy may respond to that
   if (owner.shouldFireShot(e)) {
     double bulletPower = e.getDistance() > 500.0 ? 2.0 : 3.0;
     for (int i = 0; i < numVirtualGuns; i++) {
       double angle = targetters[i].target(e, bulletPower);
       VirtualBullet bullet = new VirtualBullet();
       bullet.targetter = i;
       bullet.x = owner.getX();
       bullet.y = owner.getY();
       bullet.velX = Targetting.bulletSpeed(bulletPower) * Math.sin(angle);
       bullet.velY = Targetting.bulletSpeed(bulletPower) * Math.cos(angle);
       bullet.lastUpdateTime = lastEnemyScanTime;
       virtualBullets.add(bullet);
     }
   }
   for (int i = 0; i < numVirtualGuns; i++) {
     targetters[i].enemyPosition(e, x, y);
   }
   enemyX = x;
   enemyY = y;
 }
コード例 #25
0
ファイル: LineSelection.java プロジェクト: RayPlante/Horizon
  /**
   * Draw the LineSelection at its current location. It is the responsibility of the
   * applet/application to draw the LineSelection at the appropriate times, e.g., inside the
   * component's update() and/or paint() method. This gives maximum flexibility for double
   * buffering, etc.
   *
   * @param g The Graphics context to use for drawing.
   */
  public void draw(Graphics g) {

    if (!isVisible()) {
      return;
    }

    Color saveColor = g.getColor();
    g.setColor(color);
    if (thickness > 1) {
      double ratio = ((double) thickness) / ((double) length());
      double txdb = ratio * ((double) height) / 2.0;
      int tx = txdb > 0 ? ((int) Math.ceil(txdb)) : ((int) Math.floor(txdb));
      double tydb = -ratio * ((double) width) / 2.0;
      int ty = tydb > 0 ? ((int) Math.ceil(tydb)) : ((int) Math.floor(tydb));
      Point[] poly = new Point[4];
      for (int i = 0; i < 4; i++) poly[i] = new Point(x, y);
      poly[0].translate(tx, ty);
      poly[1].translate(-tx, -ty);
      poly[2].translate(width, height);
      poly[2].translate(-tx, -ty);
      poly[3].translate(width, height);
      poly[3].translate(tx, ty);
      Polygon polygon = new Polygon();
      for (int i = 0; i < 4; i++) polygon.addPoint(poly[i].x, poly[i].y);
      g.fillPolygon(polygon);
    } else g.drawLine(x, y, x + width, y + height);
    g.setColor(saveColor);
  } // end draw
コード例 #26
0
 /**
  * Returns a list of pairs of x coordinates for visual ranges representing given logical range. If
  * <code>startOffset == endOffset</code>, a pair of equal numbers is returned, corresponding to
  * target position. Target offsets are supposed to be located on the same visual line.
  */
 private TFloatArrayList logicalRangeToVisualRanges(int startOffset, int endOffset) {
   assert startOffset <= endOffset;
   TFloatArrayList result = new TFloatArrayList();
   for (VisualLineFragmentsIterator.Fragment fragment :
       VisualLineFragmentsIterator.create(myView, startOffset, false)) {
     int minOffset = fragment.getMinOffset();
     int maxOffset = fragment.getMaxOffset();
     if (startOffset == endOffset) {
       if (startOffset >= minOffset && startOffset <= maxOffset) {
         float x = fragment.offsetToX(startOffset);
         result.add(x);
         result.add(x);
         break;
       }
     } else if (startOffset < maxOffset && endOffset > minOffset) {
       float x1 = fragment.offsetToX(Math.max(minOffset, startOffset));
       float x2 = fragment.offsetToX(Math.min(maxOffset, endOffset));
       if (x1 > x2) {
         float tmp = x1;
         x1 = x2;
         x2 = tmp;
       }
       if (result.isEmpty() || x1 > result.get(result.size() - 1)) {
         result.add(x1);
         result.add(x2);
       } else {
         result.set(result.size() - 1, x2);
       }
     }
   }
   return result;
 }
コード例 #27
0
ファイル: extendedCanvas.java プロジェクト: kristenmills/CG
 public void printLoop(int n, float x[], float y[]) {
   // Need to swap the y component
   Polygon P = new Polygon();
   for (int i = 0; i < n; i++) P.addPoint(Math.round(x[i]), Math.round(height - y[i]));
   poly_draw.add(P);
   poly_draw_color.add(curColor);
 }
コード例 #28
0
 @NotNull
 private Dimension expandIfNecessary(@NotNull Dimension base) {
   if (base.width >= myMinWidth && base.height >= myMinHeight) {
     return base;
   }
   return new Dimension(Math.max(myMinWidth, base.width), Math.max(myMinHeight, base.height));
 }
コード例 #29
0
ファイル: CurvedGaussian.java プロジェクト: Rygbee/CiteSeerX
  public void EMpar(Database db, double prior) {
    int j, np;
    double x, y, tmp, tmpx, tmpy, tmpsx, tmpsy, tmpsxy;

    np = db.nPoints();
    tmpsx = tmpsy = tmpsxy = kmx = kmy = 0;
    for (j = 0; j < np; j++) {
      x = db.xVal(j);
      y = db.yVal(j);
      kmx += probs[j] * x;
      kmy += probs[j] * y;
      tmpsx += probs[j] * x * x;
      tmpsy += probs[j] * y * y;
      tmpsxy += probs[j] * x * y;
    }
    tmp = np * weight;
    kmx /= tmp;
    kmy /= tmp;
    ksx = Math.sqrt(tmpsx / tmp - kmx * kmx);
    ksy = Math.sqrt(tmpsy / tmp - kmy * kmy);
    ksxy = tmpsxy / tmp - kmx * kmy;
    if (ksx < mins) ksx = mins;
    if (ksy < mins) ksy = mins;
    weight = 0.9 * weight + 0.1 * prior;
  }
コード例 #30
0
ファイル: Cargas.java プロジェクト: ingeniomaps/Concentrese
  // Proceso para posicionar las imagenes en el concentrece
  public void cargarImagenes() {
    int x, y = 0;
    int numero = -1;
    double x1, y1 = 0;
    ficha = new int[a][b];
    // Incializacion de la matriz entera en -1
    for (int i = 0; i < getA(); i++) {
      for (int j = 0; j < getB(); j++) {
        ficha[i][j] = -1;
      }
    }

    // Proceso de introduccion de imagenes en posiciones aleatorias para
    // obtener mas variaciones del juego
    for (int i = 0; i < getA(); i++) {
      for (int j = 0; j < getB(); j++) {
        do {
          x1 = Math.random() * getA();
          y1 = Math.random() * getB();
          x = (int) x1;
          y = (int) y1;
        } while (ficha[x][y] != -1);
        numero++;
        if (numero == getC()) {
          numero = 0;
        }
        ficha[x][y] = numero;
        parejas[i][j].setIcon(vacio);
      }
    }
  }