Esempio n. 1
1
  /* gibt die Nummer einer Modellspalte zuruck */
  protected int getColumnForResize(int x, int y) {
    if (m_Model == null) return -1;
    if ((y <= 0)
        || (y
            >= m_Model.getFirstRowHeight()
                + (m_Model.getFixedRowCount() - 1) * m_Model.getRowHeight())) return -1;

    if (x < getFixedWidth() + 3) {
      for (int i = 0; i < m_Model.getFixedColumnCount(); i++)
        if (Math.abs(x - getColumnRight(i)) < 3) {
          if (m_Model.isColumnResizable(i)) return i;
          return -1;
        }
    }

    for (int i = m_LeftColumn; i < m_Model.getColumnCount(); i++) {
      int left = getColumnLeft(i);
      int right = left + m_Model.getColumnWidth(i);
      if (Math.abs(x - right) < 3) {
        if (m_Model.isColumnResizable(i)) return i;
        return -1;
      }
      if ((x >= left + 3) && (x <= right - 3)) break;
    }
    return -1;
  }
Esempio n. 2
1
 public static void muovi(JComponent jc, int x, int y) {
   int inX = jc.getX();
   int inY = jc.getY();
   int spost = (Math.abs(x - inX) + Math.abs(y - inY)) / 3;
   if (spost != 0) {
     int spostX = (x - inX) / spost;
     int spostY = (y - inY) / spost;
     int restoX = 0;
     int restoY = 0;
     int nX, nY;
     for (int i = 0; i < spost; i++) {
       restoX = (x - inX + restoX) % spost;
       restoY = (y - inY + restoY) % spost;
       nX = jc.getX() + (spostX);
       nY = jc.getY() + (spostY);
       spostX = (x - inX + restoX) / spost;
       spostY = (y - inY + restoY) / spost;
       jc.setLocation(nX, nY);
       jc.repaint();
       try {
         Thread.sleep(1 + 1 / 2);
       } catch (InterruptedException e) {
         e.printStackTrace();
       }
     }
     jc.setLocation(x, y);
   }
 }
    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());
    }
Esempio n. 4
1
  public void yawAdapt(float leaderYawInit, float myYawInit) {
    float leaderYaw = leader.getNavDataHandler().getNavDataDemo().getYaw() - leaderYawInit;
    float myYaw = this.drone.getNavDataHandler().getNavDataDemo().getYaw() - myYawInit;
    // System.out.println("leader :"+leaderYaw);
    // System.out.println("suiveur :"+myYaw);
    if (Math.abs(leaderYaw - myYaw) > 10) {
      if (leaderYaw * myYaw > 0) {
        this.drone.setSpeedYaw(
            (leaderYaw - myYaw)
                / Math.abs(leaderYaw - myYaw)
                * Math.min(Math.abs(leaderYaw - myYaw) / 30, 1));
      } else {
        if (myYaw < 0) {
          if (leaderYaw - myYaw < 360 - leaderYaw + myYaw) {
            this.drone.setSpeedYaw(Math.min(1, (leaderYaw - myYaw) / 30));
          } else {
            this.drone.setSpeedYaw(-Math.min(1, Math.abs(360 - leaderYaw + myYaw) / 30));
          }
        } else {
          if (-leaderYaw + myYaw < 360 + leaderYaw - myYaw) {
            this.drone.setSpeedYaw(-Math.min(1, (-leaderYaw + myYaw) / 30));
          } else {
            this.drone.setSpeedYaw(Math.min(1, Math.abs(360 + leaderYaw - myYaw) / 30));
          }
        }
      }

    } else {
      this.drone.setSpeedYaw(0);
    }
    // System.out.println("consigne yaw :"+this.drone.speedYaw);
  }
Esempio n. 5
0
  /**
   * Input W must be initialized to a nonzero vector, output is {U,V,W}, an orthonormal basis. A
   * hint is provided about whether or not W is already unit length.
   *
   * @param kU DOCUMENT ME!
   * @param kV DOCUMENT ME!
   * @param kW DOCUMENT ME!
   * @param bUnitLengthW DOCUMENT ME!
   */
  static void generateOrthonormalBasis(
      MjVector3f kU, MjVector3f kV, MjVector3f kW, boolean bUnitLengthW) {

    if (!bUnitLengthW) {
      kW.normalizeSafe();
    }

    float fInvLength;

    if (Math.abs(kW.x) >= Math.abs(kW.y)) {

      // W.x or W.z is the largest magnitude component, swap them
      fInvLength = 1.0f / (float) Math.sqrt((kW.x * kW.x) + (kW.z * kW.z));
      kU.x = -kW.z * fInvLength;
      kU.y = 0.0f;
      kU.z = +kW.x * fInvLength;
    } else {

      // W.y or W.z is the largest magnitude component, swap them
      fInvLength = 1.0f / (float) Math.sqrt((kW.y * kW.y) + (kW.z * kW.z));
      kU.x = 0.0f;
      kU.y = +kW.z * fInvLength;
      kU.z = -kW.y * fInvLength;
    }

    kV.cross(kW, kU);
  }
