public void isChased(double xClick, double yClick) {

    ySpeed = (y - yClick) / Math.hypot(x - xClick, y - yClick) * 4;
    risingTickY = 50;
    tickNeedY = risingTickY;
    speedAddY = ySpeed / risingTickY;

    speedRisingY = false;
    stableY = false;
    tickCountY = 0;

    xSpeed = (x - xClick) / Math.hypot(x - xClick, y - yClick) * 4;
    risingTickX = 50;
    tickNeedX = risingTickX;
    speedAddX = xSpeed / risingTickX;

    speedRisingX = false;
    stableX = false;
    tickCountX = 0;
    if (speedAddX > 0) {
      isLeft = false;
    } else {
      isLeft = true;
    }
  }
Esempio n. 2
0
 static double getAngle(double x1, double y1, double x3, double y3, double x2, double y2) {
   double r13 = Math.hypot(x3 - x1, y3 - y1);
   double r23 = Math.hypot(x2 - x3, y2 - y3);
   double t = ((x3 - x1) * (x2 - x3) + (y3 - y1) * (y2 - y3)) / (r13 * r23);
   return (x1 - x3) * (y2 - y3) - (y1 - y3) * (x2 - x3) < 0
       ? Math.PI - Math.acos(t)
       : Math.acos(t) - Math.PI;
 }
Esempio n. 3
0
 @Override
 public int compare(Point o1, Point o2) {
   double d1 = Math.hypot(o1.y - p.y, o1.x - p.x);
   double d2 = Math.hypot(o2.y - p.y, o2.x - p.x);
   if (isCollin(p, o1, o2)) return d1 < d2 ? -1 : d1 > d2 ? 1 : 0;
   double a1 = Math.atan2(o1.y - p.y, o1.x - p.x);
   double a2 = Math.atan2(o2.y - p.y, o2.x - p.x);
   return a1 < a2 ? -1 : a1 > a2 ? 1 : 0;
 }
Esempio n. 4
0
 static double getAngle(Atom a1, Atom a3, Atom a2) {
   double r13 = Math.hypot(a3.rx - a1.rx, a3.ry - a1.ry);
   double r23 = Math.hypot(a2.rx - a3.rx, a2.ry - a3.ry);
   double t =
       ((a3.rx - a1.rx) * (a2.rx - a3.rx) + (a3.ry - a1.ry) * (a2.ry - a3.ry)) / (r13 * r23);
   return (a1.rx - a3.rx) * (a2.ry - a3.ry) - (a1.ry - a3.ry) * (a2.rx - a3.rx) < 0
       ? Math.PI - Math.acos(t)
       : Math.acos(t) - Math.PI;
 }
Esempio n. 5
0
 boolean isParallel(Line l, Line m) {
   Point a = new Point(l.t.x - l.s.x, l.t.y - l.s.y);
   Point b = new Point(m.t.x - m.s.x, m.t.y - m.s.y);
   if (Math.abs(
           Math.abs((a.x * b.x + a.y * b.y) / (Math.hypot(a.x, a.y) * Math.hypot(b.x, b.y)) - 1))
       < EPS) {
     return true;
   }
   return false;
 }
Esempio n. 6
0
 /** Modfified funclion from LakeWalker Gets distance from point p1 to line p2-p3 */
 public double pointLineDistance(Point p1, Point p2, Point p3) {
   double x0 = p1.x;
   double y0 = p1.y;
   double x1 = p2.x;
   double y1 = p2.y;
   double x2 = p3.x;
   double y2 = p3.y;
   if (x2 == x1 && y2 == y1) {
     return Math.hypot(x1 - x0, y1 - y0);
   } else {
     return Math.abs((x2 - x1) * (y1 - y0) - (x1 - x0) * (y2 - y1)) / Math.hypot(x2 - x1, y2 - y1);
   }
 }
 /** Gets the scale */
 public float getScale() {
   if (mDetector.getCount() < 2) {
     return 1;
   } else {
     float startDeltaX = mDetector.getStartX()[1] - mDetector.getStartX()[0];
     float startDeltaY = mDetector.getStartY()[1] - mDetector.getStartY()[0];
     float currentDeltaX = mDetector.getCurrentX()[1] - mDetector.getCurrentX()[0];
     float currentDeltaY = mDetector.getCurrentY()[1] - mDetector.getCurrentY()[0];
     float startDist = (float) Math.hypot(startDeltaX, startDeltaY);
     float currentDist = (float) Math.hypot(currentDeltaX, currentDeltaY);
     return currentDist / startDist;
   }
 }
