public double sign(double a, double b) {
   if (b < 0) {
     return -Math.abs(a);
   } else {
     return Math.abs(a);
   }
 }
 double oblicz_wage(int x1, int y1, int x2, int y2) {
   double x = (double) Math.pow(Math.abs((x1 - x2)), 2);
   double y = (double) Math.pow(Math.abs((y1 - y2)), 2);
   double wynik = Math.sqrt(x + y) * 1000;
   wynik = Math.round(wynik);
   return (wynik / 1000);
 }
Example #3
0
  private void addRegime() {
    if (isEnd) return;

    if (feedCounter2 - feedCounter1 != 4 || isRegime || feedCounter2 == 0) return;

    feedCounter1 = feedCounter2;

    currentTime = System.currentTimeMillis();

    regimeX = Math.abs(random.nextInt()) % 400 + 10;
    regimeY = Math.abs(random.nextInt()) % 400 + 10;

    List<Block> blockTemp = new ArrayList<>(blocks);

    for (int i = 0; i < blockTemp.size(); i++)
      if (blockTemp.get(i).getX() < regimeX
          && blockTemp.get(i).getY() < regimeY
          && blockTemp.get(i).getX() + 10 > regimeX
          && blockTemp.get(i).getY() + 10 > regimeY) {
        regimeX = Math.abs(random.nextInt()) % 400 + 10;
        regimeY = Math.abs(random.nextInt()) % 400 + 10;
      }

    regimeRectangle.setX(regimeX);
    regimeRectangle.setY(regimeY);

    isRegime = true;
  }
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and ellipse.
  *
  * @return Returns true, if the circle is inside of the image bounds.
  */
 private boolean writeCircleAttributes(IXMLElement elem, SVGFigure f, Ellipse2D.Double ellipse) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType() &&
             ellipse.width == ellipse.height
             ) {
         
         Point2D.Double start = new Point2D.Double(ellipse.x, ellipse.y);
         Point2D.Double end = new Point2D.Double(ellipse.x + ellipse.width, ellipse.y + ellipse.height);
         t.transform(start, start);
         t.transform(end, end);
         ellipse.x = Math.min(start.x, end.x);
         ellipse.y = Math.min(start.y, end.y);
         ellipse.width = Math.abs(start.x - end.x);
         ellipse.height = Math.abs(start.y - end.y);
         
         elem.setAttribute("shape", "circle");
         elem.setAttribute("coords",
                 (int) (ellipse.x + ellipse.width / 2d)+","+
                 (int) (ellipse.y + ellipse.height / 2d)+","+
                 (int) (ellipse.width / 2d)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(ellipse.getBounds());
     } else {
         return writePolyAttributes(elem, f, (Shape) ellipse);
     }
 }
Example #5
0
  private void doesEatRegime() {
    if (isEnd) return;

    if (Math.abs(blocks.peekFirst().getX() - regimeRectangle.getX()) < 10
        && Math.abs(blocks.peekFirst().getY() - regimeRectangle.getY()) < 10
        && System.currentTimeMillis() - currentTime <= 10000) {

      regimeRectangle.setX(1200);
      isRegime = false;
      ++score;
      scoreLabel.setText(String.valueOf(score));

      blocks.pollLast();
      blocks.pollLast();
      blocks.pollLast();

      group.getChildren().remove(rectangles.peekLast());
      rectangles.pollLast();
      group.getChildren().remove(rectangles.peekLast());
      rectangles.pollLast();
      group.getChildren().remove(rectangles.peekLast());
      rectangles.pollLast();
    }

    if (System.currentTimeMillis() - currentTime > 10000) {
      regimeRectangle.setX(1200);
      isRegime = false;
    }
  }