Esempio n. 6
0
 protected String getGramaticallyCorrectName(final Duration d, boolean round) {
   String result = getName();
   if ((Math.abs(getQuantity(d, round)) == 0) || (Math.abs(getQuantity(d, round)) > 1)) {
     result = getPluralName();
   }
   return result;
 }
Esempio n. 7
0
  @Override
  public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    /*boolean res = super.onFling(e1, e2, velocityX, velocityY);
    Log.i("OF","onFLing" + res);
    return res;*/

    final float xDistance = Math.abs(e1.getX() - e2.getX());
    final float yDistance = Math.abs(e1.getY() - e2.getY());

    if (xDistance > OFGestureListener.swipe_Max_Distance
        || yDistance > OFGestureListener.swipe_Max_Distance) return false;

    velocityX = Math.abs(velocityX);
    velocityY = Math.abs(velocityY);
    boolean result = false;

    if (velocityX > OFGestureListener.swipe_Min_Velocity
        && xDistance > OFGestureListener.swipe_Min_Distance) {
      if (e1.getX() > e2.getX()) // right to left
      OFAndroid.onSwipe(e1.getPointerId(0), SWIPE_LEFT);
      else OFAndroid.onSwipe(e1.getPointerId(0), SWIPE_RIGHT);

      result = true;
    } else if (velocityY > OFGestureListener.swipe_Min_Velocity
        && yDistance > OFGestureListener.swipe_Min_Distance) {
      if (e1.getY() > e2.getY()) // bottom to up
      OFAndroid.onSwipe(e1.getPointerId(0), SWIPE_UP);
      else OFAndroid.onSwipe(e1.getPointerId(0), SWIPE_DOWN);

      result = true;
    }

    return result;
  }
Esempio n. 8
0
 public static int manhattanDistance(int pos1, int pos2) {
   int x1 = pos1 / 5;
   int x2 = pos2 / 5;
   int y1 = pos1 % 5;
   int y2 = pos2 % 5;
   return Math.abs(x1 - x2) + Math.abs(y1 - y2);
 }
    @Override
    public boolean onFling(
        final MotionEvent pMotionEventStart,
        final MotionEvent pMotionEventEnd,
        final float pVelocityX,
        final float pVelocityY) {
      final float swipeMinDistance = this.mSwipeMinDistance;

      final boolean isHorizontalFling = Math.abs(pVelocityX) > Math.abs(pVelocityY);

      if (isHorizontalFling) {
        if (pMotionEventStart.getX() - pMotionEventEnd.getX() > swipeMinDistance) {
          return SurfaceGestureDetector.this.onSwipeLeft();
        } else if (pMotionEventEnd.getX() - pMotionEventStart.getX() > swipeMinDistance) {
          return SurfaceGestureDetector.this.onSwipeRight();
        }
      } else {
        if (pMotionEventStart.getY() - pMotionEventEnd.getY() > swipeMinDistance) {
          return SurfaceGestureDetector.this.onSwipeUp();
        } else if (pMotionEventEnd.getY() - pMotionEventStart.getY() > swipeMinDistance) {
          return SurfaceGestureDetector.this.onSwipeDown();
        }
      }

      return false;
    }
Esempio n. 10
0
  @Override
  public boolean esMovimientoValido(
      Posicion posicion, TableroControlador tableromodel, Tablero tablero) {

    int xTo = posicion.getX();
    int yTo = posicion.getY();

    Casilla casillaHasta = tableromodel.getCasilla(xTo, yTo);
    Pieza pieza2 = casillaHasta.getPieza();

    if (pieza2 != null) {
      if (esBlanca() == pieza2.esBlanca()) {
        tablero.mensaje("Pieza de tu mismo color...");
        return false;
      }
    }

    int mov = esBlanca ? -1 : 1;

    Casilla casillaTo = tableromodel.getCasilla(xTo, yTo);

    int yFr = pos.getY();
    int xFr = pos.getX();

    if ((xFr == xTo && (yFr + mov) == yTo) && casillaTo.getPieza() == null) return true;

    if (Math.abs(xFr - xTo) == 1 && (yTo - yFr) == mov && casillaTo.getPieza() != null) return true;

    if (((mov * -2.5) + 3.5) == yFr && Math.abs(yFr - yTo) == 2 && (xFr - xTo) == 0) return true;

    return false;
  }