Esempio n. 8
0
  public static PyObject _pow(PyComplex value, PyComplex right) {
    double xr = value.real;
    double xi = value.imag;
    double yr = right.real;
    double yi = right.imag;

    if (yr == 0 && yi == 0) {
      return new PyComplex(1, 0);
    }

    if (xr == 0 && xi == 0) {
      if (yi != 0 || yr < 0) {
        throw Py.ZeroDivisionError("0.0 to a negative or complex power");
      }
    }

    // Check for integral powers
    int iexp = (int) yr;
    if (yi == 0 && yr == iexp && iexp >= -128 && iexp <= 128) {
      return ipow(value, iexp);
    }

    double abs = Math.hypot(xr, xi);
    double len = Math.pow(abs, yr);

    double at = Math.atan2(xi, xr);
    double phase = at * yr;
    if (yi != 0) {
      len /= Math.exp(at * yi);
      phase += yi * Math.log(abs);
    }
    return new PyComplex(len * Math.cos(phase), len * Math.sin(phase));
  }
Esempio n. 9
0
    /**
     * Gets whether or not this sensor senses a Pedestrian.
     *
     * @param tileMap the PedestrianTileBasedMap to use, to get the TileState, and the resulting
     *     list of Pedestrians in that tile
     * @return true if a Pedestrian is detected, false otherwise.
     */
    public MovingEntity relativePointSensesEntity(GameMap map) {

      MovingEntity entitySensed = null;

      // Get the point of the entity that may encounter an obstacle
      Point2D.Float relativePoint = this.entity.getRelativePointFromCenter(rx, ry);

      // Get the tile this point is in
      Tile tileSensed =
          map.getTile(
              (int) (relativePoint.x / GameMap.TILE_SIZE),
              (int) (relativePoint.y / GameMap.TILE_SIZE));

      // Search for an entity in this tile
      if (tileSensed != null) {
        LinkedList<Entity> entities = tileSensed.getEntities();

        for (Entity e : entities) {
          if (Math.hypot(relativePoint.x - e.getX(), relativePoint.y - e.getX()) <= SENSOR_RADIUS) {
            entitySensed = (MovingEntity) e;
            break;
          }
        }
      }

      return entitySensed;
    }
Esempio n. 10
0
 @Override
 public boolean collideWith(ScreenObject object) {
   return Math.hypot(
           this.x + this.getImage().getWidth() / 2 - object.x,
           this.y + this.getImage().getHeight() / 2 - object.y)
       <= this.getImage().getWidth() / 2 + object.getImage().getWidth() / 2;
 }
 float getSpan(MotionEvent aEvent) {
   final float x0 = aEvent.getX(0);
   final float x1 = aEvent.getX(1);
   final float y0 = aEvent.getY(0);
   final float y1 = aEvent.getY(1);
   return (float) Math.hypot(x1 - x0, y1 - y0);
 }
Esempio n. 12
0
 private double pointSegmentDistance(Point p, Point p1, Point p2) {
   double a, b, x, y, l, h, kt, kn, dist;
   x = p.x - p1.x;
   y = p.y - p1.y;
   a = p2.x - p1.x;
   b = p2.y - p1.y;
   l = Math.hypot(a, b);
   if (l == 0) return Math.hypot(x, y); // p1 = p2
   kt = (x * a + y * b) / l;
   kn = Math.abs((-x * b + y * a) / l);
   if (kt >= 0 && kt < l) dist = kn;
   else {
     dist = Math.min(Math.hypot(x, y), Math.hypot(x - a, y - b));
   }
   return dist;
 }
  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);

    centerX = w / 2;
    centerY = h / 2;

    // Make reference line long enough to cross the bounds diagonally after being rotated.
    referenceLine.reset();
    float radius = (float) Math.hypot(centerX, centerY);
    float delta = radius - centerX;
    referenceLine.moveTo(-delta, centerY);
    referenceLine.lineTo(getWidth() + delta, centerY);
    delta = radius - centerY;
    referenceLine.moveTo(centerX, -delta);
    referenceLine.lineTo(centerX, getHeight() + delta);

    // Set grids inside photo display bounds.
    grids.reset();
    delta = displayBounds.width() / 4.0f;
    for (float x = displayBounds.left + delta; x < displayBounds.right; x += delta) {
      grids.moveTo(x, displayBounds.top);
      grids.lineTo(x, displayBounds.bottom);
    }
    delta = displayBounds.height() / 4.0f;
    for (float y = displayBounds.top + delta; y < displayBounds.bottom; y += delta) {
      grids.moveTo(displayBounds.left, y);
      grids.lineTo(displayBounds.right, y);
    }
  }