Example #6
0
 // if left is true --> left is the anchoring End(IS element-known)
 // --> then the right side is the insertion position so we check the rightside.
 public boolean isInsertionPair(Record other, boolean left) {
   if (left) {
     // --this--><--other--
     if (this.fwd2 && !other.fwd2) {
       if ((this.start2 < other.start2)
           && (other.end2 > this.end2)
           && (Math.abs(this.end2 - other.start2) <= 100)) return true;
     }
     // --other--><--this--
     else if (other.fwd2 && !this.fwd2) {
       if ((other.start2 < this.start2)
           && (this.end2 > other.end2)
           && (Math.abs(other.end2 - this.start2) <= 100)) return true;
     }
   } else {
     // --this--><--other--
     if (this.fwd1 && !other.fwd1) {
       if ((this.start1 < other.start1)
           && (other.end1 > this.end1)
           && (Math.abs(this.end1 - other.start1) <= 100)) return true;
     }
     // --other--><--this--
     else if (other.fwd1 && !this.fwd1) {
       if ((other.start1 < this.start1)
           && (this.end1 > other.end1)
           && (Math.abs(other.end1 - this.start1) <= 100)) return true;
     }
   }
   return false;
 }
Example #7
0
  private void addFeed() {
    if (isEnd) return;

    if (isFeed) return;

    feedX = Math.abs(random.nextInt()) % 400 + 10;
    feedY = Math.abs(random.nextInt()) % 400 + 60;

    List<Block> blockTemp = new ArrayList<>(blocks);

    for (int i = 0; i < blockTemp.size(); i++)
      if (blockTemp.get(i).getX() < feedX
          && blockTemp.get(i).getY() < feedY
          && blockTemp.get(i).getX() + 10 > feedX
          && blockTemp.get(i).getY() + 10 > feedY) {
        feedX = Math.abs(random.nextInt()) % 400 + 10;
        feedY = Math.abs(random.nextInt()) % 400 + 60;
      }

    feedRectangle.setX(feedX);
    feedRectangle.setY(feedY);

    isFeed = true;

    addObstacle();
  }
Example #8
0
  private void draw_horizon(int rad, Point center, int[] angles) {
    // Draw an arc
    int arc_angle =
        ((angles[0] > angles[1]) ? (360 - angles[0]) + angles[1] : (angles[1] - angles[0]));

    Polygon remainder = new Polygon();

    offgraphics_.setColor(GREEN);
    offgraphics_.fillArc(center.x - rad, center.y - rad, 2 * rad, 2 * rad, angles[0], arc_angle);

    if (pitch_ != 0) {
      if ((pitch_ > 0 && Math.abs(roll_) < 90) || (pitch_ < 0 && Math.abs(roll_) >= 90))
        offgraphics_.setColor(BLUE);

      int cover_angle = (angles[0] + arc_angle / 2 + ((arc_angle < 180) ? 180 : 0)) % 360;

      // System.out.println (points[0] + " " + points[1]);

      // System.out.println (accepted_point);

      remainder.addPoint(
          center.x + polar_to_rect_x(rad, cover_angle),
          center.y - polar_to_rect_y(rad, cover_angle));
      remainder.addPoint(
          center.x + polar_to_rect_x(rad, angles[0]), center.y - polar_to_rect_y(rad, angles[0]));
      remainder.addPoint(
          center.x + polar_to_rect_x(rad, angles[1]), center.y - polar_to_rect_y(rad, angles[1]));
      offgraphics_.fillPolygon(remainder);
      // offgraphics_.setColor (getBackground ());
      // offgraphics_.drawPolygon (remainder);
    }
  }
Example #9
0
 /**
  * Calculates the difference
  *
  * @return difference
  */
 public double prototypeDifference(CombStat stat) {
   double sumdiff = 0;
   double weight;
   // Numeric atts: abs difference
   for (int i = 0; i < m_RegStat.getNbNumericAttributes(); i++) {
     weight = m_StatManager.getClusteringWeights().getWeight(m_RegStat.getAttribute(i));
     sumdiff += Math.abs(prototypeNum(i) - stat.prototypeNum(i)) * weight;
     // System.err.println("sumdiff: " + Math.abs(prototypeNum(i) - stat.prototypeNum(i)) *
     // weight);
   }
   // Nominal atts: Manhattan distance
   for (int i = 0; i < m_ClassStat.getNbNominalAttributes(); i++) {
     weight = m_StatManager.getClusteringWeights().getWeight(m_ClassStat.getAttribute(i));
     double sum = 0;
     double[] proto1 = prototypeNom(i);
     double[] proto2 = stat.prototypeNom(i);
     for (int j = 0; j < proto1.length; j++) {
       sum += Math.abs(proto1[j] - proto2[j]);
     }
     sumdiff += sum * weight;
     // System.err.println("sumdiff: " + (sum * weight));
   }
   // System.err.println("sumdiff-total: " + sumdiff);
   return sumdiff != 0 ? sumdiff : 0.0;
 }