Esempio n. 11
0
  public void update(float x, float y) {
    float actSlopeX, actSlopeY;

    if (x > prevX) actSlopeX = 10;
    else actSlopeX = -10;
    if (y > prevY) actSlopeY = 10;
    else actSlopeY = -10;
    // actSlopeX = x - prevX;
    // actSlopeY = y - prevY;
    xAcum += Math.abs(x - inX);
    yAcum += Math.abs(y - inY);
    n += 1;
    prevX = x;
    prevY = y;
    if (stable) {
      bufferX.add(actSlopeX);
      bufferY.add(actSlopeY);
      if (bufferX.size() >= sizeMax) {
        avSlope(x, y);
        bufferX.remove(0);
        bufferY.remove(0);
      }
    } else {
      stable = true;
    }
  }
 public void move() {
   if (Math.random() > 0.5) {
     // normal swarm behaviour
     double w = 0.509844, c1 = 2, c2 = 2;
     for (int i = 0; i < swarm.noOfDimensions; i++) {
       vX.set(
           i,
           w * vX.get(i)
               + c1 * Math.random() * (pX.get(i) - X.get(i))
               + c2 * Math.random() * (gX.get(i) - X.get(i)));
       if (vX.get(i) > vmaxX.get(i)) vX.set(i, vmaxX.get(i));
       X.set(i, X.get(i) + vX.get(i));
       if (X.get(i) > pmaxX.get(i)) X.set(i, pmaxX.get(i) * Math.random());
       if (X.get(i) < pminX.get(i))
         X.set(i, pminX.get(i) + Math.abs(pminX.get(i) * Math.random()));
     }
   } else {
     // stray particles(distracted)
     double w = 0.909844, c1 = 2.4, c2 = 0;
     for (int i = 0; i < swarm.noOfDimensions; i++) {
       vX.set(
           i,
           w * vX.get(i)
               + c1 * Math.random() * (pX.get(i) - X.get(i))
               + c2 * Math.random() * (gX.get(i) - X.get(i)));
       if (vX.get(i) > vmaxX.get(i)) vX.set(i, vmaxX.get(i));
       X.set(i, X.get(i) + vX.get(i));
       if (X.get(i) > pmaxX.get(i)) X.set(i, pmaxX.get(i) * Math.random());
       if (X.get(i) < pminX.get(i))
         X.set(i, pminX.get(i) + Math.abs(pminX.get(i) * Math.random()));
     }
   }
 }
Esempio n. 13
0
  @Override
  public void j_() {
    super.j_();
    if (npc == null) return;
    boolean navigating = npc.getNavigator().isNavigating();
    updatePackets(navigating);
    if (gravity
        && !navigating
        && getBukkitEntity() != null
        && Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))
        && !NMS.inWater(getBukkitEntity())) {
      move(0, -0.2, 0);
      // gravity. also works around an entity.onGround not updating issue
      // (onGround is normally updated by the client)
    }
    if (!npc.data().get("removefromplayerlist", true)) g();
    if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON)
      motX = motY = motZ = 0;

    NMS.updateSenses(this);
    if (navigating) {
      Navigation navigation = getNavigation();
      if (!navigation.f()) navigation.e();
      moveOnCurrentHeading();
    } else if (motX != 0 || motZ != 0 || motY != 0) {
      e(0, 0); // is this necessary? it does controllable but sometimes
      // players sink into the ground
    }

    if (noDamageTicks > 0) --noDamageTicks;
    npc.update();
  }