Esempio n. 14
0
  public void moveInDirection(CGPoint direction, double timeInterval) {
    CGPoint curPosition = getPosition();
    double dx = movementSpeed * direction.getX();
    double dy = movementSpeed * direction.getY();
    double dt = movementSpeed * timeInterval;

    CGPoint targetPosition = new CGPoint(curPosition.getX() + dx, curPosition.getY() + dy);

    double ang =
        APAUtils.polarAdjust(APAUtils.getRadiansBetweenPoints(targetPosition, curPosition));
    setZRotation(ang);

    double distRemaining = Math.hypot(dx, dy);
    if (distRemaining < dt) {
      setPosition(targetPosition);
    } else {
      setPosition(
          new CGPoint(
              curPosition.getX() - Math.sin(ang) * dt, curPosition.getY() + Math.cos(ang) * dt));
    }

    // Don't change to a walk animation if we planning an attack.
    if (!attacking) {
      requestedAnimation = APAAnimationState.Walk;
    }
  }
  private void moveCameraForward(double distance) {
    double angleXY = Math.atan2(camY - fixY, camX - fixX);
    double angleZ = Math.atan2(camZ - fixZ, Math.hypot(camY - fixY, camX - fixX));

    double distXY = distance * Math.cos(angleZ);

    camX += distXY * Math.cos(angleXY);
    camY += distXY * Math.sin(angleXY);
    camZ += distance * Math.sin(angleZ);

    if (Math.sqrt(Math.pow(camX - fixX, 2) + Math.pow(camY - fixY, 2) + Math.pow(camY - fixY, 2))
        < 1) {
      fixX += distXY * Math.cos(angleXY);
      fixY += distXY * Math.sin(angleXY);
      fixZ += distance * Math.sin(angleZ);
    }

    // Vector3d v3d = new Vector3d(camX - fixX, camY - fixY, camZ - fixZ);
    //
    // Vector3d offsetVec = new Vector3d(v3d);
    //
    //// offsetVec.normalize();
    // offsetVec.scale(distance * zoom_factor);
    //
    //// if (offsetVec.length() < v3d.length())
    //// {
    // if (!isDolly || (!isDollyX &&!isDollyY))
    // {
    // camX += offsetVec.x;
    // camY += offsetVec.y;
    // }
    //
    // if (!isDolly ||!isDollyZ)
    // camZ += offsetVec.z;
  }
  /* Calculates the ForceVector on node against every other node represented
   * in the tree with respect to force.
   */
  public ForceVector calculateForce(double x, double y, QuadTree tree) {
    if (tree.mass() <= 0) {
      return null;
    }

    double distance = (double) Math.hypot(x - tree.x(), y - tree.y());

    if (tree.isIsLeaf() || tree.mass() == 1) {
      // this is probably the case where tree has only the node.
      if (distance < 1e-8) {
        return null;
      }
      return force.calculateForce(x, y, tree.x(), tree.y());
    }

    if (distance * theta > tree.size()) {
      ForceVector f = force.calculateForce(x, y, tree.x(), tree.y(), distance);
      f.multiply(tree.mass());
      return f;
    }

    ForceVector f = new ForceVector();
    for (QuadTree child : tree.getChildren()) {
      f.add(calculateForce(x, y, child));
    }
    return f;
  }
Esempio n. 17
0
  @Override
  public boolean mousePressed(int x, int y, int trackPosition) {
    if (sliderClickedInitial) // first circle already processed
    return false;

    double distance = Math.hypot(this.x - x, this.y - y);
    if (distance < diameter / 2) {
      int timeDiff = Math.abs(trackPosition - hitObject.getTime());
      int[] hitResultOffset = game.getHitResultOffsets();

      int result = -1;
      if (timeDiff < hitResultOffset[GameData.HIT_50]) {
        result = GameData.HIT_SLIDER30;
        ticksHit++;
      } else if (timeDiff < hitResultOffset[GameData.HIT_MISS]) result = GameData.HIT_MISS;
      // else not a hit

      if (result > -1) {
        data.addHitError(hitObject.getTime(), x, y, trackPosition - hitObject.getTime());
        sliderClickedInitial = true;
        data.sliderTickResult(
            hitObject.getTime(), result, this.x, this.y, hitObject, currentRepeats);
        return true;
      }
    }
    return false;
  }