Example #10
0
  @Override
  public BoundingBox getBounds() {
    // If there are no charges, return an empty box.
    if (charges.size() <= 0) return new BoundingBox(0, 0, 0, 0, 0, 0);

    if (cachedBounds == null) {
      // Start with the box of the first charge.
      Charge c = charges.get(0);
      double ext = Math.abs(c.w);
      double corr = 1.0 + (0.1 / hardness); // see note
      cachedBounds =
          new BoundingBox(
              new Vec3(c.x - ext, c.y - ext, c.z - ext).times(corr),
              new Vec3(c.x + ext, c.y + ext, c.z + ext).times(corr));

      // A note on "corr":
      // As blobs are blobby, we can't use their weight/radius
      // directly. This would result in unwanted cut-off's. To
      // correct this, we extend the bounding box of a charge "a
      // bit". That "bit" can be smaller if the charge is harder.

      // Iteratively add the remaining charges.
      for (int i = 1; i < charges.size(); i++) {
        c = charges.get(i);
        ext = Math.abs(c.w);
        corr = 1.0 + (0.1 / hardness);
        cachedBounds.extend(
            new BoundingBox(
                new Vec3(c.x - ext, c.y - ext, c.z - ext).times(corr),
                new Vec3(c.x + ext, c.y + ext, c.z + ext).times(corr)));
      }
    }

    return cachedBounds;
  }
Example #11
0
 public boolean ok(String out, String reference) {
   // log.fine("out1: " + a);
   // log.fine("out2: " + b);
   Scanner sa = new Scanner(out);
   Scanner sb = new Scanner(reference);
   while (sa.hasNext() && sb.hasNext()) {
     if (sa.hasNextDouble() || sb.hasNextDouble()) {
       if (!sa.hasNextDouble() || !sb.hasNextDouble()) return true;
       double da = sa.nextDouble();
       double db = sb.nextDouble();
       double d_abs = Math.abs(da - db);
       double d_rel = d_abs / Math.abs(db);
       if (!(d_abs < EPS || d_rel < EPS)) {
         log.fine("NOK, " + da + " too far from " + db);
         return false;
       }
     } else {
       String xa = sa.next();
       String xb = sb.next();
       if (!xa.equals(xb)) {
         log.fine("NOK, " + xa + " != " + xb);
         return false;
       }
     }
   }
   if (sa.hasNext() || sb.hasNext()) {
     log.fine("NOK: different number of tokens.");
     return false;
   }
   return true;
 }
Example #12
0
    @Override
    public void onSensorChanged(SensorEvent event) {
      // TODO Auto-generated method stub
      float[] values = event.values;

      java.util.Locale locale = java.util.Locale.CHINA;
      SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddhhmmssSSS", locale);
      Date currentTime = new Date();
      String dateString = formatter.format(currentTime);

      if ((Math.abs(values[0]) > 14 || Math.abs(values[1]) > 14 || Math.abs(values[2]) > 14)) {
        try {
          edtmsgcontent.setText(values[0] + "x");
          String msg = imei + "," + dateString;
          if (!TextUtils.isEmpty(msg)) SendMsg(getIp(), port, msg);
          else {
            // Toast.makeText(this,"请先输入要发送的内容", Toast.LENGTH_LONG);
            edtmsgcontent.requestFocus();
          }
        } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

        mSensorManager.unregisterListener(mOnSensorEventListener);
      }
    }