Esempio n. 14
0
  /**
   * 获取旋转某个角度之后的点
   *
   * @param viewCenter
   * @param source
   * @param degree
   * @return
   */
  public static PointF obtainRoationPoint(PointF center, PointF source, float degree) {
    // 两者之间的距离
    PointF disPoint = new PointF();
    disPoint.x = source.x - center.x;
    disPoint.y = source.y - center.y;

    // 没旋转之前的弧度
    double originRadian = 0;

    // 没旋转之前的角度
    double originDegree = 0;

    // 旋转之后的角度
    double resultDegree = 0;

    // 旋转之后的弧度
    double resultRadian = 0;

    // 经过旋转之后点的坐标
    PointF resultPoint = new PointF();

    double distance = Math.sqrt(disPoint.x * disPoint.x + disPoint.y * disPoint.y);
    if (disPoint.x == 0 && disPoint.y == 0) {
      return center;
      // 第一象限
    } else if (disPoint.x >= 0 && disPoint.y >= 0) {
      // 计算与x正方向的夹角
      originRadian = Math.asin(disPoint.y / distance);

      // 第二象限
    } else if (disPoint.x < 0 && disPoint.y >= 0) {
      // 计算与x正方向的夹角
      originRadian = Math.asin(Math.abs(disPoint.x) / distance);
      originRadian = originRadian + Math.PI / 2;

      // 第三象限
    } else if (disPoint.x < 0 && disPoint.y < 0) {
      // 计算与x正方向的夹角
      originRadian = Math.asin(Math.abs(disPoint.y) / distance);
      originRadian = originRadian + Math.PI;
    } else if (disPoint.x >= 0 && disPoint.y < 0) {
      // 计算与x正方向的夹角
      originRadian = Math.asin(disPoint.x / distance);
      originRadian = originRadian + Math.PI * 3 / 2;
    }

    // 弧度换算成角度
    originDegree = radianToDegree(originRadian);
    resultDegree = originDegree + degree;

    // 角度转弧度
    resultRadian = degreeToRadian(resultDegree);

    resultPoint.x = (int) Math.round(distance * Math.cos(resultRadian));
    resultPoint.y = (int) Math.round(distance * Math.sin(resultRadian));
    resultPoint.x += center.x;
    resultPoint.y += center.y;

    return resultPoint;
  }
Esempio n. 15
0
  /** Reads the entity from NBT (calls an abstract helper method to read specialized data) */
  public void readFromNBT(NBTTagCompound par1NBTTagCompound) {
    NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Pos");
    NBTTagList nbttaglist1 = par1NBTTagCompound.getTagList("Motion");
    NBTTagList nbttaglist2 = par1NBTTagCompound.getTagList("Rotation");
    motionX = ((NBTTagDouble) nbttaglist1.tagAt(0)).data;
    motionY = ((NBTTagDouble) nbttaglist1.tagAt(1)).data;
    motionZ = ((NBTTagDouble) nbttaglist1.tagAt(2)).data;

    if (Math.abs(motionX) > 10D) {
      motionX = 0.0D;
    }

    if (Math.abs(motionY) > 10D) {
      motionY = 0.0D;
    }

    if (Math.abs(motionZ) > 10D) {
      motionZ = 0.0D;
    }

    prevPosX = lastTickPosX = posX = ((NBTTagDouble) nbttaglist.tagAt(0)).data;
    prevPosY = lastTickPosY = posY = ((NBTTagDouble) nbttaglist.tagAt(1)).data;
    prevPosZ = lastTickPosZ = posZ = ((NBTTagDouble) nbttaglist.tagAt(2)).data;
    prevRotationYaw = rotationYaw = ((NBTTagFloat) nbttaglist2.tagAt(0)).data;
    prevRotationPitch = rotationPitch = ((NBTTagFloat) nbttaglist2.tagAt(1)).data;
    fallDistance = par1NBTTagCompound.getFloat("FallDistance");
    fire = par1NBTTagCompound.getShort("Fire");
    setAir(par1NBTTagCompound.getShort("Air"));
    onGround = par1NBTTagCompound.getBoolean("OnGround");
    setPosition(posX, posY, posZ);
    setRotation(rotationYaw, rotationPitch);
    readEntityFromNBT(par1NBTTagCompound);
  }
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    // Read in the number of elements
    int n = in.nextInt();

    // Store the list of cities in an array
    int[] cities = new int[n];
    for (int i = 0; i < n; i++) {
      cities[i] = in.nextInt();
    }

    // Since the list is in ascending order (as specified in the problem
    // statement), the minimum difference will be to either the left or right
    // of the element, and the maximum will either be to the first or last
    // element
    for (int i = 0; i < n; i++) {
      int left = Integer.MAX_VALUE;
      int right = Integer.MAX_VALUE;
      if (i > 0) {
        left = Math.abs(cities[i] - cities[i - 1]);
      }
      if (i < n - 1) {
        right = Math.abs(cities[i] - cities[i + 1]);
      }
      int min = Math.min(left, right);

      left = Math.abs(cities[i] - cities[0]);
      right = Math.abs(cities[i] - cities[n - 1]);
      int max = Math.max(left, right);

      System.out.println(min + " " + max);
    }
  }