Esempio n. 18
0
  public boolean onTouchEvent2(MotionEvent event) {
    // Cancel current circle on two-fingers touch (or more.)
    if (event.getPointerCount() > 1) {
      cancelCircle(false);
      return false;
    }

    // If current circle is canceled then
    // ignore all actions except of touch down (to reset state.)
    if (mCanceled && event.getActionMasked() != MotionEvent.ACTION_DOWN) return false;

    final float x = event.getX();
    final float y = event.getY();
    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        clearAnimation();

        // Initialize circle
        mRadiusMax = 0;
        mPoint[0] = x;
        mPoint[1] = y;
        mCanceled = false;

        mHandler.removeCallbacks(mDelayedCancel);
        mHandler.postDelayed(mDelayedCancel, 1000);
        mCallback.onCircleEvent(mRadius, calculateRatio(), ACTION_START);
      case MotionEvent.ACTION_MOVE:
        setRadius((float) Math.hypot(x - mPoint[0], y - mPoint[1]));

        // Cancel the circle if it's decreasing.
        if (mRadiusMax - mRadius > mRadiusDecreaseThreshold) {
          mRadiusAimed = false;
          cancelCircle(false);
          break;
        }

        if (calculateRatio() == 1) {
          if (!mRadiusAimed) {
            mRadiusAimed = true;
            performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
          }
        } else if (mRadiusAimed) {
          mRadiusAimed = false;
          performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
        }
        break;
      case MotionEvent.ACTION_UP:
        if (mRadiusAimed) {
          mCallback.onCircleEvent(mRadius, calculateRatio(), ACTION_UNLOCK);
        }
      case MotionEvent.ACTION_CANCEL:
        mHandler.removeCallbacks(mDelayedCancel);
        cancelCircle(mRadiusAimed);
        break;
      default:
        return super.onTouchEvent(event);
    }
    return false;
  }
Esempio n. 19
0
  /**
   * Called after the body has moved to update the leg motion accordingly. This method does not use
   * a particularly convincing leg motion algorithm; low-budgets Saturday morning cartoons would be
   * proud.
   */
  public void bodyMovedBy(double dx, double dy) {
    if (anchored) {
      graphics.move(-dx, -dy);
    } else {
      double speed = Math.hypot(dx, dy),
          targetX = restPosition.getX() + dx / speed * rangeOfMotion,
          targetY = restPosition.getY() + dy / speed * rangeOfMotion,
          toTargetX = targetX - graphics.getX(),
          toTargetY = targetY - graphics.getY(),
          distToTarget = Math.hypot(toTargetX, toTargetY);
      graphics.move(toTargetX / distToTarget * speed * 1.5, toTargetY / distToTarget * speed * 1.5);
    }

    double distention =
        Math.hypot(graphics.getX() - restPosition.getX(), graphics.getY() - restPosition.getY());
    if (distention >= rangeOfMotion) anchored = !anchored;
  }
Esempio n. 20
0
  /** @return The angle of the unit circle with the image views center */
  private double getPositionAngle(double xTouch, double yTouch) {
    double x = xTouch - (circleWidth / 2d);
    double y = circleHeight - yTouch - (circleHeight / 2d);

    switch (getPositionQuadrant(x, y)) {
      case 1:
        return Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI;
      case 2:
      case 3:
        return 180 - (Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI);
      case 4:
        return 360 + Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI;
      default:
        // ignore, does not happen
        return 0;
    }
  }
Esempio n. 21
0
  /** get the angle of a touch event. */
  private double getAngle(double x, double y) {
    x = x - (wheelWidth / 2d);
    y = wheelHeight - y - (wheelHeight / 2d);

    switch (getQuadrant(x, y)) {
      case 1:
        return Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI;
      case 2:
        return 180 - Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI;
      case 3:
        return 180 + (-1 * Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI);
      case 4:
        return 360 + Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI;
      default:
        return 0;
    }
  }
 private boolean trueMove(MotionEvent aEvent) {
   if (fPreviousEvents.size() > 5) {
     return true;
   }
   DrawManager.MyMotionEvent myMotionEvent = fPreviousEvents.get(0);
   double distance =
       Math.hypot(aEvent.getX() - myMotionEvent.getX(), aEvent.getY() - myMotionEvent.getY());
   return distance > 3.;
 }