Example #13
0
 @Override
 public double heuristic() {
   // manhattan distance metric for simple maze with one agent:
   double hValue = 0;
   for (int i = 0; i < R; i++)
     hValue += Math.abs(xGoal[i] - robots[i][0]) + Math.abs(yGoal[i] - robots[i][1]);
   return hValue;
 }
Example #14
0
  protected static double ludcmp(double[][] a, int[] indx) throws ErrorSingular {

    // Return new values for a, indx, d
    double d;
    int n = a[0].length;
    int i, imax, j, k;
    double big, dum, sum, temp;
    double[] vv = new double[n + 1];
    d = (double) 1.0;
    for (i = 1; i <= n; i++) {
      big = (double) 0.0;
      for (j = 1; j <= n; j++) if ((temp = Math.abs(a[j - 1][i - 1])) > big) big = temp;
      if (big == 0.0) {
        throw new ErrorSingular("Matriz singular en ludcmp");
      }

      vv[i - 1] = (double) 1.0 / big;
    }

    for (j = 1; j <= n; j++) {
      for (i = 1; i < j; i++) {
        sum = a[j - 1][i - 1];
        for (k = 1; k < i; k++) sum -= a[k - 1][i - 1] * a[j - 1][k - 1];
        a[j - 1][i - 1] = sum;
      }

      big = (double) 0.0;
      imax = -1;
      for (i = j; i <= n; i++) {
        sum = a[j - 1][i - 1];
        for (k = 1; k < j; k++) sum -= a[k - 1][i - 1] * a[j - 1][k - 1];
        a[j - 1][i - 1] = sum;
        if ((dum = vv[i - 1] * Math.abs(sum)) >= big) {
          big = dum;
          imax = i;
        }
      }

      if (j != imax) {
        for (k = 1; k <= n; k++) {
          dum = a[k - 1][imax - 1];
          a[k - 1][imax - 1] = a[k - 1][j - 1];
          a[k - 1][j - 1] = dum;
        }
        d = -d;
        vv[imax - 1] = vv[j - 1];
      }
      indx[j - 1] = imax;
      if (Math.abs(a[j - 1][j - 1]) < MINVALPRO)
        throw new ErrorSingular("Matriz Singular en ludcmp");

      if (j != n) {
        dum = (double) 1.0 / (a[j - 1][j - 1]);
        for (i = j + 1; i <= n; i++) a[j - 1][i - 1] *= dum;
      }
    }
    return d;
  }
Example #15
0
  private void pitch_horizon(int rad, int[] angles) {
    boolean upside_down = Math.abs(roll_) >= 90;
    int angle_shift = (int) Math.round((double) (90 - (Math.abs(roll_) % 180)) / 90.0 * pitch_);

    //      System.out.println ("angle_shift " + angle_shift);

    angles[0] += angle_shift;
    angles[1] -= angle_shift;
  }
Example #16
0
 public static boolean fuzzyEqual(double x, double y, double epsilon) {
   if (Math.abs(x - y) <= epsilon) {
     return true;
   }
   if ((Math.abs(x) <= epsilon) || (Math.abs(y) <= epsilon)) {
     return false;
   }
   return (Math.abs((x - y) / x) <= epsilon) || (Math.abs((x - y) / y) <= epsilon);
 }
Example #17
0
  public void update_display(int lat, int lon, int alt, int heading) {
    String lat_str = Math.abs(lat) + "" + DEGREE + ((lat > 0) ? " N" : " S");
    String long_str = Math.abs(lon) + "" + DEGREE + ((lon > 0) ? " E" : " W");

    lat_.setText(lat_str);
    long_.setText(long_str);
    alt_.setText(alt + " Kft");
    heading_.setText(heading + "" + DEGREE + "  ");
  }