Esempio n. 17
0
  /**
   * Calculates the square root of this object. Adapted from Numerical Recipes in C - The Art of
   * Scientific Computing (ISBN 0-521-43108-5)
   */
  public Complex sqrt() {
    Complex c;
    double absRe, absIm, w, r;

    if (re == 0 && im == 0) {
      c = new Complex(0, 0);
    } else {
      absRe = Math.abs(re);
      absIm = Math.abs(im);

      if (absRe >= absIm) {
        r = absIm / absRe;
        w = Math.sqrt(absRe) * Math.sqrt(0.5 * (1.0 + Math.sqrt(1.0 + r * r)));
      } else {
        r = absRe / absIm;
        w = Math.sqrt(absIm) * Math.sqrt(0.5 * (r + Math.sqrt(1.0 + r * r)));
      }

      if (re >= 0) {
        c = new Complex(w, im / (2.0 * w));
      } else {
        if (im < 0) w = -w;
        c = new Complex(im / (2.0 * w), w);
      }
    }

    return c;
  }
 public boolean contains(int x, int y) {
   if ((Math.abs(this.getCurrentPertubatedX() - x) < 3)
       && (Math.abs(this.getCurrentPertubatedY() - y) < 3)) {
     return true;
   }
   return false;
 }
Esempio n. 19
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    int action = event.getActionMasked();
    int P = event.getPointerCount();
    // int N = event.getHistorySize();
    if (action != MotionEvent.ACTION_MOVE) {
      if (action == MotionEvent.ACTION_DOWN) {
        // startX = mCurX * mScale; // event.getX();
        // startY = mCurY * mScale; // event.getY();
        sX1 = mCurX * mScale - event.getX(0);
        sY1 = mCurY * mScale - event.getY(0);
        return true;
      }
      if (action == MotionEvent.ACTION_POINTER_DOWN) {
        // Toast.makeText(mContext,
        // Float.toString(sX1)+"apd",
        // Toast.LENGTH_SHORT).show();

        if (P == 2) {
          float sX2 = event.getX(0) - event.getX(1);
          float sY2 = event.getY(0) - event.getY(1);
          sD = (float) Math.sqrt(sX2 * sX2 + sY2 * sY2);
          mBitmapViewWidthInitial = mBitmapViewWidth;
          return true;
        } else if (P == 3) {
          sMx = (float) mCenterX - event.getX(2);
          sMy = (float) mCenterY - event.getY(2);
          return true;
        }
        return false;
      }
    } else {
      if (P == 1) {
        float a = Math.abs(sX1 + event.getX()) % mX;
        float b = Math.abs(sY1 + event.getY()) % mY;
        mCurX = (int) (a / mScale); // *(int)(event.getHistoricalX(0)-event.getHistoricalX(1));
        mCurY = (int) (b / mScale); // *(int)(event.getHistoricalY(0)-event.getHistoricalY(1));
      } else if (P == 2) {
        float sX2 = event.getX(0) - event.getX(1);
        float sY2 = event.getY(0) - event.getY(1);
        float sD2 = (float) Math.sqrt(sX2 * sX2 + sY2 * sY2);

        int r = mBitmapViewWidthInitial + Math.round(sD2 - sD);
        if (r < mScreenRadius) r = mScreenRadius;
        setViewBitmapSizes(r);
      } else if (P == 3) {
        mCenterX = (int) (sMx + event.getX(2));
        mCenterY = (int) (sMy + event.getY(2));
      } else {
        return false;
      }

      drawIntoBitmap();
      invalidate();
      if (use3D) {
        updateTexture();
      }
    }
    return true;
  }