Esempio n. 23
0
  /** Fling with no touch hints, then land off screen. */
  public void fling(final View photo) {
    final float[] o = {mWidth + mLongSide / 2f, mHeight + mLongSide / 2f};
    final float[] a = {photo.getX(), photo.getY()};
    final float[] b = {o[0], a[1] + o[0] - a[0]};
    final float[] c = {a[0] + o[1] - a[1], o[1]};
    float[] delta = {0f, 0f};
    if (Math.hypot(b[0] - a[0], b[1] - a[1]) < Math.hypot(c[0] - a[0], c[1] - a[1])) {
      delta[0] = b[0] - a[0];
      delta[1] = b[1] - a[1];
    } else {
      delta[0] = c[0] - a[0];
      delta[1] = c[1] - a[1];
    }

    final float dist = (float) Math.hypot(delta[0], delta[1]);
    final int duration = (int) (1000f * dist / mThrowSpeed);
    fling(photo, delta[0], delta[1], duration, true);
  }
Esempio n. 24
0
  private void prepare(View view, FrameLayout FrameLayout) {
    int centerX = (view.getLeft() + view.getRight()) / 2;
    int centerY = (view.getTop() + view.getBottom()) / 2;
    finalRadius = (float) Math.hypot((double) centerX, (double) centerY);

    circularAnimator =
        ViewAnimationUtils.createCircularReveal(FrameLayout, centerX, centerY, 0, finalRadius);
    circularAnimator.setDuration(500);
  }
Esempio n. 25
0
 private void setArc() {
   double r13 = Math.hypot(atom3.rx - atom1.rx, atom3.ry - atom1.ry);
   double r23 = Math.hypot(atom2.rx - atom3.rx, atom2.ry - atom3.ry);
   double t =
       ((atom3.rx - atom1.rx) * (atom2.rx - atom3.rx)
               + (atom3.ry - atom1.ry) * (atom2.ry - atom3.ry))
           / (r13 * r23);
   angle.setAngleExtent(
       (atom1.rx - atom3.rx) * (atom2.ry - atom3.ry)
                   - (atom1.ry - atom3.ry) * (atom2.rx - atom3.rx)
               < 0
           ? 180.0 - Math.toDegrees(Math.acos(t))
           : Math.toDegrees(Math.acos(t)) - 180.0);
   t = (atom1.rx - atom3.rx) / r13;
   angle.start =
       atom1.ry < atom3.ry ? Math.toDegrees(Math.acos(t)) : -Math.toDegrees(Math.acos(t));
   angle.x = atom3.rx - 0.5 * angle.width;
   angle.y = atom3.ry - 0.5 * angle.height;
 }
Esempio n. 26
0
  /** @return The angle of the unit sharear with the image view's center */
  private double getAngle(double xTouch, double yTouch) {
    double x = xTouch - (sharearWidth / 2d);
    double y = sharearHeight - yTouch - (sharearHeight / 2d);

    switch (getQuadrant(x, y)) {
      case 1:
        return Math.asin(y / Math.hypot(x, y)) * 180d / Math.PI;

      case 2:
      case 3:
        return 180d - (Math.asin(y / Math.hypot(x, y)) * 180d / Math.PI);

      case 4:
        return 360d + Math.asin(y / Math.hypot(x, y)) * 180d / Math.PI;

      default:
        // ignore, does not happen
        return 0;
    }
  }