Example #18
0
	static decision_function svm_train_one(
		svm_problem prob, svm_parameter param,
		double Cp, double Cn)
	{
		double[] alpha = new double[prob.l];
		Solver.SolutionInfo si = new Solver.SolutionInfo();
		switch(param.svm_type)
		{
			case svm_parameter.C_SVC:
				solve_c_svc(prob,param,alpha,si,Cp,Cn);
				break;
			case svm_parameter.NU_SVC:
				solve_nu_svc(prob,param,alpha,si);
				break;
			case svm_parameter.ONE_CLASS:
				solve_one_class(prob,param,alpha,si);
				break;
			case svm_parameter.EPSILON_SVR:
				solve_epsilon_svr(prob,param,alpha,si);
				break;
			case svm_parameter.NU_SVR:
				solve_nu_svr(prob,param,alpha,si);
				break;
		}

		System.out.print("obj = "+si.obj+", rho = "+si.rho+"\n");

		// output SVs

		int nSV = 0;
		int nBSV = 0;
		for(int i=0;i<prob.l;i++)
		{
			if(Math.abs(alpha[i]) > 0)
			{
				++nSV;
				if(prob.y[i] > 0)
				{
					if(Math.abs(alpha[i]) >= si.upper_bound_p)
					++nBSV;
				}
				else
				{
					if(Math.abs(alpha[i]) >= si.upper_bound_n)
						++nBSV;
				}
			}
		}

		System.out.print("nSV = "+nSV+", nBSV = "+nBSV+"\n");

		decision_function f = new decision_function();
		f.alpha = alpha;
		f.rho = si.rho;
		return f;
	}
Example #19
0
 /* Use Backtracking */
 static void addQueen(int[] q, int len) {
   if (len == N) tmpRes++;
   LOOP:
   for (int j = 0; j < N; j++) {
     for (int m = 0; m < len; m++)
       if (q[m] == j || Math.abs(m - len) == Math.abs(q[m] - j)) continue LOOP;
     q[len] = j;
     addQueen(q, len + 1);
   }
 }
Example #20
0
 Point(long x, long y) {
   this.x = x;
   this.y = y;
   this.absx = Math.abs(x);
   this.absy = Math.abs(y);
   cnt += 6;
   if (this.x == 0 || this.y == 0) {
     cnt -= 2;
   }
 }
Example #21
0
  public void paint(Graphics g) {
    System.out.println("paint");
    Graphics2D g2d = (Graphics2D) g;

    Point1 p1, p2;

    n = paintInfo.size();

    if (toolFlag == 2) g2d.clearRect(0, 0, getSize().width - 100, getSize().height - 100); // 清除

    for (int i = 0; i < n - 1; i++) {
      p1 = (Point1) paintInfo.elementAt(i);
      p2 = (Point1) paintInfo.elementAt(i + 1);
      size = new BasicStroke(p1.boarder, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);

      g2d.setColor(p1.col);
      g2d.setStroke(size);

      if (p1.tool == p2.tool) {
        switch (p1.tool) {
          case 0: // 画笔
            Line2D line1 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y);
            g2d.draw(line1);
            break;

          case 1: // 橡皮
            g.clearRect(p1.x, p1.y, p1.boarder, p1.boarder);
            break;

          case 3: // 画直线
            Line2D line2 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y);
            g2d.draw(line2);
            break;

          case 4: // 画圆
            Ellipse2D ellipse =
                new Ellipse2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y));
            g2d.draw(ellipse);
            break;

          case 5: // 画矩形
            Rectangle2D rect =
                new Rectangle2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y));
            g2d.draw(rect);
            break;

          case 6: // 截断,跳过
            i = i + 1;
            break;

          default:
        } // end switch
      } // end if
    } // end for
  }
 /** Check magnitude of difference of scalars. * */
 private static void check(double x, double y) {
   double eps = Math.pow(2.0, -52.0);
   if (x == 0 & Math.abs(y) < 10 * eps) return;
   if (y == 0 & Math.abs(x) < 10 * eps) return;
   if (Math.abs(x - y) > 10 * eps * Math.max(Math.abs(x), Math.abs(y))) {
     throw new RuntimeException(
         "The difference x-y is too large: x = "
             + Double.toString(x)
             + "  y = "
             + Double.toString(y));
   }
 }