Esempio n. 20
0
  private float avSlope(float x, float y) {

    float slopeX = 0, slopeY = 0;
    float sSlopeX = 0, sSlopeY = 0;
    boolean update = false;

    for (float bX : bufferX) {
      sSlopeX += signum(bX);
      slopeX += Math.abs(bX);
    }
    for (float bY : bufferY) {
      sSlopeY += signum(bY);
      slopeY += Math.abs(bY);
    }
    slopeX = signum(sSlopeX) * (slopeX / bufferX.size());
    slopeY = signum(sSlopeY) * (slopeY / bufferY.size());
    if (stable2) {
      if (signum(bufferSX.get(bufferSX.size() - 1)) != signum(slopeX)) {
        if (xAcum > 300 || yAcum > 300) {
          bufferSX.add(slopeX);
          bufferSY.add(slopeY);
          bufferAX.add(xAcum);
          bufferAY.add(yAcum);
          bufferLines.add(toLines(inX, inY, x, y, n));
          update = true;
        }
      }
      if (signum(bufferSY.get(bufferSY.size() - 1)) != signum(slopeY)) {
        if (xAcum > 300 || yAcum > 300) {
          bufferSX.add(slopeX);
          bufferSY.add(slopeY);
          bufferAX.add(xAcum);
          bufferAY.add(yAcum);
          if (!update) {
            bufferLines.add(toLines(inX, inY, x, y, n));
            update = true;
          }
        }
      }
    } else {
      bufferSX.add(slopeX);
      bufferSY.add(slopeY);
      bufferAX.add(xAcum);
      bufferAY.add(yAcum);
      bufferLines.add(toLines(inX, inY, x, y, n));
      update = true;
      stable2 = true;
    }
    if (update) {
      xAcum = 0;
      yAcum = 0;
      n = 0;
      inX = x;
      inY = y;
      //	Log.i("ººººººººººººººººººººººº","ººººººººººººººººººººººº");
      //	Log.i("-----------------------","-----------------------");
      //	Log.i("ººººººººººººººººººººººº","ººººººººººººººººººººººº");
    }
    return 1;
  }
  /**
   * Determine the closest coordinate of the opponents base that the robot should travel to,
   *
   * @return closest opponent base coordinate to robot starting location
   */
  private void determineClosestOpponentBaseCoordinate() {

    double currentDistance = 1000;
    closestOpponentBaseCoordinate = null;
    for (Coordinate coordinate :
        new Coordinate[] {
          opponentBaseCoordinate_BL,
          opponentBaseCoordinate_TR,
          opponentBaseCoordinate_TL,
          opponentBaseCoordinate_BR
        }) {
      // added this so the algorithm doesn't consider the coordinates close to the wall (close
      // meaning 1 tile or less away from wall)
      if (coordinate.getX() < 1 * tileLength
          || coordinate.getX() > 9 * tileLength
          || coordinate.getY() < 1 * tileLength
          || coordinate.getY() > 9 * tileLength) continue;

      double deltaX = Math.abs(coordinate.getX() - startingCoordinate.getX());
      double deltaY = Math.abs(coordinate.getY() - startingCoordinate.getY());

      double distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
      if (distance < currentDistance) {
        currentDistance = distance;
        closestOpponentBaseCoordinate = coordinate;
      }
    }

    if (closestOpponentBaseCoordinate == null)
      throw new NullPointerException("Could not determine closest opponent base coordinate");
  }
Esempio n. 22
0
  /**
   * Perform some sanity checks on the integration parameters.
   *
   * @param equations differential equations set
   * @param t0 start time
   * @param y0 state vector at t0
   * @param t target time for the integration
   * @param y placeholder where to put the state vector
   * @exception IntegratorException if some inconsistency is detected
   */
  protected void sanityChecks(
      final FirstOrderDifferentialEquations equations,
      final double t0,
      final double[] y0,
      final double t,
      final double[] y)
      throws IntegratorException {

    if (equations.getDimension() != y0.length) {
      throw new IntegratorException(
          "dimensions mismatch: ODE problem has dimension {0},"
              + " initial state vector has dimension {1}",
          new Object[] {Integer.valueOf(equations.getDimension()), Integer.valueOf(y0.length)});
    }

    if (equations.getDimension() != y.length) {
      throw new IntegratorException(
          "dimensions mismatch: ODE problem has dimension {0},"
              + " final state vector has dimension {1}",
          new Object[] {Integer.valueOf(equations.getDimension()), Integer.valueOf(y.length)});
    }

    if (Math.abs(t - t0) <= 1.0e-12 * Math.max(Math.abs(t0), Math.abs(t))) {
      throw new IntegratorException(
          "too small integration interval: length = {0}",
          new Object[] {Double.valueOf(Math.abs(t - t0))});
    }
  }