Esempio n. 27
0
  public void dibujaGrafico(Canvas canvas) {

    canvas.save();
    int x = (int) (posX + ancho / 2);
    int y = (int) (posY + alto / 2);
    drawable.setBounds((int) posX, (int) posY, (int) posX + ancho, (int) posY + alto);
    drawable.draw(canvas);
    canvas.restore();
    int rInval = (int) Math.hypot(ancho, alto) / 2 + MAX_VELOCIDAD;
    view.invalidate(x - rInval, y - rInval, x + rInval, y + rInval);
  }
  public int addBand(Rect rect) {
    mBands.add(0, mCurrentBand = new Band(rect.centerX(), rect.centerY()));
    mCurrentBand.mask = false;
    int x = (mCurrentBand.xPos1 + mCurrentBand.xPos2) / 2;
    int y = (mCurrentBand.yPos1 + mCurrentBand.yPos2) / 2;
    double addDelta = ADD_MIN_DIST * Math.max(rect.width(), rect.height());
    boolean moved = true;
    int count = 0;
    int toMove = mBands.indexOf(mCurrentBand);

    while (moved) {
      moved = false;
      count++;
      if (count > 14) {
        break;
      }

      for (Band point : mBands) {
        if (point.mask) {
          break;
        }
      }

      for (Band point : mBands) {
        if (point.mask) {
          break;
        }
        int index = mBands.indexOf(point);

        if (toMove != index) {
          double dist = Math.hypot(point.xPos1 - x, point.yPos1 - y);
          if (dist < addDelta) {
            moved = true;
            mCurrentBand.xPos1 += addDelta;
            mCurrentBand.yPos1 += addDelta;
            mCurrentBand.xPos2 += addDelta;
            mCurrentBand.yPos2 += addDelta;
            x = (mCurrentBand.xPos1 + mCurrentBand.xPos2) / 2;
            y = (mCurrentBand.yPos1 + mCurrentBand.yPos2) / 2;

            if (mCurrentBand.yPos1 > rect.bottom) {
              mCurrentBand.yPos1 = (int) (rect.top + addDelta);
            }
            if (mCurrentBand.xPos1 > rect.right) {
              mCurrentBand.xPos1 = (int) (rect.left + addDelta);
            }
          }
        }
      }
    }
    trimVector();
    return 0;
  }
Esempio n. 29
0
  // Piercing可能なエリアをターゲットに入れる
  private boolean[][] searchIntervals(
      Coord<Integer> current, Coord<Integer> target, Range range, boolean pierceUnit) {
    Range span =
        new Range(
            RangeType.ARCH,
            0,
            distanse(current, target),
            0,
            Math.abs(height[current.y][current.x] - height[target.y][target.x]));

    boolean[][] availables = new boolean[map[0].length][map.length];
    availables[target.x][target.y] = true;

    if (!searchFloat(target.x, target.y, span)) return availables;

    int hexSize = 128;
    double r = hexSize / 2 * 1.732 / 2 * (1.2 + range.max);

    Coord<Double> currentC = getCoordByHex(current.x, current.y, hexSize);
    Coord<Double> targetC = getCoordByHex(target.x, target.y, hexSize);

    double thetaL = Math.atan2(targetC.y - currentC.y, targetC.x - currentC.x);

    for (int y = 0; y < map.length; y++)
      for (int x = 0; x < map[y].length; x++) {
        if (
        /*map[y][x] > OBSTACLE
        || */ (target.x == x && target.y == y)
            || (current.x == x && current.y == y)
            || distanse(current.x, current.y, x, y) > span.max) continue;

        Coord<Double> barC = getCoordByHex(x, y, hexSize);

        //				if(range.max < 1) {
        //					if(isOnRay(x, y, current, target, currentC, targetC, barC, -unitHeight)
        //							|| !isOnRay(x, y, current, target, currentC, targetC, barC, obstacleHeight))
        //						continue;
        //				}

        //				if(Math.abs(height[y][x] - height[current.y][current.x]) > range.maxH
        //						&& Math.abs(height[y][x] - height[target.y][target.x]) > range.maxH)
        //					continue;

        double theta = Math.atan2(barC.y - currentC.y, barC.x - currentC.x) - thetaL;

        if (Math.cos(theta) < 0
            || Math.cos(thetaL - Math.atan2(targetC.y - barC.y, targetC.x - barC.x)) < 0) continue;

        if (Math.hypot(barC.x - currentC.x, barC.y - currentC.y) * Math.abs(Math.sin(theta)) < r)
          availables[x][y] = true;
      }
    return availables;
  }
 @Test
 public void testHypotenuse() throws Exception {
   Random random = new Random();
   for (int i = 0; i < TRIES; i++) {
     double x = random.nextDouble();
     double y = random.nextDouble();
     double h = Math.hypot(x, y);
     BigDecimal decimalX = BigDecimal.valueOf(x);
     BigDecimal decimalY = BigDecimal.valueOf(y);
     assertEquals(BigMath.hypot(x, y, CONTEXT).doubleValue() / h, 1, DBL_TOLERANCE);
     assertEquals(BigMath.hypot(decimalX, decimalY, CONTEXT).doubleValue() / h, 1, DBL_TOLERANCE);
   }
 }