Example #23
0
    private Line addLine(Point p1, Point p2) {
      if (Math.abs(p1.getX() - p2.getX()) < 5 || Math.abs(p1.getY() - p2.getY()) < 5) {
        return null;
      }

      Line line = null;
      if (p1 != null && p2 != null) {
        line = new Line(p1, p2);
        canvas.add(line);
      }
      repaint();
      return line;
    }
 private boolean checkAllow(long ip) {
   int cur = 0;
   int minRule = (rule[cur] != 0) ? rule[cur] : Integer.MAX_VALUE;
   for (int i = 31; i >= 0; i--) {
     int bit = ((ip & (1L << i)) == 0) ? 0 : 1;
     cur = go[bit][cur];
     if (cur < 0) {
       break;
     }
     minRule = (rule[cur] != 0 && Math.abs(rule[cur]) < Math.abs(minRule)) ? rule[cur] : minRule;
   }
   return minRule >= 0;
 }
Example #25
0
 public static int rules(
     String top, Vector<String> first, Vector<String> second, Vector<String> afia) {
   while (!first.isEmpty() && !second.isEmpty()) {
     if (count % 2 == 0) {
       boolean check = false;
       for (int i = 0; i < first.size(); i++) {
         check =
             matcher(
                 top,
                 first.elementAt(
                     i)); // performs a linear search on player1's whot to see if any matches the
         // top card
         if (check == true) {
           place.addElement(first.elementAt(i));
           first.removeElementAt(i);
           break;
         }
       }
       if (check == false) {
         Random rd = new Random();
         int pick = Math.abs(rd.nextInt(afia.size() - 1)) % (afia.size() - 1);
         first.addElement(afia.elementAt(pick));
         afia.removeElementAt(pick);
       }
     } else {
       boolean check = false;
       for (int i = 0; i < second.size(); i++) {
         check =
             matcher(
                 top,
                 second.elementAt(
                     i)); // performs a linear search on player1's whot to see if any matches the
         // top card
         if (check == true) {
           place.addElement(second.elementAt(i));
           second.removeElementAt(i);
           break;
         }
       }
       if (check == false) {
         Random rd = new Random();
         int pick = Math.abs(rd.nextInt(afia.size() - 1)) % (afia.size() - 1);
         second.addElement(afia.elementAt(pick));
         afia.removeElementAt(pick);
       }
     }
   }
   return 1;
 }
Example #26
0
 @Override
 public int commit() {
   String key;
   String value;
   rm();
   try {
     for (Map.Entry<String, String> i : map.entrySet()) {
       key = i.getKey();
       value = i.getValue();
       Integer ndirectory = Math.abs(key.getBytes("UTF-8")[0] % N);
       Integer nfile = Math.abs((key.getBytes("UTF-8")[0] / N) % N);
       String pathToDir = path + File.separator + ndirectory.toString() + ".dir";
       File file = new File(pathToDir);
       if (!file.exists()) {
         file.mkdir();
       }
       String pathToFile =
           path
               + File.separator
               + ndirectory.toString()
               + ".dir"
               + File.separator
               + nfile.toString()
               + ".dat";
       file = new File(pathToFile);
       if (!file.exists()) {
         file.createNewFile();
       }
       DataOutputStream outStream = new DataOutputStream(new FileOutputStream(pathToFile, true));
       byte[] byteWord = key.getBytes("UTF-8");
       outStream.writeInt(byteWord.length);
       outStream.write(byteWord);
       outStream.flush();
       byteWord = value.getBytes("UTF-8");
       outStream.writeInt(byteWord.length);
       outStream.write(byteWord);
       outStream.flush();
       outStream.close();
     }
   } catch (IOException e) {
     System.err.println(e.getMessage());
     System.exit(-1);
   }
   TableState ts = new TableState(map, unsavedChanges, numberOfElements);
   tableStates.put(++numberOfState, ts);
   int n = unsavedChanges;
   unsavedChanges = 0;
   return n;
 }