Esempio n. 23
0
  public void movePlayer(Touchpad touchpad) {
    float touchX = touchpad.getKnobPercentX();
    float touchY = touchpad.getKnobPercentY();

    if (touchX < -0.1 && touchX < -Math.abs(touchY)) {
      spriteVector.y = 0;
      spriteVector.x = -SPRITE_SPEED;
      spriteDirection = SpriteDirection.e;
    } else if (touchX > 0.1 && touchX > Math.abs(touchY)) {
      spriteVector.y = 0;
      spriteVector.x = SPRITE_SPEED;
      spriteDirection = SpriteDirection.w;
    } else if (touchY < -0.1 && touchY <= -Math.abs(touchX)) {
      spriteVector.x = 0;
      spriteVector.y = -SPRITE_SPEED;
      spriteDirection = SpriteDirection.s;
    } else if (touchY > 0.1 && touchY >= Math.abs(touchX)) {
      spriteVector.x = 0;
      spriteVector.y = SPRITE_SPEED;
      spriteDirection = SpriteDirection.n;
    } else if (touchX <= 0.1 && touchX >= -0.1 && touchY <= 0.1 && touchY >= -0.1) {
      spriteVector.x = 0;
      spriteVector.y = 0;
    }

    if (spriteVector.x == 0 && spriteVector.y == 0) spriteState = State.Idle;
    else spriteState = State.Walking;
  }
Esempio n. 24
0
 private void generateHugeRoundMushroom(World world, int x, int y, int z) {
   final int capYStart = totalHeight + y + 1 - capThickness;
   byte capSize = capRadius;
   for (int yy = capYStart; yy < y + 1 + totalHeight; yy++) { // generate cap
     if (yy == y + totalHeight) {
       capSize--;
     }
     for (int xx = x - capSize; xx < x + 1 + capSize; xx++) {
       for (int zz = z - capSize; zz < z + 1 + capSize; zz++) {
         if (yy != y + totalHeight) {
           int xDif = Math.abs(x - xx);
           int zDif = Math.abs(z - zz);
           if ((xDif < capSize && zDif < capSize) || (xDif == capSize && zDif == capSize)) {
             continue;
           }
         }
         final short data;
         if (useTextureMetadata) {
           data = getRoundMushroomCapData(x, y, z, xx, yy, zz, totalHeight, capSize);
         } else {
           data = 0;
         }
         world.setBlockMaterial(xx, yy, zz, capMaterial, data, null);
       }
     }
   }
   final short data = useTextureMetadata ? (short) 10 : (short) 0;
   for (int yy = y; yy < totalHeight + y; yy++) { // generate stem
     world.setBlockMaterial(x, yy, z, stemMaterial, data, null);
   }
 }
  @Override
  public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {

    final int x1 = (int) e1.getX();
    final int y1 = (int) e1.getY();
    final int x2 = (int) e2.getX();
    final int y2 = (int) e2.getY();
    final int deltaX = x2 - mItemX;
    final int deltaY = y2 - mItemY;

    if (mCanDrag && !mDragging && (mHitPos != MISS || mFlingHitPos != MISS)) {
      if (mHitPos != MISS) {
        if (mDragInitMode == ON_DRAG && Math.abs(y2 - y1) > mTouchSlop && mSortEnabled) {
          startDrag(mHitPos, deltaX, deltaY);
        } else if (mDragInitMode != ON_DOWN && Math.abs(x2 - x1) > mTouchSlop && mRemoveEnabled) {
          mIsRemoving = true;
          startDrag(mFlingHitPos, deltaX, deltaY);
        }
      } else if (mFlingHitPos != MISS) {
        if (Math.abs(x2 - x1) > mTouchSlop && mRemoveEnabled) {
          mIsRemoving = true;
          startDrag(mFlingHitPos, deltaX, deltaY);
        } else if (Math.abs(y2 - y1) > mTouchSlop) {
          mCanDrag = false; // if started to scroll the list then
          // don't allow sorting nor fling-removing
        }
      }
    }
    // return whatever
    return false;
  }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    Log.e("mcoy", "McoyScrollView--onInterceptTouchEvent");
    switch (ev.getAction()) {
      case MotionEvent.ACTION_DOWN:
        xDistance = yDistance = 0f;
        xLast = ev.getX();
        yLast = ev.getY();
        break;
      case MotionEvent.ACTION_MOVE:
        final float curX = ev.getX();
        final float curY = ev.getY();

        xDistance += Math.abs(curX - xLast);
        yDistance += Math.abs(curY - yLast);
        xLast = curX;
        yLast = curY;

        if (xDistance > yDistance) {
          return false;
        }
    }
    boolean onIntercept = super.onInterceptTouchEvent(ev);
    Log.e("mcoy", "McoyScrollView--onInterceptTouchEvent return " + onIntercept);

    return onIntercept;
  }
Esempio n. 27
0
 @Override
 public Drawable getItemAt(double x, double y) {
   final double realradius = ENDNODEOUTERRADIUS + (ENDNODEOUTERSTROKEWIDTH / 2);
   return ((Math.abs(x - getX()) <= realradius) && (Math.abs(y - getY()) <= realradius))
       ? this
       : null;
 }
Esempio n. 28
0
  /*
     public Unit[] cantarget (Unit x){

  int xdiff = Math.abs((x.getxcoord() - y.getxcoord()));
  int ydiff = Math.abs((x.getycoord() - y.getycoord()));
  int diff = xdiff + ydiff;


     }
     */
  public void attack(Unit x, Unit y) {
    int xdiff = Math.abs((x.getxcoord() - y.getxcoord()));
    int ydiff = Math.abs((x.getycoord() - y.getycoord()));
    int diff = xdiff + ydiff;
    if (diff <= x.getmaxrange() && diff >= x.getminrange()) {
      String type1 = x.getgoodagainst();
      String type2 = y.gettiretype();
      int troops = x.getHP();
      int dmg = x.getAttack();
      int block = y.getDefense() + Board[y.getxcoord()][y.getycoord()].getTerrain().getdefenseinc();
      if (type1.equals(type2)) {
        if (type1.equals("Foot")) {
          dmg += 1;
        }
        if (type1.equals("Tank")) {
          dmg *= 2;
        }
        if (type1.equals("Air")) {
          dmg += 4;
        }
      }
      dmg -= 10 - troops;
      int dmgdealt = dmg - block;
      if (dmgdealt > 0) {
        y.setHP(y.getHP() - dmg);
      }
      x.setmoved(true);
    } else {
      System.out.println("Unit not in Range");
    }
  }
Esempio n. 29
0
    public void onLocationChanged(Location location) {

      String message =
          String.format(
              "New Location \n Longitude: %1$s \n Latitude: %2$s",
              location.getLongitude(), location.getLatitude());
      Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
      if (Math.abs(oldlat - location.getLatitude()) + Math.abs(oldlong - location.getLongitude())
          > 0) ;
      oldlat = location.getLatitude();
      oldlong = location.getLongitude();

      dbh.addPlace(oldlat, oldlong, 2.2);
      Toast.makeText(MainActivity.this, "Newer", Toast.LENGTH_LONG).show();
      List<location> contacts = dbh.getAllplaces();
      location newc = new location();
      newc.setlong("6.9");
      newc.setlat("9.6");
      newc.ID = 5;
      newc.radius = 2.0;
      dbh.deleteplace(newc);
      for (location cn : contacts) {
        Toast.makeText(MainActivity.this, "" + cn.getlat(), Toast.LENGTH_LONG).show();
      }
    }
Esempio n. 30
0
  /**
   * Method that calculates how much a node overlaps with another node
   *
   * @param node1
   * @param node2
   * @return The size of the overlapping area
   */
  public double overlap(ProxyNode node1, ProxyNode node2) {
    // Check if both nodes are close enough in the x-dimension to overlap
    double X1 = node1.getPlacementX();
    double X2 = node2.getPlacementX();
    double width1 = node1.width / 2;
    double width2 = node2.width / 2;
    double distX = Math.abs(X1 - X2);
    double minDistX = width1 + width2;

    if (distX < minDistX) {
      // Check if both nodes are close enough in the y-dimension to overlap
      double Y1 = node1.getPlacementY();
      double Y2 = node2.getPlacementY();
      double height1 = node1.height / 2;
      double height2 = node2.height / 2;
      double distY = Math.abs(Y1 - Y2);
      double minDistY = height1 + height2;

      if (distY < minDistY) {
        double minX1 = X1 - width1;
        double minX2 = X2 - width2;
        double maxX1 = X1 + width1;
        double maxX2 = X2 + width2;
        double minY1 = Y1 - height1;
        double minY2 = Y2 - height2;
        double maxY1 = Y1 + height1;
        double maxY2 = Y2 + height2;

        return (Math.min(maxX2, maxX1) - Math.max(minX1, minX2))
            * (Math.min(maxY2, maxY1) - Math.max(minY1, minY2));
      }
    }

    return 0;
  }