Example #27
0
  /** *****************************Connected Component Recursive ***************************** */
  void connect(int y, int x) {

    if (conect_output[y][x] == 0) {
      conect_output[y][x] = 175;
      obj_size++;

      // System.out.println("Size :" +obj_size);
      s = x + 1;
      t = y;
      if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) {
        //	conect_output[s][t] = 175;
        connect(t, s);
      }

      s = x;
      t = y - 1;
      if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) {
        //	conect_output[s][t] = 175;
        connect(t, s);
      }
      s = x + 1;
      t = y - 1;
      if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) {
        //	conect_output[s][t] = 175;
        connect(t, s);
      }
      s = x + 1;
      t = y + 1;
      if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) {
        //	conect_output[s][t] = 175;
        connect(t, s);
      }
      s = x - 1;
      t = y - 1;
      if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) {
        //	conect_output[s][t] = 175;
        connect(t, s);
      }
      s = x - 1;
      t = y + 1;
      if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) {
        //	conect_output[s][t] = 175;
        connect(t, s);
      }
      s = x + 1;
      t = y;
      if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) {
        //	conect_output[s][t] = 175;
        connect(t, s);
      }
      s = x - 1;
      t = y;
      if (boundary_check(t, s) && (Math.abs(conect_input[t][s] - intensity) < 20)) {
        //	conect_output[s][t] = 175;
        connect(t, s);
      }
    }
  }
  /**
   * Move the cursor <i>where</i> characters, withough checking the current buffer.
   *
   * @see #where
   * @param where the number of characters to move to the right or left.
   */
  private final void moveInternal(final int where) throws IOException {
    // debug ("move cursor " + where + " ("
    // + buf.cursor + " => " + (buf.cursor + where) + ")");
    buf.cursor += where;

    char c;

    if (where < 0) {
      int len = 0;
      for (int i = buf.cursor; i < buf.cursor - where; i++) {
        if (buf.getBuffer().charAt(i) == '\t') len += TAB_WIDTH;
        else len++;
      }

      char cbuf[] = new char[len];
      Arrays.fill(cbuf, BACKSPACE);
      out.write(cbuf);

      return;
    } else if (buf.cursor == 0) {
      return;
    } else if (mask != null) {
      c = mask.charValue();
    } else {
      printCharacters(buf.buffer.substring(buf.cursor - where, buf.cursor).toCharArray());
      return;
    }

    // null character mask: don't output anything
    if (NULL_MASK.equals(mask)) {
      return;
    }

    printCharacters(c, Math.abs(where));
  }
Example #29
0
  public double getRadix(int age, String candlesLine) {
    double hi = 100;
    double lo = 0;

    int c = 0;
    while (c++ < 100) {
      double mid = lo + (hi - lo) / 2.0;
      double curr = check(candlesLine, mid);

      if (curr < age) {
        lo = mid;
      } else {
        hi = mid;
      }
    }

    int l = candlesLine.length();

    if (age == 1
        && candlesLine.charAt(l - 1) == '1'
        && candlesLine.substring(0, l - 1).indexOf('1') == -1) {
      return -2;
    }

    if (lo == 0 || Math.abs(check(candlesLine, lo) - age) > 1.0e-8) {
      return -1;
    }

    return lo;
  }
Example #30
0
  private int dfsVisit(Pack u, int[] status, boolean wipe, Map<String, PackColor> colours) {
    colours.put(u.getName(), PackColor.GREY);
    int check = checkValues[getPos(u.getName())];

    if (Math.abs(check) != 1) {
      wipe = true;
    }
    List<String> deps = u.getDependants();
    if (deps != null) {
      for (String name : deps) {
        Pack v = nameToPack.get(name);
        if (wipe) {
          status[getPos(v.getName())] = 1;
        }
        if (colours.get(v.getName()) == PackColor.WHITE) {
          final int result = dfsVisit(v, status, wipe, colours);
          if (result != 0) {
            return result;
          }
        }
      }
    }
    colours.put(u.getName(), PackColor.BLACK);
    return 0;
  }